| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<RectTransform>();
- }
- 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<RectTransform>().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);
- }
- }
- }
- }
|