UIManager.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.SceneManagement;
  7. public class UIManager : MonoBehaviour {
  8. public static UIManager instance;
  9. #region 变量声明
  10. //撤销全部按钮
  11. public Button RevokeAll_btn;
  12. //撤销按钮
  13. public Button Revoke_btn;
  14. RaycastHit _Hit;
  15. Ray _Ray;
  16. #endregion
  17. #region 私有方法
  18. private void Awake()
  19. {
  20. instance = this;
  21. BtnAddClick();
  22. }
  23. private void Update()
  24. {
  25. if (Input.GetMouseButtonDown(0))
  26. {
  27. _Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  28. if (!EventSystem.current.IsPointerOverGameObject())
  29. {
  30. if (Physics.Raycast(_Ray, out _Hit))
  31. {
  32. DeviceStateManager.Instance.AddObjToPool(_Hit.transform.gameObject);
  33. }
  34. }
  35. }
  36. //相机移动
  37. CameraMove();
  38. }
  39. /// <summary>
  40. /// 给Button添加事件
  41. /// </summary>
  42. private void BtnAddClick()
  43. {
  44. RevokeAll_btn.onClick.AddListener(RevokeAllBtnClick);
  45. Revoke_btn.onClick.AddListener(RevokeBtnClick);
  46. }
  47. private void OnOriginalDisplayToggleClick(bool isOn)
  48. {
  49. if (isOn)
  50. {
  51. RevokeAll_btn.gameObject.SetActive(false);
  52. Revoke_btn.gameObject.SetActive(false);
  53. RevokeAllBtnClick();
  54. }
  55. else
  56. {
  57. RevokeAll_btn.gameObject.SetActive(true);
  58. Revoke_btn.gameObject.SetActive(true);
  59. }
  60. }
  61. /// <summary>
  62. /// 撤销上一步操作
  63. /// </summary>
  64. private void RevokeBtnClick()
  65. {
  66. DeviceStateManager.Instance.RemoveObjToPool();
  67. }
  68. /// <summary>
  69. /// 退出操作
  70. /// </summary>
  71. private void CloseButtonClick()
  72. {
  73. Application.Quit();
  74. //SceneManager.LoadScene("MainScene");
  75. //QILunjiManager.Instance.RemoveAllFromPool();
  76. }
  77. /// <summary>
  78. /// 撤销所有操作
  79. /// </summary>
  80. private void RevokeAllBtnClick()
  81. {
  82. DeviceStateManager.Instance.RemoveAllFromPool();
  83. }
  84. /// <summary>
  85. /// 相机移动
  86. /// </summary>
  87. private void CameraMove()
  88. {
  89. //transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * 10f, 0, 0);
  90. //transform.Translate(0, 0, Input.GetAxis("Vertical") * Time.deltaTime * 10f);
  91. //if (Input.GetMouseButton(1))
  92. //{
  93. // _Rota.x -= Input.GetAxis("Mouse Y") * 60f * Time.deltaTime;
  94. // _Rota.y += Input.GetAxis("Mouse X") * 60f * Time.deltaTime;
  95. // Quaternion Q = Quaternion.Euler(_Rota);
  96. // transform.rotation = Q;
  97. //}
  98. }
  99. #endregion
  100. }