Advertisement
akitheone

Untitled

Oct 23rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System;
  6. using Assets.ClientScripts.net.packets.outgoing;
  7.  
  8. public class KeyboardInput : MonoBehaviour
  9. {
  10. private List<int> keyList = new List<int>();
  11. private List<int> action_keyList = new List<int>();
  12. public bool[] controls = new bool[(int)KeyInput.Count];
  13. public bool[] special_actions = new bool[(int)KeyInput.Count];
  14.  
  15. public float RotationSpeed = 100.0f;
  16.  
  17. public bool isLerpingPosition;
  18. public bool isLerpingRotating;
  19.  
  20. public float timeStartedLerping;
  21. public float timeToLerp;
  22.  
  23. public CharacterController _characterController;
  24.  
  25. public Guid myIndex;
  26. public Animator animator;
  27.  
  28. private void Awake()
  29. {
  30.  
  31. animator = GetComponent<Animator>();
  32. _characterController = GetComponent<CharacterController>();
  33.  
  34. }
  35.  
  36. public float Gravity = 14.5f;
  37. public KeyInput lastAction;
  38. private void Update()
  39. {
  40. if (animator == null)
  41. {
  42. animator = GetComponent<Animator>();
  43. }
  44.  
  45. if (myIndex == NetworkManager.instance.myIndex)
  46. {
  47. #region W Input
  48. if (Input.GetKeyDown(KeyCode.Tab))
  49. {
  50. special_actions[(int)KeyInput.TAB] = true;
  51. lastAction = KeyInput.TAB;
  52. }
  53.  
  54. if (Input.GetKeyDown(KeyCode.W))
  55. {
  56. controls[(int)KeyInput.W] = true;
  57. }
  58. else if (Input.GetKeyUp(KeyCode.W))
  59. {
  60. controls[(int)KeyInput.W] = false;
  61. }
  62. #endregion
  63.  
  64. #region S Input
  65. if (Input.GetKeyDown(KeyCode.S))
  66. {
  67. controls[(int)KeyInput.S] = true;
  68. }
  69. else if (Input.GetKeyUp(KeyCode.S))
  70. {
  71. controls[(int)KeyInput.S] = false;
  72. }
  73. #endregion
  74.  
  75. #region A Input
  76. if (Input.GetKeyDown(KeyCode.A))
  77. {
  78. controls[(int)KeyInput.A] = true;
  79. }
  80. else if (Input.GetKeyUp(KeyCode.A))
  81. {
  82. controls[(int)KeyInput.A] = false;
  83. }
  84. #endregion
  85.  
  86. #region D Input
  87. if (Input.GetKeyDown(KeyCode.D))
  88. {
  89. controls[(int)KeyInput.D] = true;
  90. }
  91. else if (Input.GetKeyUp(KeyCode.D))
  92. {
  93. controls[(int)KeyInput.D] = false;
  94. }
  95. #endregion
  96.  
  97.  
  98. foreach (var key in special_actions.Select((value, i) => new { i, value }))
  99. {
  100. if (key.value == true)
  101. {
  102. action_keyList.Add(key.i);
  103. }
  104. }
  105. if (action_keyList.Count > 0)
  106. {
  107. if (myIndex != null)
  108. {
  109. string camName = "Camera-Id: " + myIndex + "(Clone)";
  110. NetworkManager.instance.SendPacket(new SendActionKeys(action_keyList).CreteatePacket());
  111. special_actions[(int)lastAction] = false;
  112. }
  113. action_keyList.Clear();
  114. }
  115. foreach (var key in controls.Select((value, i) => new { i, value }))
  116. {
  117. if (key.value == true)
  118. {
  119. keyList.Add(key.i);
  120.  
  121. }
  122. }
  123. if (keyList.Count > 0)
  124. {
  125. if (myIndex != null) {
  126.  
  127. string camName = "Camera-Id: " + myIndex + "(Clone)";
  128. NetworkManager.instance.SendPacket(new SendMovementKeys(keyList, transform.position.y, UnWrapAngle(GameObject.Find(camName).transform.localEulerAngles.y), GameObject.Find(camName).transform.forward).CreteatePacket());
  129. }
  130. keyList.Clear();
  131. }
  132. if (AreAllFalse(controls))
  133. {
  134. //isLerpingPosition = false;
  135. //isLerpingRotating = false;
  136. NetworkManager.instance.SendPacket(new SendMovementIdle().CreteatePacket());
  137. }
  138.  
  139.  
  140. //myAnimState.PerofmAnimation();
  141.  
  142. }
  143. }
  144.  
  145. public void FixedUpdate()
  146. {
  147.  
  148. }
  149. public bool AreAllFalse(bool[] array)
  150. {
  151. foreach (var b in controls)
  152. {
  153. if (b)
  154. return false;
  155. }
  156. return true;
  157. }
  158. public float UnWrapAngle(float angle)
  159. {
  160. if (angle >= 0) return angle;
  161. angle -= angle % 360;
  162. return 360 - angle;
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement