CursorManager.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using CMF;
  2. using UnityEngine;
  3. using WS;
  4. [ObjectSystem]
  5. public class CursorManagerAwakeSystem : AwakeSystem<CursorManager>
  6. {
  7. public override void Awake(CursorManager self)
  8. {
  9. self.Awake();
  10. }
  11. }
  12. [ObjectSystem]
  13. public class CursorManagerUpdateSyste : UpdateSystem<CursorManager>
  14. {
  15. public override void Update(CursorManager self)
  16. {
  17. self.Update();
  18. }
  19. }
  20. public class CursorManager : SingleComponent<CursorManager>
  21. {
  22. public enum CursorState
  23. {
  24. Hide,
  25. HideAndMove,
  26. Show,
  27. ShowAndMove,
  28. }
  29. public CursorState cursorState;
  30. public CharacterKeyboardInput keyboardInput;
  31. public CameraController cameraController;
  32. public void Awake() { }
  33. public void Update() { }
  34. public void SetCursorState(CursorState state)
  35. {
  36. bool isControllerMove = false;
  37. switch (state)
  38. {
  39. case CursorState.Hide:
  40. Cursor.lockState = CursorLockMode.Locked;
  41. isControllerMove = false;
  42. break;
  43. case CursorState.HideAndMove:
  44. Cursor.lockState = CursorLockMode.Locked;
  45. isControllerMove = true;
  46. break;
  47. case CursorState.Show:
  48. Cursor.lockState = CursorLockMode.None;
  49. isControllerMove = false;
  50. break;
  51. case CursorState.ShowAndMove:
  52. Cursor.lockState = CursorLockMode.None;
  53. isControllerMove = true;
  54. break;
  55. }
  56. if (keyboardInput != null)
  57. {
  58. keyboardInput.useInput = isControllerMove;
  59. }
  60. if (cameraController != null)
  61. {
  62. cameraController.enabled = isControllerMove;
  63. }
  64. }
  65. }