上海苏宁宝丽嘉酒店,2020.11.17 15:30改为单机版本,以后合成单机版本可以以此版本为模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

230 lines
6.4 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using AX.InputSystem;
using System;
using AX.MessageSystem;
/// <summary>
/// 鼠标指针管理类【单利模式】(游戏中,不同状态对于不同指针)
/// </summary>
public class CursorManager : MonoBehaviour
{
/// <summary>
/// 私有静态成员
/// </summary>
private static CursorManager instance;
private GameObject cursor;
private GameObject replayCursor;
private Transform cursorParent;
private DateTime t1;
private DateTime t2;
/// <summary>
/// 外部访问,公共静态成员(单例)
/// </summary>
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<Canvas>())
//{
// c = cursor.AddComponent<Canvas>();
//}
//else
//{
// c = cursor.GetComponent<Canvas>();
//}
//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);
// }
// }
//}
}
/// <summary>
/// 正常状态指针图
/// </summary>
public GameObject cursorNormal;
public Sprite cursorNormalSprite;
/// <summary>
/// 单击状态指针
/// </summary>
public Sprite cursorClickSprite;
/// <summary>
/// 对话状态指针图
/// </summary>
//public Texture2D cursorNpcTalk;
/// <summary>
/// 攻击状态指针图
/// </summary>
//public Texture2D cursorAttack;
/// <summary>
/// 锁定状态指针图
/// </summary>
//public Texture2D cursorLockTarget;
/// <summary>
/// 拾捡物品状态指针图
/// </summary>
//public Texture2D cursorPick;
/// <summary>
/// 指针默认点击热点位置(指针左上角)
/// </summary>
//private Vector2 hotspot = Vector2.zero;
/// <summary>
/// 指针类型(Auto:自动选择)
/// </summary>
//private CursorMode mode = CursorMode.Auto;
/// <summary>
/// 设置默认指针显示图
/// </summary>
public void SetNormal()
{
Vector3 pos;
if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)cursorParent, Input.mousePosition, cursorParent.gameObject.GetComponent<Canvas>().worldCamera, out pos))
{
cursor.GetComponent<RectTransform>().position = pos;
}
//光标始终悬浮在UI上
cursor.transform.SetAsLastSibling();
}
public void SetNormalType()
{
cursor.GetComponent<Image>().sprite = cursorNormalSprite;
}
private void SetNormalType(IMessage msg)
{
//SetNormalType();
}
/// <summary>
/// 点击UI时的指针图
/// </summary>
public void SetClick(CmdArgs arg)
{
//if (!replayCursor)
//{
// replayCursor = Instantiate(cursorNormal, cursorParent) as GameObject;
// Canvas c;
// if (!replayCursor.GetComponent<Canvas>())
// {
// c = replayCursor.AddComponent<Canvas>();
// }
// else
// {
// c = replayCursor.GetComponent<Canvas>();
// }
// c.overrideSorting = true;
// c.sortingOrder = 30001;
// replayCursor.GetComponent<Image>().sprite = cursorClickSprite;
// Vector3 pos;
// if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)cursorParent, arg.currentCursorPos, cursorParent.gameObject.GetComponent<Canvas>().worldCamera, out pos))
// {
// replayCursor.GetComponent<RectTransform>().position = pos;
// }
//}
//else
//{
// replayCursor.GetComponent<Image>().sprite = cursorClickSprite;
// Vector3 pos;
// if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)cursorParent, arg.currentCursorPos, cursorParent.gameObject.GetComponent<Canvas>().worldCamera, out pos))
// {
// replayCursor.GetComponent<RectTransform>().position = pos;
// }
//}
}
}