CursorUIView.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using ProjectBase.UI;
  2. using ShotSimulator.Train;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace ShotSimulator.UI
  9. {
  10. public class CursorUIView : BaseUIView
  11. {
  12. public RectTransform canvasRT;
  13. private CursorType current_CursorType;
  14. private GameObject current_Cursor;
  15. public GameObject m_UICursor;
  16. public GameObject m_DefaultCursor;
  17. public GameObject m_SnipeCursor;
  18. protected override void InitUIObjects()
  19. {
  20. base.InitUIObjects();
  21. canvasRT = transform.GetComponent<RectTransform>();
  22. }
  23. protected override void UpdateArguments(params object[] args)
  24. {
  25. base.UpdateArguments(args);
  26. current_CursorType = (CursorType)Enum.ToObject(typeof(CursorType), args[0]);
  27. }
  28. protected override void UpdateViewCallBack()
  29. {
  30. base.UpdateViewCallBack();
  31. SetCurrentCursor(current_CursorType);
  32. }
  33. protected override void OnShowCallBack()
  34. {
  35. base.OnShowCallBack();
  36. }
  37. private void Update()
  38. {
  39. if (TrainTaskLoader.GetInstance().CurTrainHandle != null)
  40. {
  41. if (TrainTaskLoader.GetInstance().CurTrainHandle.IsRunning)
  42. {
  43. if (!TrainTaskLoader.GetInstance().CurTrainHandle.IsPause)
  44. {
  45. if (VirtualMouse.GetInstance().IsSelectUIObject())
  46. {
  47. SetCurrentCursor(CursorType.UICursor);
  48. }
  49. else
  50. {
  51. SetCurrentCursor(TrainTaskLoader.GetInstance().CurTrainHandle.TrainInfo.cursorType);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. private void LateUpdate()
  58. {
  59. if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRT, VirtualMouse.GetInstance().screenPos, UIManager.GetInstance().m_UICamera, out var pos))
  60. {
  61. if (current_Cursor != null)
  62. {
  63. current_Cursor.GetComponent<RectTransform>().localPosition = pos;
  64. }
  65. }
  66. }
  67. private void SetCurrentCursor(CursorType type)
  68. {
  69. if (current_Cursor != null)
  70. {
  71. current_Cursor.gameObject.SetActive(false);
  72. }
  73. switch (type)
  74. {
  75. case CursorType.UICursor:
  76. current_Cursor = m_UICursor;
  77. break;
  78. case CursorType.DefaultCursor:
  79. current_Cursor = m_DefaultCursor;
  80. break;
  81. case CursorType.SnipeCursor:
  82. current_Cursor = m_SnipeCursor;
  83. break;
  84. }
  85. if (!VirtualMouse.GetInstance().TacticalMode || type != CursorType.DefaultCursor)
  86. {
  87. current_Cursor.gameObject.SetActive(true);
  88. }
  89. }
  90. }
  91. }