using ProjectBase.UI; using ShotSimulator.Train; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace ShotSimulator.UI { public class CursorUIView : BaseUIView { public RectTransform canvasRT; private CursorType current_CursorType; private GameObject current_Cursor; public GameObject m_UICursor; public GameObject m_DefaultCursor; public GameObject m_SnipeCursor; protected override void InitUIObjects() { base.InitUIObjects(); canvasRT = transform.GetComponent(); } protected override void UpdateArguments(params object[] args) { base.UpdateArguments(args); current_CursorType = (CursorType)Enum.ToObject(typeof(CursorType), args[0]); } protected override void UpdateViewCallBack() { base.UpdateViewCallBack(); SetCurrentCursor(current_CursorType); } protected override void OnShowCallBack() { base.OnShowCallBack(); } private void Update() { if (TrainTaskLoader.GetInstance().CurTrainHandle != null) { if (TrainTaskLoader.GetInstance().CurTrainHandle.IsRunning) { if (!TrainTaskLoader.GetInstance().CurTrainHandle.IsPause) { if (VirtualMouse.GetInstance().IsSelectUIObject()) { SetCurrentCursor(CursorType.UICursor); } else { SetCurrentCursor(TrainTaskLoader.GetInstance().CurTrainHandle.TrainInfo.cursorType); } } } } } private void LateUpdate() { if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRT, VirtualMouse.GetInstance().screenPos, UIManager.GetInstance().m_UICamera, out var pos)) { if (current_Cursor != null) { current_Cursor.GetComponent().localPosition = pos; } } } private void SetCurrentCursor(CursorType type) { if (current_Cursor != null) { current_Cursor.gameObject.SetActive(false); } switch (type) { case CursorType.UICursor: current_Cursor = m_UICursor; break; case CursorType.DefaultCursor: current_Cursor = m_DefaultCursor; break; case CursorType.SnipeCursor: current_Cursor = m_SnipeCursor; break; } if (!VirtualMouse.GetInstance().TacticalMode || type != CursorType.DefaultCursor) { current_Cursor.gameObject.SetActive(true); } } } }