Advertisement
shadowx320

InputHandler.cs

Apr 23rd, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace SA
  6. {
  7. public class InputHandler : MonoBehaviour
  8. {
  9. float vertical;
  10. float horizontal;
  11. bool b_input;
  12. bool a_input;
  13. bool x_input;
  14. bool y_input;
  15.  
  16. bool rb_input;
  17. float rt_axis;
  18. bool rt_input;
  19. bool lb_input;
  20. float lt_axis;
  21. bool lt_input;
  22.  
  23. bool leftAxis_down;
  24. bool rightAxis_down;
  25.  
  26. StateManager states;
  27. CameraManager camManager;
  28.  
  29. float delta;
  30.  
  31. void Start ()
  32. {
  33. states = GetComponent<StateManager>();
  34. states.Init();
  35.  
  36. camManager = CameraManager.singleton;
  37. camManager.Init(this.transform);
  38. }
  39.  
  40. void FixedUpdate ()
  41. {
  42. delta = Time.fixedDeltaTime;
  43. GetInput();
  44. UpdateStates();
  45. states.FixedTick(Time.deltaTime);
  46. camManager.Tick(delta);
  47. }
  48.  
  49. void Update()
  50. {
  51. delta = Time.deltaTime;
  52. states.Tick(delta);
  53. }
  54.  
  55. void GetInput()
  56. {
  57. vertical = Input.GetAxis("Vertical");
  58. horizontal = Input.GetAxis("Horizontal");
  59. b_input = Input.GetButton("B");
  60. a_input = Input.GetButton("A");
  61. y_input = Input.GetButtonUp("Y");
  62. x_input = Input.GetButton("X");
  63. rt_input = Input.GetButton("RT");
  64. rt_axis = Input.GetAxis("RT");
  65. if (rt_axis != 0)
  66. rt_input = true;
  67.  
  68. lt_input = Input.GetButton("LT");
  69. lt_axis = Input.GetAxis("LT");
  70. if (lt_axis != 0)
  71. lt_input = true;
  72.  
  73. rb_input = Input.GetButton("RB");
  74. lb_input = Input.GetButton("LB");
  75.  
  76. rightAxis_down = Input.GetButtonUp("L");
  77. }
  78.  
  79. void UpdateStates()
  80. {
  81. states.horizontal = horizontal;
  82. states.vertical = vertical;
  83.  
  84. Vector3 v = vertical * camManager.transform.forward;
  85. Vector3 h = horizontal * camManager.transform.right;
  86. states.moveDir = (v + h).normalized;
  87. float m = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
  88. states.moveAmount = Mathf.Clamp01(m);
  89.  
  90. states.rollInput = b_input;
  91.  
  92. if(b_input)
  93. {
  94. //states.run = (states.moveAmount > 0);
  95. }
  96. else
  97. {
  98. //states.run = false;
  99. }
  100.  
  101. states.rt = rt_input;
  102. states.lt = lt_input;
  103. states.rb = rb_input;
  104. states.lb = lb_input;
  105.  
  106. if(y_input)
  107. {
  108. states.isTwoHanded = !states.isTwoHanded;
  109. states.HandleTwoHanded();
  110. }
  111.  
  112. if(rightAxis_down)
  113. {
  114. states.lockOn = !states.lockOn;
  115.  
  116. if(states.lockOnTarget == null)
  117. states.lockOn = false;
  118.  
  119. camManager.lockonTarget = states.lockOnTarget;
  120. camManager.lockon = states.lockOn;
  121. }
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement