您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
56 行
1.8 KiB
56 行
1.8 KiB
using MLAPI;
|
|
using UnityEngine;
|
|
|
|
namespace BossRoom.Client
|
|
{
|
|
/// <summary>
|
|
/// Captures inputs for a character on a client and sends them to the server.
|
|
/// </summary>
|
|
[RequireComponent(typeof(NetworkCharacterState))]
|
|
public class ClientInputSender : NetworkedBehaviour
|
|
{
|
|
private NetworkCharacterState networkCharacter;
|
|
|
|
public override void NetworkStart()
|
|
{
|
|
// TODO Don't use NetworkedBehaviour for just NetworkStart [GOMPS-81]
|
|
if (!IsClient || !IsOwner)
|
|
{
|
|
enabled = false;
|
|
}
|
|
}
|
|
|
|
|
|
void Awake()
|
|
{
|
|
networkCharacter = GetComponent<NetworkCharacterState>();
|
|
}
|
|
|
|
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.
|
|
networkCharacter.InvokeServerRpc(networkCharacter.SendCharacterInputServerRpc, hit.point, "MLAPI_INTERNAL");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
var data = new ActionRequestData();
|
|
data.ActionTypeEnum = Action.TANK_BASEATTACK;
|
|
networkCharacter.C2S_DoAction(ref data);
|
|
}
|
|
}
|
|
}
|
|
}
|