WaterRangeCtrlTool.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 AnimationCurve waterCurveSZ;
  11. public AnimationCurve waterCurveVZ;
  12. public AnimationCurve waterCurve_65000;
  13. public int waterCurveIndex
  14. {
  15. private set;
  16. get;
  17. }
  18. private void Awake()
  19. {
  20. _Instance = this;
  21. FxObjects = new GameObject[this.transform.childCount];
  22. for (int i = 0; i < FxObjects.Length; i++)
  23. {
  24. FxObjects[i] = this.gameObject.transform.GetChild(i).gameObject;
  25. FxObjects[i].SetActive(true);
  26. }
  27. waterRangeMat = this.transform.Find("NeiHe_FenQu").GetComponent<MeshRenderer>().material;
  28. }
  29. public void ShowFx(bool reSetValue)
  30. {
  31. if (reSetValue)
  32. {
  33. SetRangeValue(1);
  34. }
  35. for (int i = 0; i < FxObjects.Length; i++)
  36. {
  37. FxObjects[i].SetActive(true);
  38. }
  39. }
  40. public void HideFx()
  41. {
  42. for (int i = 0; i < FxObjects.Length; i++)
  43. {
  44. FxObjects[i].SetActive(false);
  45. }
  46. }
  47. public void SetRangeValue(float value)
  48. {
  49. float rangeValue=0;
  50. switch (waterCurveIndex)
  51. {
  52. case 0 :
  53. rangeValue = waterCurve_65000.Evaluate(value);
  54. break;
  55. case 1 :
  56. rangeValue = waterCurve_65000.Evaluate(value);
  57. break;
  58. }
  59. waterRangeMat.SetFloat("_ClipLength",rangeValue);
  60. }
  61. public void ChangeWaterCurve(int index)
  62. {
  63. waterCurveIndex = index;
  64. }
  65. }