MoveItem.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. #if UNITY_EDITOR
  6. using UnityEditor;
  7. #endif
  8. using System.Linq;
  9. using HighlightingSystem;
  10. public class MoveItem : MonoBehaviour
  11. {
  12. [HideIf("m_IsHighterHide")]
  13. [LabelText("相对方向")]
  14. public Vector3 m_Direction = new Vector3(0, 0, 0);
  15. [HideIf("m_IsHighterHide")]
  16. /// <summary>
  17. /// 使用世界坐标方向
  18. /// </summary>
  19. public bool m_UserGlobalDirection;
  20. [LabelText("运行时长")]
  21. public float m_Duration;
  22. [OnValueChanged("IsHighterHideValueChange")]
  23. [LabelText("高亮闪烁隐藏")]
  24. public bool m_IsHighterHide;
  25. private Vector3 m_CacheDirection = Vector3.zero;
  26. private void IsHighterHideValueChange(bool result)
  27. {
  28. if (result)
  29. {
  30. m_CacheDirection = m_Direction;
  31. m_Direction = Vector3.zero;
  32. }
  33. else
  34. {
  35. m_Direction = m_CacheDirection;
  36. }
  37. }
  38. public void OpenHighter(bool open)
  39. {
  40. HighlightingSystem.Highlighter highlighter = GetComponent<HighlightingSystem.Highlighter>() == null ? gameObject.AddComponent<HighlightingSystem.Highlighter>() : GetComponent<HighlightingSystem.Highlighter>();
  41. if (open)
  42. {
  43. if (m_IsHighterHide)
  44. {
  45. highlighter.FlashingOn(Color.green, Color.yellow,4f);
  46. }
  47. else
  48. {
  49. highlighter.ConstantOn();
  50. }
  51. }else
  52. {
  53. Destroy(highlighter);
  54. }
  55. }
  56. /// <summary>
  57. /// 设置初始状态
  58. /// </summary>
  59. /// <param name="position"></param>
  60. public void SetInitState(Vector3 position)
  61. {
  62. transform.position = position;
  63. }
  64. /// <summary>
  65. /// 设置最终状态
  66. /// </summary>
  67. public void SetFianlState()
  68. {
  69. if (m_UserGlobalDirection)
  70. {
  71. transform.position = transform.position + m_Direction;
  72. }else
  73. {
  74. transform.position = transform.position + transform.TransformDirection(m_Direction);
  75. }
  76. }
  77. #if UNITY_EDITOR
  78. private void OnDrawGizmos()
  79. {
  80. DrawPathLine();
  81. }
  82. public void DrawPathLine()
  83. {
  84. if (Selection.gameObjects.Contains(this.gameObject))
  85. {
  86. Gizmos.color = Color.yellow;
  87. if (m_UserGlobalDirection)
  88. {
  89. Gizmos.DrawLine(transform.position, transform.position + m_Direction);
  90. }
  91. else
  92. {
  93. Gizmos.DrawLine(transform.position, transform.position + transform.TransformDirection(m_Direction));
  94. }
  95. }
  96. }
  97. #endif
  98. }