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. highlighter.overlay = true;
  42. if (open)
  43. {
  44. if (m_IsHighterHide)
  45. {
  46. highlighter.FlashingOn(Color.yellow, new Color(1,1,0,0),4f);
  47. }
  48. else
  49. {
  50. highlighter.ConstantOn();
  51. }
  52. }else
  53. {
  54. Destroy(highlighter);
  55. }
  56. }
  57. /// <summary>
  58. /// 设置初始状态
  59. /// </summary>
  60. /// <param name="position"></param>
  61. public void SetInitState(Vector3 position)
  62. {
  63. transform.position = position;
  64. }
  65. /// <summary>
  66. /// 设置最终状态
  67. /// </summary>
  68. public void SetFianlState()
  69. {
  70. if (m_UserGlobalDirection)
  71. {
  72. transform.position = transform.position + m_Direction;
  73. }else
  74. {
  75. transform.position = transform.position + transform.TransformDirection(m_Direction);
  76. }
  77. }
  78. #if UNITY_EDITOR
  79. private void OnDrawGizmos()
  80. {
  81. DrawPathLine();
  82. }
  83. public void DrawPathLine()
  84. {
  85. if (Selection.gameObjects.Contains(this.gameObject))
  86. {
  87. Gizmos.color = Color.yellow;
  88. if (m_UserGlobalDirection)
  89. {
  90. Gizmos.DrawLine(transform.position, transform.position + m_Direction);
  91. }
  92. else
  93. {
  94. Gizmos.DrawLine(transform.position, transform.position + transform.TransformDirection(m_Direction));
  95. }
  96. }
  97. }
  98. #endif
  99. }