summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-20 22:36:58 +0800
committerchai <215380520@qq.com>2024-05-20 22:36:58 +0800
commita22c505984697881f5f911a165ee022087b69e09 (patch)
treed3c030aef1ae9b8a01c889dd2902bb1e3324e72b /Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs
parent4a4cc82d069b26bc4d4532e73860f86b211ca239 (diff)
*renameHEADmaster
Diffstat (limited to 'Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs')
-rw-r--r--Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs105
1 files changed, 0 insertions, 105 deletions
diff --git a/Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs b/Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs
deleted file mode 100644
index 9e876ab..0000000
--- a/Thronefall_1_57/Thronefall/FlatKit/Buoyancy.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-using UnityEngine;
-
-namespace FlatKit;
-
-public class Buoyancy : MonoBehaviour
-{
- [Tooltip("The object that contains a Water material.")]
- public Transform water;
-
- [Space]
- [Tooltip("Range of probing wave height for buoyancy rotation.")]
- public float size = 1f;
-
- [Tooltip("Max height of buoyancy going up and down.")]
- public float amplitude = 1f;
-
- [Space]
- [Tooltip("Optionally provide a separate material to get the wave parameters.")]
- public Material overrideWaterMaterial;
-
- private Material _material;
-
- private float _speed;
-
- private float _amplitude;
-
- private float _frequency;
-
- private float _direction;
-
- private Vector3 _originalPosition;
-
- private void Start()
- {
- Renderer component = water.GetComponent<Renderer>();
- _material = ((overrideWaterMaterial != null) ? overrideWaterMaterial : component.sharedMaterial);
- _speed = _material.GetFloat("_WaveSpeed");
- _amplitude = _material.GetFloat("_WaveAmplitude");
- _frequency = _material.GetFloat("_WaveFrequency");
- _direction = _material.GetFloat("_WaveDirection");
- Transform transform = base.transform;
- _originalPosition = transform.position;
- }
-
- private void Update()
- {
- Vector3 position = base.transform.position;
- Vector3 positionOS = water.InverseTransformPoint(position);
- position.y = GetHeightOS(positionOS) + _originalPosition.y;
- base.transform.position = position;
- base.transform.up = GetNormalWS(positionOS);
- }
-
- private Vector2 GradientNoiseDir(Vector2 p)
- {
- p = new Vector2(p.x % 289f, p.y % 289f);
- float num = (34f * p.x + 1f) * p.x % 289f + p.y;
- num = (34f * num + 1f) * num % 289f;
- num = num / 41f % 1f * 2f - 1f;
- return new Vector2(num - Mathf.Floor(num + 0.5f), Mathf.Abs(num) - 0.5f).normalized;
- }
-
- private float GradientNoise(Vector2 p)
- {
- Vector2 vector = new Vector2(Mathf.Floor(p.x), Mathf.Floor(p.y));
- Vector2 vector2 = new Vector2(p.x % 1f, p.y % 1f);
- float a = Vector3.Dot(GradientNoiseDir(vector), vector2);
- float b = Vector3.Dot(GradientNoiseDir(vector + Vector2.up), vector2 - Vector2.up);
- float a2 = Vector3.Dot(GradientNoiseDir(vector + Vector2.right), vector2 - Vector2.right);
- float b2 = Vector3.Dot(GradientNoiseDir(vector + Vector2.one), vector2 - Vector2.one);
- vector2 = vector2 * vector2 * vector2 * (vector2 * (vector2 * 6f - Vector2.one * 15f) + Vector2.one * 10f);
- return Mathf.Lerp(Mathf.Lerp(a, b, vector2.y), Mathf.Lerp(a2, b2, vector2.y), vector2.x);
- }
-
- private Vector3 GetNormalWS(Vector3 positionOS)
- {
- Vector3 vector = positionOS + Vector3.forward * size;
- vector.y = GetHeightOS(vector);
- Vector3 vector2 = positionOS + Vector3.right * size;
- vector2.y = GetHeightOS(vector);
- Vector3 normalized = Vector3.Cross(vector - positionOS, vector2 - positionOS).normalized;
- return water.TransformDirection(normalized);
- }
-
- private float SineWave(Vector3 positionOS, float offset)
- {
- float num = Time.timeSinceLevelLoad * 2f;
- float num2 = Mathf.Sin(offset + num * _speed + (positionOS.x * Mathf.Sin(offset + _direction) + positionOS.z * Mathf.Cos(offset + _direction)) * _frequency);
- if (_material.IsKeywordEnabled("_WAVEMODE_POINTY"))
- {
- num2 = 1f - Mathf.Abs(num2);
- }
- return num2 * _amplitude;
- }
-
- private float GetHeightOS(Vector3 positionOS)
- {
- float num = SineWave(positionOS, 0f);
- if (_material.IsKeywordEnabled("_WAVEMODE_GRID"))
- {
- num *= SineWave(positionOS, 1.57f);
- }
- return num * amplitude;
- }
-}