117 lines
1.7 KiB
C#
117 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace UltimateWater
|
|
{
|
|
[AddComponentMenu("Ultimate Water/Water Profile Blend (simple)")]
|
|
public class WaterProfileBlendSimple : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Water _Water;
|
|
|
|
[SerializeField]
|
|
[Header("Profiles")]
|
|
private WaterProfile _First;
|
|
|
|
[SerializeField]
|
|
private WaterProfile _Second;
|
|
|
|
[Header("Blend:")]
|
|
[SerializeField]
|
|
[Range(0f, 1f)]
|
|
private float _Factor;
|
|
|
|
private readonly Water.WeightedProfile[] _Profiles = new Water.WeightedProfile[2];
|
|
|
|
public Water Water
|
|
{
|
|
get
|
|
{
|
|
return _Water;
|
|
}
|
|
set
|
|
{
|
|
_Water = value;
|
|
UpdateProfiles();
|
|
}
|
|
}
|
|
|
|
public WaterProfile First
|
|
{
|
|
get
|
|
{
|
|
return _First;
|
|
}
|
|
set
|
|
{
|
|
_First = value;
|
|
UpdateProfiles();
|
|
}
|
|
}
|
|
|
|
public WaterProfile Second
|
|
{
|
|
get
|
|
{
|
|
return _Second;
|
|
}
|
|
set
|
|
{
|
|
_Second = value;
|
|
UpdateProfiles();
|
|
}
|
|
}
|
|
|
|
public float Factor
|
|
{
|
|
get
|
|
{
|
|
return _Factor;
|
|
}
|
|
set
|
|
{
|
|
_Factor = Mathf.Clamp01(value);
|
|
UpdateProfiles();
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (Water == null)
|
|
{
|
|
Water = Utilities.GetWaterReference();
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
UpdateProfiles();
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (Application.isPlaying && !(Water == null) && Water.WindWaves != null)
|
|
{
|
|
UpdateProfiles();
|
|
}
|
|
}
|
|
|
|
private void Reset()
|
|
{
|
|
if (Water == null)
|
|
{
|
|
Water = Utilities.GetWaterReference();
|
|
}
|
|
}
|
|
|
|
private void UpdateProfiles()
|
|
{
|
|
if (!(Water == null) && !(First == null) && !(Second == null))
|
|
{
|
|
_Profiles[0] = new Water.WeightedProfile(First, 1f - Factor);
|
|
_Profiles[1] = new Water.WeightedProfile(Second, Factor);
|
|
Water.ProfilesManager.SetProfiles(_Profiles);
|
|
}
|
|
}
|
|
}
|
|
}
|