using DG.Tweening; using HighlightPlus; using System; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization; using TMPro; using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; [Serializable] public class ItemInfo { public int toolId; public int triggerID; public string toolName; public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial; public GameObject objPrefab; public Vector3 selfPosInToolRoom; public Vector3 selfAngleInToolRoom; public int index; } /// /// 工具或者材料基类,此脚本必须挂在工具或者材料上 /// public abstract class BaseToolOrDevice : MonoBehaviour { public ItemInfo itemInfo; [HideInInspector] public HighlightEffect _highlight; public Tween tween; private void Awake() { //此脚本仅工具间有用 if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) { Destroy(this); return; } if (GetComponent()) { _highlight = GetComponent(); _highlight.outlineWidth = 0.5f; _highlight.innerGlowColor = _highlight.outlineColor; } if (GameManager.RunModelMgr?.ModeType == E_ModeType.Study) GameManager.EventMgr?.AddEventListener(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); } private void SwitchSubProcessStepTriggerID(string arg0) { if (itemInfo.toolName == arg0) { tween = DOVirtual.Float(1, 0f, 1f, t => { _highlight.innerGlow = t; _highlight.outline = t; }).SetLoops(-1, LoopType.Yoyo); _highlight?.SetHighlighted(true); } else { _highlight?.SetHighlighted(false); if (tween != null) tween.Kill(true); } } public void GetInfo() { //_highlight = GetComponent(); D_ToolAndMaterialData dTMD = GameManager.ToolAndmaterialMgr.GetToolOrMaterialOrDeviceInfoByObjName(gameObject.name); if (dTMD != null) { itemInfo.toolId = dTMD.id; itemInfo.triggerID = dTMD.id; itemInfo.toolName = dTMD.objName; itemInfo.toolOrDeviceOrMaterial = (E_ToolOrDeviceOrMaterials)dTMD.type; gameObject.SetActive(true); itemInfo.objPrefab = Resources.Load("Prefabs/Objects/Tools/" + gameObject.name); itemInfo.selfPosInToolRoom = transform.position; itemInfo.selfAngleInToolRoom = transform.eulerAngles; } //else //{ // gameObject.SetActive(false); //} } private void OnMouseEnter() { if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) return; if (EventSystem.current.IsPointerOverGameObject()) return; OnEnter(); } private void OnMouseDown() { if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) return; if (EventSystem.current.IsPointerOverGameObject()) return; OnDown(); } private void OnMouseExit() { if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) return; OnExit(); if (EventSystem.current.IsPointerOverGameObject()) return; } public virtual void OnEnter() { //Debug.Log("进入"); } public virtual void OnDown() { //Debug.Log("点击"); } public virtual void OnExit() { //Debug.Log("离开"); } private void OnDestroy() { if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) GameManager.EventMgr.RemoveEventListener(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); } //private void OnDisable() //{ // GameManager.EventMgr.RemoveEventListener(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); //} }