WaterRangeCtrlTool.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class WaterRangeCtrlTool : MonoBehaviour
  6. {
  7. public static WaterRangeCtrlTool _Instance;
  8. public GameObject[] FxObjects;
  9. public Material waterRangeMat;
  10. public Transform hemian;
  11. public AnimationCurve waterCurveSZ;
  12. public AnimationCurve waterCurveVZ;
  13. public AnimationCurve waterCurve_65000;
  14. public AnimationCurve waterCurve_70000;
  15. public Action<float> onCtrlChange;
  16. public int waterCurveIndex
  17. {
  18. private set;
  19. get;
  20. }
  21. private void Awake()
  22. {
  23. _Instance = this;
  24. FxObjects = new GameObject[this.transform.childCount];
  25. for (int i = 0; i < FxObjects.Length; i++)
  26. {
  27. FxObjects[i] = this.gameObject.transform.GetChild(i).gameObject;
  28. //FxObjects[i].SetActive(true);
  29. }
  30. waterRangeMat = this.transform.Find("NeiHe_FenQu").GetComponent<MeshRenderer>().material;
  31. //hemian = this.transform.Find("HeMianTrans");
  32. ChangeWaterCurve(0);
  33. }
  34. public void ShowFx(bool reSetValue)
  35. {
  36. if (reSetValue)
  37. {
  38. SetRangeValue(0);
  39. }
  40. for (int i = 0; i < FxObjects.Length; i++)
  41. {
  42. FxObjects[i].SetActive(true);
  43. }
  44. hemian.transform.localPosition = Vector3.forward * 35;
  45. }
  46. public void HideFx()
  47. {
  48. waterRangeMat.SetFloat("_ClipLength", 1);
  49. hemian.transform.localPosition = Vector3.zero;
  50. for (int i = 0; i < FxObjects.Length; i++)
  51. {
  52. FxObjects[i].SetActive(false);
  53. }
  54. }
  55. public void SetRangeValue(float value)
  56. {
  57. //Debug.Log(value);
  58. float rangeValue=0;
  59. switch (waterCurveIndex)
  60. {
  61. case 0 :
  62. rangeValue = waterCurve_65000.Evaluate(value);
  63. break;
  64. case 1 :
  65. rangeValue = waterCurve_70000.Evaluate(value);
  66. break;
  67. }
  68. //Debug.Log(rangeValue);
  69. waterRangeMat.SetFloat("_ClipLength",rangeValue);
  70. onCtrlChange?.Invoke(rangeValue);
  71. }
  72. public void ChangeWaterCurve(int index)
  73. {
  74. waterCurveIndex = index;
  75. }
  76. }