using HighlightPlus; using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; /// /// 工具或者材料基类,此脚本必须挂在工具或者材料上 /// public abstract class BaseToolOrDevice : MonoBehaviour { //public struct ItemInfo //{ // public int toolId; // public string toolName; // public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial; //} public class ItemInfo { public int toolId; public string toolName; public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial; public ItemInfo(int id, string Name, E_ToolOrDeviceOrMaterials itemType) { toolId = id; toolName = Name; toolOrDeviceOrMaterial = itemType; } // 你可以在这里添加更多的属性和方法 } ///// ///// 工具Id ///// //public int toolId; //public string toolName; ///// ///// 工器具类型 工具/材质/设备 ///// //public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial; public HighlightEffect _highlight; public bool IsClick = true; private SomeOtherClass otherClass = new SomeOtherClass(); private Dictionary itemDatabase = new Dictionary(); private void Start() { _highlight = GetComponent(); //itemDatabase.Add("Screwdriver", new ItemInfo { toolId = 2, toolName = "螺丝刀", toolOrDeviceOrMaterial = E_ToolOrDeviceOrMaterials.Tool }); } public class SomeOtherClass { public void ProcessItemInfo(ItemInfo itemInfo) { Debug.Log($"处理物品: ID={itemInfo.toolId}, 中文名={itemInfo.toolName}, 类型={itemInfo.toolOrDeviceOrMaterial}"); } } [ContextMenu("GetInfo")] public void GetInfo(string itemName) { if (itemDatabase.ContainsKey(itemName)) { ItemInfo info = itemDatabase[itemName]; otherClass.ProcessItemInfo(info); // 设置ItemInfo对象 } } //public void GetInfo(string itemName) //{ // if (itemDatabase.ContainsKey(itemName)) // { // ItemInfo info = itemDatabase[itemName]; // OnItemInfoReceived?.Invoke(info); // } //} //public void GetInfo(GameObject Item,string ItemName,E_ToolOrDeviceOrMaterials E_Item) //{ // Item.SetActive(false); // if (itemDatabase.ContainsKey(ItemName)) // { // // 获取物品信息 // ItemInfo info = itemDatabase[ItemName]; // // TODO: 后续处理,例如更新UI或执行其他逻辑 // } // else // { // Debug.LogWarning($"物品 '{ItemName}' 不存在于数据库中"); // } // switch (E_Item) // { // case E_ToolOrDeviceOrMaterials.Tool: // break; // case E_ToolOrDeviceOrMaterials.Materials: // break; // } // //TODO:后续 根据英文名称去获取ID 中文名 和其它 //} private void OnMouseEnter() { if (GameManager.RunModelMgr.SceneType!= E_SceneType.ToolRoom) return; if (EventSystem.current.IsPointerOverGameObject()) return; OnEnter(); //TODO: 这里写提示打开的代码 UIManager.Instance.ShowPanel(E_UI_Layer.System, (panel) => { panel.Init(gameObject.name); //GetComponentInChildren().text = gameObject.name; //transform.position = Input.mousePosition + new Vector3(10, 10, 0); }); //提示面板 } private void OnMouseDown() { if (GameManager.RunModelMgr.SceneType!= E_SceneType.ToolRoom) return; if (EventSystem.current.IsPointerOverGameObject()) return; OnDown(); //gameObject.SetActive(false); } private void OnMouseExit() { UIManager.Instance.HidePanel();//提示面板 //TODO: 这里写提示关闭的代码 if (GameManager.RunModelMgr.SceneType!= E_SceneType.ToolRoom) return; if (EventSystem.current.IsPointerOverGameObject()) return; OnExit(); } public virtual void OnEnter() { Debug.Log("进入"); } public virtual void OnDown() { Debug.Log("点击"); } public virtual void OnExit() { Debug.Log("离开"); } }