using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AX.InputSystem; using System; using AX.MessageSystem; /// /// 鼠标指针管理类【单利模式】(游戏中,不同状态对于不同指针) /// public class CursorManager : MonoBehaviour { /// /// 私有静态成员 /// private static CursorManager instance; private GameObject cursor; private GameObject replayCursor; private Transform cursorParent; private DateTime t1; private DateTime t2; /// /// 外部访问,公共静态成员(单例) /// public static CursorManager GetInstance { get { return instance; } } void Start() { //赋值单例 instance = this; // Cursor.visible = false; cursorParent = GameObject.Find("Canvas").transform; // cursor = Instantiate(cursorNormal, cursorParent) as GameObject; //添加层控制 //Canvas c; //if (!cursor.GetComponent()) //{ // c = cursor.AddComponent(); //} //else //{ // c = cursor.GetComponent(); //} //c.overrideSorting = true; //c.sortingOrder = 30002; //if (GameSettings.othersSettings.isReplayMode) //{ // cursor.SetActive(false); //} } private void OnEnable() { MessageDispatcher.AddListener("DELETE_COMMAND", SetNormalType); MessageDispatcher.AddListener("CANCEL_SELECTED_COMMAND", SetNormalType); } private void OnDisable() { MessageDispatcher.RemoveListener("DELETE_COMMAND", SetNormalType); MessageDispatcher.RemoveListener("CANCEL_SELECTED_COMMAND", SetNormalType); } private void OnDestroy() { Cursor.visible = true; } private void Update() { //SetNormal(); //Cursor.visible = false; //if (GameSettings.othersSettings.isReplayMode) //{ // if (!GameSettings.othersSettings.isReplayPause && !GameSettings.othersSettings.isReplayOver) // { // if (replayCursor) // { // replayCursor.SetActive(true); // } // if (!cursor.activeSelf) // { // if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0) // { // cursor.SetActive(true); // t1 = DateTime.Now; // } // } // else // { // t2 = DateTime.Now; // if ((t2 - t1) >= new TimeSpan(0, 0, 0, 3, 0)) // { // if (Input.GetAxis("Mouse X") == 0 && Input.GetAxis("Mouse Y") == 0) // { // cursor.SetActive(false); // } // } // } // } // else // { // if (replayCursor) // { // replayCursor.SetActive(false); // } // if (cursor) // { // cursor.SetActive(true); // } // } //} } /// /// 正常状态指针图 /// public GameObject cursorNormal; public Sprite cursorNormalSprite; /// /// 单击状态指针 /// public Sprite cursorClickSprite; /// /// 对话状态指针图 /// //public Texture2D cursorNpcTalk; /// /// 攻击状态指针图 /// //public Texture2D cursorAttack; /// /// 锁定状态指针图 /// //public Texture2D cursorLockTarget; /// /// 拾捡物品状态指针图 /// //public Texture2D cursorPick; /// /// 指针默认点击热点位置(指针左上角) /// //private Vector2 hotspot = Vector2.zero; /// /// 指针类型(Auto:自动选择) /// //private CursorMode mode = CursorMode.Auto; /// /// 设置默认指针显示图 /// public void SetNormal() { Vector3 pos; if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)cursorParent, Input.mousePosition, cursorParent.gameObject.GetComponent().worldCamera, out pos)) { cursor.GetComponent().position = pos; } //光标始终悬浮在UI上 cursor.transform.SetAsLastSibling(); } public void SetNormalType() { cursor.GetComponent().sprite = cursorNormalSprite; } private void SetNormalType(IMessage msg) { //SetNormalType(); } /// /// 点击UI时的指针图 /// public void SetClick(CmdArgs arg) { //if (!replayCursor) //{ // replayCursor = Instantiate(cursorNormal, cursorParent) as GameObject; // Canvas c; // if (!replayCursor.GetComponent()) // { // c = replayCursor.AddComponent(); // } // else // { // c = replayCursor.GetComponent(); // } // c.overrideSorting = true; // c.sortingOrder = 30001; // replayCursor.GetComponent().sprite = cursorClickSprite; // Vector3 pos; // if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)cursorParent, arg.currentCursorPos, cursorParent.gameObject.GetComponent().worldCamera, out pos)) // { // replayCursor.GetComponent().position = pos; // } //} //else //{ // replayCursor.GetComponent().sprite = cursorClickSprite; // Vector3 pos; // if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)cursorParent, arg.currentCursorPos, cursorParent.gameObject.GetComponent().worldCamera, out pos)) // { // replayCursor.GetComponent().position = pos; // } //} } }