├── .codacy.yml
├── .gitattributes
├── .gitignore
├── CHANGELOG.md
├── CHANGELOG.md.meta
├── Demo.meta
├── Demo
├── Demo.unitypackage
└── Demo.unitypackage.meta
├── LICENSE.md
├── LICENSE.md.meta
├── README.md
├── README.md.meta
├── Runtime.meta
├── Runtime
├── Water2D.cs
├── Water2D.cs.meta
├── Water2DCollider.cs
├── Water2DCollider.cs.meta
├── Water2DMeshData.cs
├── Water2DMeshData.cs.meta
├── Water2DSurfaceNodeData.cs
├── Water2DSurfaceNodeData.cs.meta
├── Water3DCollider.cs
├── Water3DCollider.cs.meta
├── WaterCollider.cs
├── WaterCollider.cs.meta
├── com.gameframe.water2d.asmdef
├── com.gameframe.water2d.asmdef.meta
├── csc.rsp
└── csc.rsp.meta
├── package.json
└── package.json.meta
/.codacy.yml:
--------------------------------------------------------------------------------
1 | exclude_paths:
2 | - '*.md'
3 | - 'Tests/Editor/*.cs'
4 | - 'Tests/Runtime/*.cs'
5 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # This .gitignore file should be placed at the root of your Unity project directory
2 | #
3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
4 | #
5 | /[Ll]ibrary/
6 | /[Tt]emp/
7 | /[Oo]bj/
8 | /[Bb]uild/
9 | /[Bb]uilds/
10 | /[Ll]ogs/
11 | /[Mm]emoryCaptures/
12 |
13 | # Never ignore Asset meta data
14 | !/[Aa]ssets/**/*.meta
15 |
16 | # Uncomment this line if you wish to ignore the asset store tools plugin
17 | # /[Aa]ssets/AssetStoreTools*
18 |
19 | # Autogenerated Jetbrains Rider plugin
20 | [Aa]ssets/Plugins/Editor/JetBrains*
21 |
22 | # Visual Studio cache directory
23 | .vs/
24 |
25 | # Gradle cache directory
26 | .gradle/
27 |
28 | # Autogenerated VS/MD/Consulo solution and project files
29 | ExportedObj/
30 | .consulo/
31 | *.csproj
32 | *.unityproj
33 | *.sln
34 | *.suo
35 | *.tmp
36 | *.user
37 | *.userprefs
38 | *.pidb
39 | *.booproj
40 | *.svd
41 | *.pdb
42 | *.mdb
43 | *.opendb
44 | *.VC.db
45 |
46 | # Unity3D generated meta files
47 | *.pidb.meta
48 | *.pdb.meta
49 | *.mdb.meta
50 |
51 | # Unity3D generated file on crash reports
52 | sysinfo.txt
53 |
54 | # Builds
55 | *.apk
56 | *.unitypackage
57 |
58 | # Crashlytics generated file
59 | crashlytics-build.properties
60 |
61 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Created 1/27/2020
--------------------------------------------------------------------------------
/CHANGELOG.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cc6705fae29964f79829c476d9d531f1
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Demo.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4e7000b75f3d8974b8ffaf17744ff588
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Demo/Demo.unitypackage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coryleach/UnityWater2D/6c63506c47497e1692b55cb4857eaddb30bd857d/Demo/Demo.unitypackage
--------------------------------------------------------------------------------
/Demo/Demo.unitypackage.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ce552b010cf734c4cbdf20a1f2ea795f
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Cory R. Leach
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/LICENSE.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 16064804e805940e8a75a029305c8170
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Gameframe.Water2D 👋
5 |
6 |
7 | [](https://www.codacy.com/manual/coryleach/UnityWater2D?utm_source=github.com&utm_medium=referral&utm_content=coryleach/UnityWater2D&utm_campaign=Badge_Grade)
8 | 
9 | [](https://openupm.com/packages/com.gameframe.water2d/)
10 | 
11 |
12 | [](https://twitter.com/coryleach)
13 |
14 |
15 |
16 |
17 |
18 | > Splashy 2D water
19 |
20 | ## Quick Package Install
21 |
22 | #### Using UnityPackageManager (for Unity 2019.3 or later)
23 | Open the package manager window (menu: Window > Package Manager)
24 | Select "Add package from git URL...", fill in the pop-up with the following link:
25 | https://github.com/coryleach/UnityWater2D.git#2.0.1
26 |
27 | #### Using UnityPackageManager (for Unity 2019.1 or later)
28 |
29 | Find the manifest.json file in the Packages folder of your project and edit it to look like this:
30 | ```js
31 | {
32 | "dependencies": {
33 | "com.gameframe.water2d": "https://github.com/coryleach/UnityWater2D.git#2.0.1",
34 | ...
35 | },
36 | }
37 | ```
38 |
39 |
40 |
43 |
44 | ## Usage
45 |
46 | Import the package in the demo folder for example usage
47 |
48 |
49 |
50 | ## Author
51 |
52 | 👤 **Cory Leach**
53 |
54 | * Twitter: [@coryleach](https://twitter.com/coryleach)
55 | * Github: [@coryleach](https://github.com/coryleach)
56 |
57 |
58 | ## Show your support
59 |
60 | Give a ⭐️ if this project helped you!
61 |
62 | ***
63 | _This README was generated with ❤️ by [Gameframe.Packages](https://github.com/coryleach/unitypackages)_
64 |
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ccb7a51e794d44a35a4bc4f4094e4251
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 058d7ad85640a43f79c0a1cfef4bc397
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Runtime/Water2D.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace Gameframe.Water2D
4 | {
5 |
6 | public class Water2D : MonoBehaviour
7 | {
8 | [SerializeField, Range(0f, 1f)] private float springConstant = 0.236f;
9 | [SerializeField, Range(0f, 1f)] private float damping = 0.878f;
10 | [SerializeField, Range(0f, 0.2f)] private float spread = 0.0173f;
11 |
12 | [SerializeField] private GameObject splashFx;
13 | [SerializeField] private Material material;
14 |
15 | [SerializeField] private int nodeDensity = 1;
16 |
17 | [SerializeField] private float zOffset;
18 |
19 | [SerializeField] private float width = 10;
20 | [SerializeField] private float height = 10;
21 |
22 | [SerializeField] private bool useCollider3D;
23 | [SerializeField] private float nodeMass = 40;
24 | public float NodeMass => nodeMass;
25 |
26 | [SerializeField] private float waterDrag = 2f;
27 | public float WaterDrag => waterDrag;
28 |
29 | private Water2DSurfaceNodeData[] _nodes;
30 | private Water2DMeshData[] _meshes;
31 |
32 | private void Start()
33 | {
34 | Build();
35 | }
36 |
37 | private void FixedUpdate()
38 | {
39 | PropagateWaves();
40 | UpdateNodes();
41 | }
42 |
43 | private void Update()
44 | {
45 | UpdateMeshes();
46 | }
47 |
48 | private const float Left = 0f;
49 | private const float Top = 0f;
50 | private const float BaseHeight = 0;
51 |
52 | private int _edgeCount;
53 |
54 | [ContextMenu("Build")]
55 | public void Build()
56 | {
57 | ClearChildren();
58 | SpawnWater();
59 | }
60 |
61 | private void ClearChildren()
62 | {
63 | var children = gameObject.transform.childCount;
64 | for (var i = children - 1; i >= 0; i--)
65 | {
66 | var child = gameObject.transform.GetChild(i);
67 |
68 | if (Application.isPlaying)
69 | {
70 | Destroy(child.gameObject);
71 | }
72 | else
73 | {
74 | DestroyImmediate(child.gameObject);
75 | }
76 |
77 | }
78 | }
79 |
80 | private void SpawnWater()
81 | {
82 | _edgeCount = Mathf.RoundToInt(width) * nodeDensity;
83 | var nodeCount = _edgeCount + 1;
84 |
85 | var meshWidth = width / _edgeCount;
86 |
87 | _nodes = new Water2DSurfaceNodeData[nodeCount];
88 | _meshes = new Water2DMeshData[_edgeCount];
89 |
90 | //Build Nodes
91 | for (var i = 0; i < _nodes.Length; i++)
92 | {
93 |
94 | var node = new Water2DSurfaceNodeData();
95 | _nodes[i] = node;
96 |
97 | node.yPos = Top;
98 | node.xPos = Left + (width * i) / _edgeCount;
99 | node.acceleration = 0;
100 | node.velocity = 0;
101 |
102 | }
103 |
104 | //Build Meshes
105 | for (var i = 0; i < _meshes.Length; i++)
106 | {
107 |
108 | var leftNode = _nodes[i];
109 | var rightNode = _nodes[i + 1];
110 |
111 | _meshes[i] = new Water2DMeshData();
112 | var edgeMesh = _meshes[i];
113 |
114 | //Build Mesh
115 | edgeMesh.mesh = new Mesh();
116 | Vector3[] verts = new Vector3[4];
117 | verts[0] = new Vector3(0, leftNode.yPos, zOffset);
118 | verts[1] = new Vector3(meshWidth, rightNode.yPos, zOffset);
119 | verts[2] = new Vector3(meshWidth, -height, zOffset);
120 | verts[3] = new Vector3(0, -height, zOffset);
121 |
122 | // (0) (1)
123 | // +--------+
124 | // | |
125 | // +--------+
126 | // (3) (2)
127 |
128 | Vector2[] uv = new Vector2[4];
129 | uv[0] = new Vector2(0, 1);
130 | uv[1] = new Vector2(1, 1);
131 | uv[2] = new Vector2(0, 0);
132 | uv[3] = new Vector3(1, 0);
133 |
134 | int[] triangles = {0, 1, 3, 3, 1, 2};
135 |
136 | edgeMesh.mesh.vertices = verts;
137 | edgeMesh.mesh.uv = uv;
138 | edgeMesh.mesh.triangles = triangles;
139 |
140 | //Build Game Object
141 | edgeMesh.gameObject = new GameObject("Mesh " + i);
142 | edgeMesh.gameObject.transform.parent = transform;
143 | edgeMesh.gameObject.transform.localPosition = new Vector3(leftNode.xPos, 0, 0);
144 |
145 | edgeMesh.renderer = edgeMesh.gameObject.AddComponent();
146 | edgeMesh.filter = edgeMesh.gameObject.AddComponent();
147 |
148 | edgeMesh.renderer.material = material;
149 | edgeMesh.filter.mesh = edgeMesh.mesh;
150 |
151 | //Build Collider
152 | if (useCollider3D)
153 | {
154 | edgeMesh.collider3D = edgeMesh.gameObject.AddComponent();
155 | edgeMesh.collider3D.size = new Vector3(meshWidth, height, 1);
156 | edgeMesh.collider3D.center = new Vector3(meshWidth * 0.5f, height * -0.5f, 0.5f);
157 | edgeMesh.collider3D.isTrigger = true; //*/
158 |
159 | var waterCollider = edgeMesh.collider3D.gameObject.AddComponent();
160 | waterCollider.WaterBody = this;
161 | waterCollider.LeftNode = i;
162 | waterCollider.RightNode = i + 1;
163 | }
164 | else
165 | {
166 | edgeMesh.collider = edgeMesh.gameObject.AddComponent();
167 | edgeMesh.collider.size = new Vector2(meshWidth, height);
168 | edgeMesh.collider.offset = new Vector2(meshWidth * 0.5f, height * -0.5f);
169 | edgeMesh.collider.isTrigger = true;
170 |
171 | var waterCollider = edgeMesh.collider.gameObject.AddComponent();
172 | waterCollider.WaterBody = this;
173 | waterCollider.LeftNode = i;
174 | waterCollider.RightNode = i + 1;
175 | }
176 |
177 | }
178 |
179 |
180 | }
181 |
182 | private void UpdateMeshes()
183 | {
184 | var meshWidth = width / _edgeCount;
185 |
186 | for (var i = 0; i < _meshes.Length; i++)
187 | {
188 |
189 | var leftNode = _nodes[i];
190 | var rightNode = _nodes[i + 1];
191 | var edgeMesh = _meshes[i];
192 |
193 | //Build Mesh
194 | var verts = new Vector3[4];
195 | verts[0] = new Vector3(0, leftNode.yPos, zOffset);
196 | verts[1] = new Vector3(meshWidth, rightNode.yPos, zOffset);
197 | verts[2] = new Vector3(meshWidth, -height, zOffset);
198 | verts[3] = new Vector3(0, -height, zOffset);
199 |
200 | edgeMesh.mesh.vertices = verts;
201 |
202 | }
203 |
204 | }
205 |
206 | private void UpdateNodes()
207 | {
208 |
209 | //Update node velocity and yPos
210 | for (var i = 0; i < _nodes.Length; i++)
211 | {
212 |
213 | var node = _nodes[i];
214 | var force = springConstant * (node.yPos - BaseHeight) + node.velocity * damping;
215 | node.acceleration = -force / nodeMass;
216 | node.velocity += node.acceleration;
217 | node.yPos += node.velocity;
218 | }
219 |
220 | }
221 |
222 | private void PropagateWaves()
223 | {
224 |
225 | var leftDelta = new float[_nodes.Length];
226 | var rightDelta = new float[_nodes.Length];
227 |
228 | const int iterations = 2;
229 |
230 | for (var j = 0; j < iterations; j++)
231 | {
232 |
233 | //Propagate Outward from each node
234 | for (var i = 0; i < _nodes.Length; i++)
235 | {
236 |
237 | Water2DSurfaceNodeData leftNode = null;
238 | Water2DSurfaceNodeData node = _nodes[i];
239 | Water2DSurfaceNodeData rightNode = null;
240 |
241 | if (i + 1 < _nodes.Length)
242 | {
243 | rightNode = _nodes[i + 1];
244 | }
245 |
246 | if (i - 1 >= 0)
247 | {
248 | leftNode = _nodes[i - 1];
249 | }
250 |
251 | //Multiply height difference by a spread factor
252 | if (leftNode != null)
253 | {
254 | leftDelta[i] = spread * (node.yPos - leftNode.yPos);
255 | leftNode.velocity += leftDelta[i];
256 | }
257 |
258 | if (rightNode != null)
259 | {
260 | rightDelta[i] = spread * (node.yPos - rightNode.yPos);
261 | rightNode.velocity += rightDelta[i];
262 | }
263 |
264 | }
265 |
266 | }
267 |
268 | //Finally Update Positions
269 | for (var i = 0; i < _nodes.Length; i++)
270 | {
271 |
272 | //Left
273 | if (i - 1 >= 0)
274 | {
275 | _nodes[i - 1].yPos += leftDelta[i];
276 | }
277 |
278 | //Right
279 | if (i + 1 < _nodes.Length)
280 | {
281 | _nodes[i + 1].yPos += rightDelta[i];
282 | }
283 |
284 | }
285 |
286 | }
287 |
288 | public void Collision(Water2DCollider waterCollider, float xPos, float momentum)
289 | {
290 | var leftNode = _nodes[waterCollider.LeftNode];
291 | var rightNode = _nodes[waterCollider.RightNode];
292 |
293 | var velocity = momentum / nodeMass;
294 |
295 | float leftWeight;
296 |
297 | if (xPos < leftNode.xPos)
298 | {
299 | leftWeight = 1f;
300 | }
301 | else if (xPos > rightNode.xPos)
302 | {
303 | leftWeight = 0f;
304 | }
305 | else
306 | {
307 | var localWidth = rightNode.xPos - leftNode.xPos;
308 | leftWeight = (xPos - leftNode.xPos) / localWidth;
309 | }
310 |
311 | //Spawn Splash Partile
312 | leftNode.velocity += velocity * leftWeight;
313 | rightNode.velocity += velocity * (1f - leftWeight);
314 |
315 | if (splashFx != null)
316 | {
317 | var splashX = (rightNode.xPos + leftNode.xPos) * 0.5f;
318 | var pt = transform.TransformPoint(new Vector3(splashX, 0, -5));
319 | Instantiate(splashFx, pt, Quaternion.identity);
320 | }
321 |
322 | }
323 |
324 | public void Collision(Water3DCollider waterCollider, float xPos, float momentum)
325 | {
326 |
327 | var leftNode = _nodes[waterCollider.LeftNode];
328 | var rightNode = _nodes[waterCollider.RightNode];
329 |
330 | var velocity = momentum / nodeMass;
331 |
332 | float leftWeight;
333 |
334 | if (xPos < leftNode.xPos)
335 | {
336 | leftWeight = 1f;
337 | }
338 | else if (xPos > rightNode.xPos)
339 | {
340 | leftWeight = 0f;
341 | }
342 | else
343 | {
344 | var localWidth = rightNode.xPos - leftNode.xPos;
345 | leftWeight = (xPos - leftNode.xPos) / localWidth;
346 | }
347 |
348 | //Spawn Splash Particle
349 | leftNode.velocity += velocity * leftWeight;
350 | rightNode.velocity += velocity * (1f - leftWeight);
351 |
352 | if (splashFx != null)
353 | {
354 | var splashX = (rightNode.xPos + leftNode.xPos) * 0.5f;
355 | var pt = transform.TransformPoint(new Vector3(splashX, 0, 0));
356 | Instantiate(splashFx, pt, Quaternion.identity);
357 | }
358 |
359 | }
360 |
361 | }
362 |
363 | }
--------------------------------------------------------------------------------
/Runtime/Water2D.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b8190a3a8d7134d6b9f91c308237ed3e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/Water2DCollider.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2014 Cory R. Leach
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using UnityEngine;
26 |
27 | namespace Gameframe.Water2D
28 | {
29 |
30 | public class Water2DCollider : WaterCollider
31 | {
32 |
33 | void OnTriggerEnter2D(Collider2D collider)
34 | {
35 | var rigidbody2d = collider.GetComponent();
36 | if (rigidbody2d != null)
37 | {
38 | rigidbody2d.drag = waterBody.WaterDrag;
39 |
40 | var momentum = rigidbody2d.velocity.y * rigidbody2d.mass;
41 | var xPos = rigidbody2d.position.x;
42 |
43 | waterBody.Collision(this, xPos, momentum);
44 |
45 | //Set a new V for this object
46 | var v = rigidbody2d.velocity;
47 | v.y = momentum / waterBody.NodeMass;
48 | rigidbody2d.velocity = v;
49 | }
50 | }
51 |
52 | void OnTriggerStay2D(Collider2D collider)
53 | {
54 | var rigidbody2d = collider.GetComponent();
55 | if (rigidbody2d != null)
56 | {
57 | rigidbody2d.drag = waterBody.WaterDrag;
58 | }
59 | }
60 |
61 | void OnTriggerExit2D(Collider2D collider)
62 | {
63 | var rigidbody2d = collider.GetComponent();
64 | if (rigidbody2d != null)
65 | {
66 | rigidbody2d.drag = 0f;
67 | }
68 | }
69 |
70 | }
71 |
72 | }
--------------------------------------------------------------------------------
/Runtime/Water2DCollider.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4ede85987d82a49f98e129a10ebd02c4
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/Water2DMeshData.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace Gameframe.Water2D
4 | {
5 | [System.Serializable]
6 | public class Water2DMeshData
7 | {
8 | public GameObject gameObject;
9 | public MeshRenderer renderer;
10 | public MeshFilter filter;
11 | public Mesh mesh;
12 | public BoxCollider2D collider;
13 | public BoxCollider collider3D;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Runtime/Water2DMeshData.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f5bf0fbcc355e2e4e93385bb1810d50b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/Water2DSurfaceNodeData.cs:
--------------------------------------------------------------------------------
1 | namespace Gameframe.Water2D
2 | {
3 | [System.Serializable]
4 | public class Water2DSurfaceNodeData
5 | {
6 | public float xPos;
7 | public float yPos;
8 | public float velocity;
9 | public float acceleration;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Runtime/Water2DSurfaceNodeData.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: afb47a06b10a66245a152db2eb504ec3
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/Water3DCollider.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2014 Cory R. Leach
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using UnityEngine;
26 |
27 | namespace Gameframe.Water2D
28 | {
29 | public class Water3DCollider : WaterCollider
30 | {
31 |
32 | void OnTriggerEnter(Collider collider)
33 | {
34 | var otherRigidbody = collider.GetComponent();
35 |
36 | if ( otherRigidbody != null )
37 | {
38 | otherRigidbody.drag = waterBody.WaterDrag;
39 |
40 | float momentum = otherRigidbody.velocity.y * otherRigidbody.mass;
41 | float xPos = otherRigidbody.position.x;
42 |
43 | waterBody.Collision(this,xPos,momentum);
44 |
45 | //Set a new V for this object
46 | var v = otherRigidbody.velocity;
47 | v.y = momentum / waterBody.NodeMass;
48 | otherRigidbody.velocity = v;
49 | }
50 | }
51 |
52 | void OnTriggerStay(Collider collider)
53 | {
54 | var otherRigidbody = collider.GetComponent();
55 | if ( otherRigidbody != null )
56 | {
57 | otherRigidbody.drag = waterBody.WaterDrag;
58 | }
59 | }
60 |
61 | void OnTriggerExit(Collider collider)
62 | {
63 | var otherRigidbody = collider.GetComponent();
64 | if ( otherRigidbody != null )
65 | {
66 | otherRigidbody.drag = 0f;
67 | }
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Runtime/Water3DCollider.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2de07830ab490413e8a99b769a0cf0c2
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/WaterCollider.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 |
5 | namespace Gameframe.Water2D
6 | {
7 | public abstract class WaterCollider : MonoBehaviour
8 | {
9 | [SerializeField]
10 | protected Water2D waterBody;
11 | public Water2D WaterBody
12 | {
13 | get => waterBody;
14 | set => waterBody = value;
15 | }
16 |
17 | [SerializeField]
18 | protected int leftNode;
19 | public int LeftNode
20 | {
21 | get => leftNode;
22 | set => leftNode = value;
23 | }
24 |
25 | [SerializeField]
26 | protected int rightNode;
27 |
28 | public int RightNode
29 | {
30 | get => rightNode;
31 | set => rightNode = value;
32 | }
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/Runtime/WaterCollider.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 532e7e23489d1bb42a037940e710f1ca
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/com.gameframe.water2d.asmdef:
--------------------------------------------------------------------------------
1 | { "name": "com.gameframe.water2d" }
--------------------------------------------------------------------------------
/Runtime/com.gameframe.water2d.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 896a4d93be41e46f594b299dc5d0a4e6
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Runtime/csc.rsp:
--------------------------------------------------------------------------------
1 | -nowarn:CS0649
2 |
--------------------------------------------------------------------------------
/Runtime/csc.rsp.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: faf4ee4a5cda8f64ea6ade0656e71adf
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.gameframe.water2d",
3 | "displayName": "Gameframe.Water2D",
4 | "version": "2.0.1",
5 | "keywords": [],
6 | "author": {
7 | "name": "Cory Leach",
8 | "email": "cory.leach@gmail.com",
9 | "url": "https://github.com/coryleach",
10 | "github": "coryleach",
11 | "twitter": "coryleach"
12 | },
13 | "description": "> Splashy 2D water",
14 | "repositoryName": "UnityWater2D"
15 | }
--------------------------------------------------------------------------------
/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bd955e491d52740e199e05365d6f9dc0
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------