WaterRangeCtrlTool.cs 1.8 KB

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