using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; #if UNITY_EDITOR using UnityEditor; #endif using System.Linq; using HighlightingSystem; public class MoveItem : MonoBehaviour { [HideIf("m_IsHighterHide")] [LabelText("相对方向")] public Vector3 m_Direction = new Vector3(0, 0, 0); [HideIf("m_IsHighterHide")] /// /// 使用世界坐标方向 /// public bool m_UserGlobalDirection; [LabelText("运行时长")] public float m_Duration; [OnValueChanged("IsHighterHideValueChange")] [LabelText("高亮闪烁隐藏")] public bool m_IsHighterHide; private Vector3 m_CacheDirection = Vector3.zero; private void IsHighterHideValueChange(bool result) { if (result) { m_CacheDirection = m_Direction; m_Direction = Vector3.zero; } else { m_Direction = m_CacheDirection; } } public void OpenHighter(bool open) { HighlightingSystem.Highlighter highlighter = GetComponent() == null ? gameObject.AddComponent() : GetComponent(); if (open) { if (m_IsHighterHide) { highlighter.FlashingOn(Color.green, Color.yellow,4f); } else { highlighter.ConstantOn(); } }else { Destroy(highlighter); } } /// /// 设置初始状态 /// /// public void SetInitState(Vector3 position) { transform.position = position; } /// /// 设置最终状态 /// public void SetFianlState() { if (m_UserGlobalDirection) { transform.position = transform.position + m_Direction; }else { transform.position = transform.position + transform.TransformDirection(m_Direction); } } #if UNITY_EDITOR private void OnDrawGizmos() { DrawPathLine(); } public void DrawPathLine() { if (Selection.gameObjects.Contains(this.gameObject)) { Gizmos.color = Color.yellow; if (m_UserGlobalDirection) { Gizmos.DrawLine(transform.position, transform.position + m_Direction); } else { Gizmos.DrawLine(transform.position, transform.position + transform.TransformDirection(m_Direction)); } } } #endif }