WaterRangeCtrlTool.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. waterRangeMat.SetFloat("_ClipLength", 1);
  45. //for (int i = 0; i < FxObjects.Length; i++)
  46. //{
  47. // FxObjects[i].SetActive(false);
  48. //}
  49. }
  50. public void SetRangeValue(float value)
  51. {
  52. float rangeValue=0;
  53. switch (waterCurveIndex)
  54. {
  55. case 0 :
  56. rangeValue = waterCurve_65000.Evaluate(value);
  57. break;
  58. case 1 :
  59. rangeValue = waterCurve_70000.Evaluate(value);
  60. break;
  61. }
  62. waterRangeMat.SetFloat("_ClipLength",rangeValue);
  63. }
  64. public void ChangeWaterCurve(int index)
  65. {
  66. waterCurveIndex = index;
  67. }
  68. }