WaterRangeCtrlTool.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. ChangeWaterCurve(0);
  29. }
  30. public void ShowFx(bool reSetValue)
  31. {
  32. if (reSetValue)
  33. {
  34. SetRangeValue(1);
  35. }
  36. for (int i = 0; i < FxObjects.Length; i++)
  37. {
  38. FxObjects[i].SetActive(true);
  39. }
  40. }
  41. public void HideFx()
  42. {
  43. for (int i = 0; i < FxObjects.Length; i++)
  44. {
  45. FxObjects[i].SetActive(false);
  46. }
  47. }
  48. public void SetRangeValue(float value)
  49. {
  50. float rangeValue=0;
  51. switch (waterCurveIndex)
  52. {
  53. case 0 :
  54. rangeValue = waterCurve_65000.Evaluate(value);
  55. break;
  56. case 1 :
  57. rangeValue = waterCurve_65000.Evaluate(value);
  58. break;
  59. }
  60. waterRangeMat.SetFloat("_ClipLength",rangeValue);
  61. }
  62. public void ChangeWaterCurve(int index)
  63. {
  64. waterCurveIndex = index;
  65. }
  66. }