using System.Collections; using System.Collections.Generic; using UnityEngine; using HighlightPlus; using UnityEngine.EventSystems; using System; using DG.Tweening; using System.Runtime.Serialization.Formatters.Binary; /// /// 常驻交互 /// public class PermanentTriggerBase : MonoBehaviour { public int triggerID; public string triggerName; public HighlightEffect _highlight; /// /// 打分事件 /// private Action scoreAction; /// /// 手中飞出时的回调 /// protected Action hand_out_action; /// /// 收回手里的回调 /// protected Action hand_back_action; /// /// 是否初始化了 /// private bool isInit; public Tween tween; public void Awake() { if (!isInit) { isInit = true; OnAwake(); } } private void Start() { OnStart(); } private void SwitchSubProcessStepTriggerID(string arg0) { try { string info = ""; if (arg0.Contains("+")) { info = arg0.Split('+')[1]; } else { info = arg0; } if (_highlight != null) { if (triggerName == info) { _highlight.SetHighlighted(true); tween = DOVirtual.Float(1, 0f, 1f, t => { _highlight.outline = t; _highlight.innerGlow = t; }).SetLoops(-1, LoopType.Yoyo); } else { _highlight.SetHighlighted(false); if (tween != null) tween.Kill(true); } _highlight.Refresh(); } } catch (Exception e) { Debug.LogError(e.Message + " " + arg0); } } /// /// Awake /// protected virtual void OnAwake() { if (GetComponent()) { _highlight = GetComponent(); _highlight.outlineWidth = 0.5f; float factor = Mathf.Pow(2, 3f); Color tempColor = _highlight.outlineColor; _highlight.innerGlowColor = tempColor; if (triggerName != "收回工具" && triggerName != "NPC客户" && triggerName != "NPC负责人") _highlight.outlineColor = new Color(tempColor.r * factor, tempColor.g * factor, tempColor.b * factor); //_highlight.innerGlowColor. } } /// /// Start /// protected virtual void OnStart() { } private void OnMouseEnter() { if (EventSystem.current.IsPointerOverGameObject()) return; OnMEnter(); } private void OnMouseDown() { if (EventSystem.current.IsPointerOverGameObject()) return; OnMDown(); } private void OnMouseExit() { if (EventSystem.current.IsPointerOverGameObject()) return; OnMExit(); } protected virtual void OnMEnter() { } protected virtual void OnMDown() { } protected virtual void OnMExit() { } protected virtual void OnDestroy() { } //private void OnDisable() //{ // GameManager.EventMgr.RemoveEventListener(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); //} public void AddScoreAction(Action back) { this.scoreAction = back; } /// /// 调用打分功能 /// /// 参数 默认不传 /// /// 触发的物体识别号 默认传自己的 /// 系统id 默认当前系统 /// 科目id 默认当前科目 public void CallScoreAction(object para = null, string triggerName = null, int systemcid = 0, int shchmeid = 0) { scoreAction?.Invoke(triggerName == null ? this.triggerName : triggerName, para, systemcid, shchmeid); } /// /// 保存Trigger的自身具体信息,参考scoreBase /// //public virtual string SaveCurrentTriggerStat() { return ""; } /// /// 加载Trigger的自身具体信息,参考scoreBase /// //public virtual void LoadCurrentTriggerStat(string triggerInfo) { } }