43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UltimateWater
|
|
{
|
|
[AddComponentMenu("Ultimate Water/Dynamic/Water Force")]
|
|
public sealed class WaterForce : MonoBehaviour
|
|
{
|
|
public struct Data
|
|
{
|
|
public Vector3 Position;
|
|
|
|
public float Force;
|
|
}
|
|
|
|
[Tooltip("Force affecting water surface")]
|
|
public float Force = 0.01f;
|
|
|
|
[Tooltip("Area of water displacement")]
|
|
public float Radius = 1f;
|
|
|
|
private static readonly List<Data> _ForceData = new List<Data>(1);
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
Data item = default(Data);
|
|
item.Position = base.transform.position;
|
|
item.Force = Force * Time.fixedDeltaTime;
|
|
_ForceData.Clear();
|
|
_ForceData.Add(item);
|
|
WaterRipples.AddForce(_ForceData, Radius);
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.color = Color.green * 0.8f + Color.gray * 0.2f;
|
|
Gizmos.DrawLine(base.transform.position + Vector3.up * 2f, base.transform.position - Vector3.up * 2f);
|
|
Gizmos.DrawLine(base.transform.position + (Vector3.forward + Vector3.left), base.transform.position - (Vector3.forward + Vector3.left));
|
|
Gizmos.DrawLine(base.transform.position + (Vector3.forward - Vector3.left), base.transform.position - (Vector3.forward - Vector3.left));
|
|
}
|
|
}
|
|
}
|