Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System;
- using Assets.ClientScripts.net.packets.outgoing;
- public class KeyboardInput : MonoBehaviour
- {
- private List<int> keyList = new List<int>();
- private List<int> action_keyList = new List<int>();
- public bool[] controls = new bool[(int)KeyInput.Count];
- public bool[] special_actions = new bool[(int)KeyInput.Count];
- public float RotationSpeed = 100.0f;
- public bool isLerpingPosition;
- public bool isLerpingRotating;
- public float timeStartedLerping;
- public float timeToLerp;
- public CharacterController _characterController;
- public Guid myIndex;
- public Animator animator;
- private void Awake()
- {
- animator = GetComponent<Animator>();
- _characterController = GetComponent<CharacterController>();
- }
- public float Gravity = 14.5f;
- public KeyInput lastAction;
- private void Update()
- {
- if (animator == null)
- {
- animator = GetComponent<Animator>();
- }
- if (myIndex == NetworkManager.instance.myIndex)
- {
- #region W Input
- if (Input.GetKeyDown(KeyCode.Tab))
- {
- special_actions[(int)KeyInput.TAB] = true;
- lastAction = KeyInput.TAB;
- }
- if (Input.GetKeyDown(KeyCode.W))
- {
- controls[(int)KeyInput.W] = true;
- }
- else if (Input.GetKeyUp(KeyCode.W))
- {
- controls[(int)KeyInput.W] = false;
- }
- #endregion
- #region S Input
- if (Input.GetKeyDown(KeyCode.S))
- {
- controls[(int)KeyInput.S] = true;
- }
- else if (Input.GetKeyUp(KeyCode.S))
- {
- controls[(int)KeyInput.S] = false;
- }
- #endregion
- #region A Input
- if (Input.GetKeyDown(KeyCode.A))
- {
- controls[(int)KeyInput.A] = true;
- }
- else if (Input.GetKeyUp(KeyCode.A))
- {
- controls[(int)KeyInput.A] = false;
- }
- #endregion
- #region D Input
- if (Input.GetKeyDown(KeyCode.D))
- {
- controls[(int)KeyInput.D] = true;
- }
- else if (Input.GetKeyUp(KeyCode.D))
- {
- controls[(int)KeyInput.D] = false;
- }
- #endregion
- foreach (var key in special_actions.Select((value, i) => new { i, value }))
- {
- if (key.value == true)
- {
- action_keyList.Add(key.i);
- }
- }
- if (action_keyList.Count > 0)
- {
- if (myIndex != null)
- {
- string camName = "Camera-Id: " + myIndex + "(Clone)";
- NetworkManager.instance.SendPacket(new SendActionKeys(action_keyList).CreteatePacket());
- special_actions[(int)lastAction] = false;
- }
- action_keyList.Clear();
- }
- foreach (var key in controls.Select((value, i) => new { i, value }))
- {
- if (key.value == true)
- {
- keyList.Add(key.i);
- }
- }
- if (keyList.Count > 0)
- {
- if (myIndex != null) {
- string camName = "Camera-Id: " + myIndex + "(Clone)";
- NetworkManager.instance.SendPacket(new SendMovementKeys(keyList, transform.position.y, UnWrapAngle(GameObject.Find(camName).transform.localEulerAngles.y), GameObject.Find(camName).transform.forward).CreteatePacket());
- }
- keyList.Clear();
- }
- if (AreAllFalse(controls))
- {
- //isLerpingPosition = false;
- //isLerpingRotating = false;
- NetworkManager.instance.SendPacket(new SendMovementIdle().CreteatePacket());
- }
- //myAnimState.PerofmAnimation();
- }
- }
- public void FixedUpdate()
- {
- }
- public bool AreAllFalse(bool[] array)
- {
- foreach (var b in controls)
- {
- if (b)
- return false;
- }
- return true;
- }
- public float UnWrapAngle(float angle)
- {
- if (angle >= 0) return angle;
- angle -= angle % 360;
- return 360 - angle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement