using System.Collections; using System.Collections.Generic; using UnityEngine; using HighlightPlus; using UnityEngine.EventSystems; using System; using Unity.VisualScripting; /// <summary> /// 常驻交互 /// </summary> public class PermanentTriggerBase : MonoBehaviour { public int triggerID; public string triggerName; public HighlightEffect _highlight; /// <summary> /// 打分事件 /// </summary> private Action<string, object, int, int> scoreAction; /// <summary> /// 手中飞出时的回调 /// </summary> protected Action hand_out_action; /// <summary> /// 收回手里的回调 /// </summary> protected Action hand_back_action; /// <summary> /// 是否初始化了 /// </summary> private bool isInit; public void Awake() { if (!isInit) { isInit = true; OnAwake(); if (ScoreManager.instance != null) { AddScoreAction(ScoreManager.instance.Check); } } } private void Start() { OnStart(); } private void SwitchSubProcessStepTriggerID(string arg0) { if (triggerName == arg0) { _highlight.SetHighlighted(true); } else { _highlight.SetHighlighted(false); } } /// <summary> /// Awake /// </summary> protected virtual void OnAwake() { if (GetComponent<HighlightEffect>()) _highlight = GetComponent<HighlightEffect>(); if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) GameManager.EventMgr.AddEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); } /// <summary> /// Start /// </summary> 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() { if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); } //private void OnDisable() //{ // GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); //} public void AddScoreAction(Action<string, object, int, int> back) { this.scoreAction = back; } /// <summary> /// 调用打分功能 /// </summary> /// <param name="para">参数 默认不传</param> /// /// <param name="triggerName">触发的物体识别号 默认传自己的</param> /// <param name="systemcid">系统id 默认当前系统</param> /// <param name="shchmeid">科目id 默认当前科目</param> 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); } }