WaterRangeCtrlTool.cs 2.1 KB

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