using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class WaterRangeCtrlTool : MonoBehaviour { public static WaterRangeCtrlTool _Instance; public GameObject[] FxObjects; public Material waterRangeMat; public Transform hemian; public AnimationCurve waterCurveSZ; public AnimationCurve waterCurveVZ; public AnimationCurve waterCurve_65000; public AnimationCurve waterCurve_70000; public Action onCtrlChange; public int waterCurveIndex { private set; get; } private void Awake() { _Instance = this; FxObjects = new GameObject[this.transform.childCount]; for (int i = 0; i < FxObjects.Length; i++) { FxObjects[i] = this.gameObject.transform.GetChild(i).gameObject; //FxObjects[i].SetActive(true); } waterRangeMat = this.transform.Find("NeiHe_FenQu").GetComponent().material; //hemian = this.transform.Find("HeMianTrans"); ChangeWaterCurve(0); } public void ShowFx(bool reSetValue) { if (reSetValue) { SetRangeValue(0); } for (int i = 0; i < FxObjects.Length; i++) { FxObjects[i].SetActive(true); } hemian.transform.localPosition = Vector3.forward * 35; } public void HideFx() { waterRangeMat.SetFloat("_ClipLength", 1); hemian.transform.localPosition = Vector3.zero; for (int i = 0; i < FxObjects.Length; i++) { FxObjects[i].SetActive(false); } } public void SetRangeValue(float value) { //Debug.Log(value); float rangeValue=0; switch (waterCurveIndex) { case 0 : rangeValue = waterCurve_65000.Evaluate(value); break; case 1 : rangeValue = waterCurve_70000.Evaluate(value); break; } //Debug.Log(rangeValue); waterRangeMat.SetFloat("_ClipLength",rangeValue); onCtrlChange?.Invoke(rangeValue); } public void ChangeWaterCurve(int index) { waterCurveIndex = index; } }