using System.Collections.Generic; using UnityEngine; namespace UltimateWater { [AddComponentMenu("Ultimate Water/Water Profile Blend")] public class WaterProfileBlend : MonoBehaviour { public Water Water; [SerializeField] private List _Profiles = new List { null }; [SerializeField] private List _Weights = new List { 1f }; private void Awake() { if (Water == null) { Water = Utilities.GetWaterReference(); if (Water.IsNullReference(this)) { return; } } _Profiles.RemoveAll((WaterProfile x) => x == null); if (_Profiles.Count == 0) { Debug.LogError("[WaterProfileBlend] : no valid profiles found"); base.enabled = false; } } private void Start() { Water.ProfilesManager.SetProfiles(CreateProfiles(_Profiles, _Weights)); } private void OnValidate() { if (Application.isPlaying && Water != null && Water.WindWaves != null) { Water.ProfilesManager.SetProfiles(CreateProfiles(_Profiles, _Weights)); } if (WeightSum(_Weights) == 0f) { _Weights[0] = 1f; } } private void Reset() { if (Water == null) { Water = Utilities.GetWaterReference(); } } private static Water.WeightedProfile[] CreateProfiles(List profiles, List weights) { List list = NormalizeWeights(weights); int count = profiles.Count; Water.WeightedProfile[] array = new Water.WeightedProfile[count]; for (int i = 0; i < count; i++) { array[i] = new Water.WeightedProfile(profiles[i], list[i]); } return array; } private static float WeightSum(List weights) { float num = 0f; for (int i = 0; i < weights.Count; i++) { num += weights[i]; } return num; } private static List NormalizeWeights(List weights) { List list = new List(weights.Count); float num = WeightSum(weights); for (int i = 0; i < weights.Count; i++) { list.Add(weights[i] / num); } return list; } } }