WaterRangeCtrlTool.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. float rangeValue=0;
  57. switch (waterCurveIndex)
  58. {
  59. case 0 :
  60. rangeValue = waterCurve_65000.Evaluate(value);
  61. break;
  62. case 1 :
  63. rangeValue = waterCurve_70000.Evaluate(value);
  64. break;
  65. }
  66. waterRangeMat.SetFloat("_ClipLength",rangeValue);
  67. }
  68. public void ChangeWaterCurve(int index)
  69. {
  70. waterCurveIndex = index;
  71. }
  72. }