using MLAPI; using UnityEngine; namespace BossRoom.Client { /// /// Captures inputs for a character on a client and sends them to the server. /// [RequireComponent(typeof(NetworkCharacterState))] public class ClientInputSender : NetworkedBehaviour { private NetworkCharacterState m_NetworkCharacter; public override void NetworkStart() { // TODO Don't use NetworkedBehaviour for just NetworkStart [GOMPS-81] if (!IsClient || !IsOwner) { enabled = false; } } void Awake() { m_NetworkCharacter = GetComponent(); } void FixedUpdate() { // TODO replace with new Unity Input System [GOMPS-81] // Is mouse button pressed (not just checking for down to allow continuous movement inputs by holding the mouse button down) if (Input.GetMouseButton(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { // The MLAPI_INTERNAL channel is a reliable sequenced channel. Inputs should always arrive and be in order that's why this channel is used. m_NetworkCharacter.InvokeServerRpc(m_NetworkCharacter.SendCharacterInputServerRpc, hit.point, "MLAPI_INTERNAL"); } } } private void Update() { if (Input.GetMouseButtonDown(1)) { var data = new ActionRequestData(); data.ActionTypeEnum = Action.TANK_BASEATTACK; m_NetworkCharacter.C2S_DoAction(ref data); } } } }