1. svn -> git

This commit is contained in:
2017-04-12 01:23:07 +09:00
commit daaaf2997b
406 changed files with 68990 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using UnityEngine;
using System.Collections.Generic;
// Reading/writing textures for the first time can cause lag, so this script can be used to do it on scene load
[AddComponentMenu("Destructible 2D/D2D Cache Textures")]
public class D2D_CacheTextures : MonoBehaviour
{
public List<Texture2D> ReadableTextures = new List<Texture2D>();
protected virtual void Awake()
{
foreach (var readableTexture in ReadableTextures)
{
if (readableTexture != null && readableTexture.width > 0 && readableTexture.height > 0)
{
readableTexture.GetPixel(0, 0);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9e2a59ccfed4fe04880788087dfff24e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,19 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Click To Spawn")]
public class D2D_ClickToSpawn : MonoBehaviour
{
public GameObject Prefab;
protected virtual void Update()
{
if (Input.GetMouseButtonDown(0) == true && Prefab != null && Camera.main != null)
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var distance = D2D_Helper.Divide(ray.origin.z, ray.direction.z);
var point = ray.origin - ray.direction * distance;
D2D_Helper.CloneGameObject(Prefab, null).transform.position = point;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f51cc0bd066e67544a5ae53cca94f8d4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,27 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Click To Stamp")]
public class D2D_ClickToStamp : MonoBehaviour
{
public LayerMask Layers = -1;
public Texture2D StampTex;
public Vector2 Size = Vector2.one;
public float Angle;
public float Hardness = 1.0f;
protected virtual void Update()
{
if (Input.GetMouseButtonDown(0) == true && Camera.main != null)
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var distance = D2D_Helper.Divide(ray.origin.z, ray.direction.z);
var point = ray.origin - ray.direction * distance;
D2D_Destructible.StampAll(point, Size, Angle, StampTex, Hardness, Layers);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ff27626022dc0764cafe1392f44ac184
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,44 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Damage On Collision")]
public class D2D_DamageOnCollision : MonoBehaviour
{
public D2D_DamageableSprite DamageableSprite;
public float RelativeVelocityRequired = 1.0f;
public float DamageScale = 1.0f;
protected virtual void Awake()
{
if (DamageableSprite == null)
{
DamageableSprite = GetComponent<D2D_DamageableSprite>();
}
}
protected virtual void OnCollisionEnter2D(Collision2D collision)
{
if (DamageableSprite != null)
{
var magnitude = collision.relativeVelocity.magnitude;
if (magnitude >= RelativeVelocityRequired)
{
var damage = (magnitude - RelativeVelocityRequired) * DamageScale;
DamageableSprite.InflictDamage(damage);
}
}
}
#if UNITY_EDITOR
protected virtual void Reset()
{
if (DamageableSprite == null)
{
DamageableSprite = GetComponent<D2D_DamageableSprite>();
}
}
#endif
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0f04369491c63ef4b8faea60e06874ed
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,43 @@
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Destructible 2D/D2D Demo GUI")]
public class D2D_DemoGUI : MonoBehaviour
{
protected virtual void OnGUI()
{
var r1 = new Rect(5 + 105 * 0, 50, 100, 50);
var r2 = new Rect(5 + 105 * 1, 50, 100, 50);
var r3 = new Rect(5 + 105 * 2, 50, 100, 50);
var r4 = new Rect(5 + 105 * 3, 50, 100, 50);
if (GUI.Button(r1, "Reload") == true)
{
Application.LoadLevel(Application.loadedLevel);
}
if (GUI.Button(r2, "Halve") == true)
{
foreach (var destructibleSprite in D2D_DestructibleSprite.DestructibleSprites)
{
destructibleSprite.HalveAlphaTexAndSplitMinPixels();
}
}
if (GUI.Button(r3, "Blur") == true)
{
foreach (var destructibleSprite in D2D_DestructibleSprite.DestructibleSprites)
{
destructibleSprite.BlurAlphaTex();
}
}
if (GUI.Button(r4, "Sharpness") == true)
{
foreach (var destructibleSprite in D2D_DestructibleSprite.DestructibleSprites)
{
destructibleSprite.Sharpness *= 2;
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 938952eec1835ac48a5abb40135c116f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,17 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Destroy After Time")]
public class D2D_DestroyAfterTime : MonoBehaviour
{
public float Seconds = 10.0f;
protected virtual void Update()
{
Seconds -= Time.deltaTime;
if (Seconds <= 0.0f)
{
Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5c5427425b2ccd2438063cfc81dec5af
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,75 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Drag To Shoot")]
public class D2D_DragToShoot : MonoBehaviour
{
public GameObject Bullet;
public float Power = 3.0f;
public float AngleOffset;
public float AngleRandomness;
public SpriteRenderer Indicator;
private bool down;
private Vector3 startMousePosition;
public GameObject startFirePosition;
protected virtual void Update()
{
// Begin dragging?
if (Input.GetMouseButton(0) == true && down == false)
{
down = true;
// mouse pos -> unit pos
//startMousePosition = Input.mousePosition;
}
// End dragging?
if (Input.GetMouseButton(0) == false && down == true)
{
down = false;
// Fire?
if (Camera.main != null && Bullet != null)
{
var endMousePosition = Input.mousePosition;
var startPos = startFirePosition.transform.position;// Camera.main.ScreenToWorldPoint(startMousePosition);
var endPos = Camera.main.ScreenToWorldPoint( endMousePosition);
var vec = endPos - startPos;
var angle = D2D_Helper.Atan2(vec) * -Mathf.Rad2Deg + AngleOffset + Random.Range(-0.5f, 0.5f) * AngleRandomness;
var clone = D2D_Helper.CloneGameObject(Bullet, null, startPos, Quaternion.Euler(0.0f, 0.0f, angle));
var cloneRb2D = clone.GetComponent<Rigidbody2D>();
if (cloneRb2D != null)
{
cloneRb2D.velocity = (endPos - startPos) * Power;
}
}
}
// Show dragging?
if (Indicator != null)
{
Indicator.enabled = down;
if (Camera.main != null && down == true)
{
var currentMousePosition = Input.mousePosition;
var startPos = startFirePosition.transform.position;// Camera.main.ScreenToWorldPoint( startMousePosition);
var currentPos = Camera.main.ScreenToWorldPoint(currentMousePosition);
var scale = Vector3.Distance(currentPos, startPos);
var angle = D2D_Helper.Atan2(currentPos - startPos) * Mathf.Rad2Deg;
Indicator.transform.position = startFirePosition.transform.position;// Camera.main.ScreenToWorldPoint(startMousePosition);
Indicator.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -angle);
Indicator.transform.localScale = new Vector3(scale, scale, scale);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e9ba5fabb9b040c44ae1477313d5d30c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,61 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Drag To Slice")]
public class D2D_DragToSlice : MonoBehaviour
{
public Texture2D StampTex;
public float Thickness = 1.0f;
public float Hardness = 1.0f;
public SpriteRenderer Indicator;
private bool down;
private Vector3 startMousePosition;
protected virtual void Update()
{
if (Input.GetMouseButton(0) == true && down == false)
{
down = true;
startMousePosition = Input.mousePosition;
}
if (Input.GetMouseButton(0) == false && down == true)
{
down = false;
if (Camera.main != null)
{
var endMousePosition = Input.mousePosition;
var startPos = Camera.main.ScreenToWorldPoint(startMousePosition);
var endPos = Camera.main.ScreenToWorldPoint( endMousePosition);
D2D_Destructible.SliceAll(startPos, endPos, Thickness, StampTex, Hardness);
}
}
if (Indicator != null)
{
Indicator.enabled = down;
if (Camera.main != null && down == true)
{
var currentMousePosition = Input.mousePosition;
var startPos = Camera.main.ScreenToWorldPoint( startMousePosition);
var currentPos = Camera.main.ScreenToWorldPoint(currentMousePosition);
var scale = Vector3.Distance(currentPos, startPos);
var angle = D2D_Helper.Atan2(currentPos - startPos) * Mathf.Rad2Deg;
var newPosition = Camera.main.ScreenToWorldPoint(startMousePosition);
newPosition.z = Indicator.transform.position.z;
Indicator.transform.position = newPosition;
Indicator.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -angle);
Indicator.transform.localScale = new Vector3(Thickness, scale, scale);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 83de1e29fbe98b94bb2bdf1356fe21b0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,18 @@
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Destructible 2D/D2D Follow")]
public class D2D_Follow : MonoBehaviour
{
public Transform Target;
public Vector3 Offset;
protected virtual void Update()
{
if (Target != null)
{
D2D_Helper.SetPosition(transform, Target.transform.position + Offset);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0146149b345bfb446b29a58b83cb76eb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,32 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D FPS Counter")]
public class D2D_FpsCounter : MonoBehaviour
{
public GUIText Text;
private float counter;
private int frames;
private float fps;
protected virtual void Update()
{
counter += Time.deltaTime;
frames += 1;
if (counter >= 1.0f)
{
fps = (float)frames / counter;
counter = 0.0f;
frames = 0;
}
if (Text != null)
{
Text.text = "FPS: " + fps.ToString("0");
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4d60eab1a63aab04584efcdaa2fd09ea
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,6 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Mothership Core")]
public class D2D_MothershipCore : MonoBehaviour
{
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ae176ea2265d9a4985517dba718e4a1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,18 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Mothership Thruster")]
public class D2D_MothershipThruster : MonoBehaviour
{
public ParticleSystem Particles;
public D2D_MothershipCore Core;
protected virtual void Update()
{
// Core not connected?
if (Particles != null && Core == null)
{
Particles.enableEmission = false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 473f9bf559844b34eba53d3bcb26bb6d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,24 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Replace On Collision")]
public class D2D_ReplaceOnCollision : MonoBehaviour
{
public float RelativeVelocityRequired;
public GameObject Spawn;
protected virtual void OnCollisionEnter2D(Collision2D collision)
{
Destroy(gameObject);
if (Spawn != null)
{
if (collision.relativeVelocity.magnitude >= RelativeVelocityRequired)
{
var contact0 = collision.contacts[0];
Instantiate(Spawn, contact0.point, transform.rotation);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5d96b81764a65db4a834fe31edbad712
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,31 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Replace On Trigger")]
public class D2D_ReplaceOnTrigger : MonoBehaviour
{
public GameObject Spawn;
public bool IgnoreSameTag;
public bool CanHitTrigger;
protected virtual void OnTriggerEnter2D(Collider2D collider)
{
if (IgnoreSameTag == true && tag == collider.tag)
{
return;
}
if (CanHitTrigger == false && collider.isTrigger == true)
{
return;
}
Destroy(gameObject);
if (Spawn != null)
{
Instantiate(Spawn, transform.position, transform.rotation);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d7aca1e0d73549b42903ddc200d5e670
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,30 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Spawn On Collision")]
public class D2D_SpawnOnCollision : MonoBehaviour
{
public float RelativeVelocityRequired = 1.0f;
public GameObject Spawn;
public float SpawnCooldown;
private float cooldownTimer;
protected virtual void OnCollisionEnter2D(Collision2D collision)
{
if (Spawn != null && cooldownTimer <= 0.0f && collision.relativeVelocity.magnitude >= RelativeVelocityRequired)
{
cooldownTimer = SpawnCooldown;
var contact0 = collision.contacts[0];
Instantiate(Spawn, contact0.point, transform.rotation);
}
}
protected virtual void Update()
{
cooldownTimer -= Time.deltaTime;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 32db1667742313f4fb4ad457dc3190d9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,36 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Top Down Car")]
public class D2D_TopDownCar : MonoBehaviour
{
public D2D_TopDownWheel FrontLeftWheel;
public D2D_TopDownWheel FrontRightWheel;
public D2D_TopDownWheel BackLeftWheel;
public D2D_TopDownWheel BackRightWheel;
public float Throttle;
public float ThrottleLimit = 10.0f;
public float SteeringAngle;
public float SteeringLimit = 30.0f;
protected virtual void Update()
{
Throttle = Input.GetAxis("Vertical") * ThrottleLimit;
if ( FrontLeftWheel != null) FrontLeftWheel.SurfaceSpeed = Throttle;
if (FrontRightWheel != null) FrontRightWheel.SurfaceSpeed = Throttle;
if ( BackLeftWheel != null) BackLeftWheel.SurfaceSpeed = Throttle;
if ( BackRightWheel != null) BackRightWheel.SurfaceSpeed = Throttle;
SteeringAngle = Input.GetAxis("Horizontal") * SteeringLimit;
if ( FrontLeftWheel != null) FrontLeftWheel.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -SteeringAngle);
if (FrontRightWheel != null) FrontRightWheel.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -SteeringAngle);
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 48a9224a1b36f4e4f92faf5f0f5dc4fc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,36 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Top Down Gun")]
public class D2D_TopDownGun : MonoBehaviour
{
public GameObject Bullet;
public float ShotCooldown = 0.1f;
public float ShootSpeed = 10.0f;
public bool IsFiring;
private float cooldownTimer;
protected virtual void FixedUpdate()
{
if (IsFiring == true && Bullet != null && cooldownTimer <= 0.0f)
{
cooldownTimer = ShotCooldown;
var clone = D2D_Helper.CloneGameObject(Bullet, null, transform.position, transform.rotation);
var body = clone.GetComponent<Rigidbody2D>();
if (body != null)
{
body.velocity = transform.up * ShootSpeed;
}
}
}
protected virtual void Update()
{
cooldownTimer -= Time.deltaTime;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7520a7e2dd8139844a57b0329de84e51
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,29 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Top Down Spaceship")]
public class D2D_TopDownSpaceship : MonoBehaviour
{
public D2D_TopDownThruster LeftThruster;
public D2D_TopDownThruster RightThruster;
public float LeftThrottle;
public float RightThrottle;
public D2D_TopDownGun LeftGun;
public D2D_TopDownGun RightGun;
protected virtual void Update()
{
LeftThrottle = Input.GetAxis("Vertical") + Mathf.Abs(Mathf.Max(0.0f, Input.GetAxis("Horizontal")));
RightThrottle = Input.GetAxis("Vertical") + Mathf.Abs(Mathf.Min(0.0f, Input.GetAxis("Horizontal")));
if ( LeftThruster != null) LeftThruster.Throttle = LeftThrottle;
if (RightThruster != null) RightThruster.Throttle = RightThrottle;
if (LeftGun != null) LeftGun.IsFiring = Input.GetAxis("Jump") > 0.0f;
if (RightGun != null) RightGun.IsFiring = Input.GetAxis("Jump") > 0.0f;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a89c3d52a05954f4f9c369fdd0131b87
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,24 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Top Down Thruster")]
public class D2D_TopDownThruster : MonoBehaviour
{
public Rigidbody2D body;
public float Throttle;
public float MoveSpeed = 50.0f;
public float TurnSpeed = 5.0f;
protected virtual void FixedUpdate()
{
transform.localScale = new Vector3(Throttle, Throttle, Throttle);
if (body != null)
{
body.velocity += Throttle * MoveSpeed * Time.fixedDeltaTime * (Vector2)transform.up;
body.angularVelocity += Throttle * TurnSpeed * Time.fixedDeltaTime;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e8ce83bcdae0c0c428102305e4a5d011
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,17 @@
using UnityEngine;
[AddComponentMenu("Destructible 2D/D2D Top Down Wheel")]
public class D2D_TopDownWheel : MonoBehaviour
{
public Rigidbody2D body;
public float SurfaceSpeed;
protected virtual void FixedUpdate()
{
if (body != null)
{
body.AddForceAtPosition(transform.up * SurfaceSpeed, transform.position);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0a3e22550732c0945bccb45e0ef55713
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,143 @@
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Destructible 2D/D2D Water")]
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class D2D_Water : MonoBehaviour
{
public Color WaveColour = Color.blue;
public int WaveCount = 10;
public float WaveWidth = 1.0f;
public float WaveThickness = 1.0f;
public float WaveAmplitude = 1.0f;
public float WaveFrequency = 1.0f;
public float WaveOffset;
public float WaveAge;
public float WaveSpeed = 0.1f;
public Color SeaColour = Color.black;
public float SeaDepth = 10.0f;
public Texture2D NoiseTex;
[HideInInspector]
[SerializeField]
private MeshFilter meshFilter;
private Mesh mesh;
private Vector3[] positions;
private Color[] colours;
private Vector2[] uvs;
private int[] indices;
protected virtual void Update()
{
if (meshFilter == null) meshFilter = GetComponent<MeshFilter>();
if (mesh == null)
{
mesh = new Mesh();
mesh.hideFlags = HideFlags.DontSave;
}
// Prevent this from dirtying the scene when exiting play mode
D2D_Helper.StealthSet(meshFilter, mesh);
// Generate positions?
if (positions == null || positions.Length != WaveCount * 3 + 3)
{
positions = new Vector3[WaveCount * 3 + 3];
}
// Generate colours?
if (colours == null || colours.Length != WaveCount * 3 + 3)
{
colours = new Color[WaveCount * 3 + 3];
}
for (var i = 0; i <= WaveCount; i++)
{
colours[i * 3 + 0] = WaveColour;
colours[i * 3 + 1] = SeaColour;
colours[i * 3 + 2] = SeaColour;
}
// Generate uvs?
if (uvs == null || uvs.Length != WaveCount * 3 + 3)
{
uvs = new Vector2[WaveCount * 3 + 3];
}
// Generate indices?
if (indices == null || indices.Length != WaveCount * 12)
{
indices = new int[WaveCount * 12];
for (var i = 0; i < WaveCount; i++)
{
// Wave
indices[i * 12 + 0] = i * 3 + 0;
indices[i * 12 + 1] = i * 3 + 1;
indices[i * 12 + 2] = i * 3 + 3;
indices[i * 12 + 3] = i * 3 + 4;
indices[i * 12 + 4] = i * 3 + 3;
indices[i * 12 + 5] = i * 3 + 1;
// Sea
indices[i * 12 + 6] = i * 3 + 1;
indices[i * 12 + 7] = i * 3 + 2;
indices[i * 12 + 8] = i * 3 + 4;
indices[i * 12 + 9] = i * 3 + 5;
indices[i * 12 + 10] = i * 3 + 4;
indices[i * 12 + 11] = i * 3 + 2;
}
}
// Make waves move?
if (NoiseTex != null)
{
WaveAge += WaveSpeed * Time.deltaTime;
var halfSize = WaveCount * WaveWidth * 0.5f;
for (var i = 0; i <= WaveCount; i++)
{
var sample = NoiseTex.GetPixelBilinear(WaveOffset + i * WaveFrequency, WaveAge).r - 0.5f;
var x = i * WaveWidth - halfSize;
var y = sample * 2.0f * WaveAmplitude;
positions[i * 3 + 0] = new Vector3(x, y , 0.0f);
positions[i * 3 + 1] = new Vector3(x, y - WaveThickness, 0.0f);
positions[i * 3 + 2] = new Vector3(x, y - SeaDepth , 0.0f);
}
}
// Update mesh
mesh.Clear();
mesh.vertices = positions;
mesh.colors = colours;
mesh.triangles = indices;
mesh.uv = uvs;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
protected virtual void OnDestroy()
{
D2D_Helper.Destroy(mesh);
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 95072fa2012b89148859d4d3eaf74f0f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: