OldBlueWater/BlueWater/Assets/NWH/Dynamic Water Physics 2/Scripts/SailController/WindIndicator.cs

69 lines
1.6 KiB
C#
Raw Normal View History

2023-12-19 02:31:29 +00:00
using UnityEngine;
#if UNITY_EDITOR
using NWH.DWP2.NUI;
using NWH.DWP2.SailController;
using UnityEditor;
#endif
namespace NWH.DWP2.SailController
{
/// <summary>
/// Shows apparent wind if placed as a child of the SailController,
/// or true wind otherwise.
/// </summary>
public class WindIndicator : MonoBehaviour
{
private SailController _sailController;
private void Awake()
{
_sailController = GetComponentInParent<SailController>();
}
private void Update()
{
if (_sailController != null)
{
// Show apparent wind.
transform.rotation = Quaternion.LookRotation(_sailController.ApparentWind.normalized,
transform.parent.up);
}
else if (WindGenerator.Instance != null)
{
// Show true wind.
transform.rotation = Quaternion.LookRotation(WindGenerator.Instance.CurrentWind.normalized,
transform.parent.up);
}
}
}
}
#if UNITY_EDITOR
namespace NWH.DWP2.SailController
{
[CustomEditor(typeof(WindIndicator))]
[CanEditMultipleObjects]
public class WindIndicatorEditor : DWP_NUIEditor
{
public override bool OnInspectorNUI()
{
if (!base.OnInspectorNUI())
{
return false;
}
drawer.Info("Shows apparent wind if placed as a child of the SailController, " +
"or true wind otherwise.");
drawer.EndEditor(this);
return true;
}
}
}
#endif