Luke Stampfli
4 年前
当前提交
e7d31100
共有 10 个文件被更改,包括 85 次插入 和 107 次删除
-
16Assets/BossRoom/Prefabs/Player.prefab
-
19Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs
-
17Assets/BossRoom/Scripts/Shared/NetworkCharacterState.cs
-
44Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs
-
11Assets/BossRoom/Scripts/Client/ClientInput.cs.meta
-
36Assets/BossRoom/Scripts/Client/ClientCharacter.cs
-
49Assets/BossRoom/Scripts/Client/ClientInput.cs
-
0/Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs.meta
-
0/Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs.meta
-
0/Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs
|
|||
using BossRoom.Shared; |
|||
using MLAPI; |
|||
using UnityEngine; |
|||
|
|||
namespace BossRoom.Client |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(NetworkCharacterState))] |
|||
public class ClientCharacterVisualization : NetworkedBehaviour |
|||
{ |
|||
private NetworkCharacterState networkCharacterState; |
|||
|
|||
/// <summary>
|
|||
/// The GameObject which visually represents the character is a child object of the character GameObject. This needs to be the case to support host mode.
|
|||
/// In host mode <see cref="MonoBehaviour.transform"/> is the transform which is relevant for gameplay.
|
|||
/// <see cref="m_ClientVisuals"/> is the visual representation on the client side which has interpolated position values.
|
|||
/// </summary>
|
|||
[SerializeField] private Transform m_ClientVisuals; |
|||
|
|||
/// <inheritdoc />
|
|||
public override void NetworkStart() |
|||
{ |
|||
if (!IsClient) |
|||
{ |
|||
enabled = false; |
|||
} |
|||
} |
|||
|
|||
void Awake() |
|||
{ |
|||
networkCharacterState = GetComponent<NetworkCharacterState>(); |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
// TODO Needs core sdk support. This and rotation should grab the interpolated value of network position based on the last received snapshots.
|
|||
m_ClientVisuals.position = networkCharacterState.NetworkPosition.Value; |
|||
|
|||
m_ClientVisuals.rotation = Quaternion.Euler(0, networkCharacterState.NetworkRotationY.Value, 0); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 331c67f15523ad7419792662b9768f44 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using BossRoom.Shared; |
|||
using MLAPI; |
|||
using UnityEngine; |
|||
|
|||
namespace BossRoom.Client |
|||
{ |
|||
[RequireComponent(typeof(NetworkCharacterState))] |
|||
public class ClientCharacter: NetworkedBehaviour |
|||
{ |
|||
private NetworkCharacterState networkCharacterState; |
|||
|
|||
[SerializeField] |
|||
private Transform clientInterpolatedObject; |
|||
|
|||
public override void NetworkStart() |
|||
{ |
|||
if (!IsClient) |
|||
{ |
|||
enabled = false; |
|||
} |
|||
} |
|||
|
|||
void Awake() |
|||
{ |
|||
networkCharacterState = GetComponent<NetworkCharacterState>(); |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
// TODO Needs core sdk support. This and rotation should grab the interpolated value of network position based on the last received snapshots.
|
|||
clientInterpolatedObject.position = networkCharacterState.NetworkPosition.Value; |
|||
|
|||
clientInterpolatedObject.rotation = Quaternion.Euler(0, networkCharacterState.NetworkRotationY.Value, 0); |
|||
} |
|||
} |
|||
} |
|
|||
using BossRoom.Shared; |
|||
using MLAPI; |
|||
using UnityEngine; |
|||
|
|||
namespace BossRoom.Client |
|||
{ |
|||
[RequireComponent(typeof(NetworkCharacterState))] |
|||
public class ClientInput : NetworkedBehaviour |
|||
{ |
|||
private NetworkCharacterState networkCharacter; |
|||
|
|||
public override void NetworkStart() |
|||
{ |
|||
// TODO The entire disabling/enabling is still sketchy and the reason why this has to be a NetworkedBehaviour
|
|||
if (!IsClient) |
|||
{ |
|||
enabled = false; |
|||
} |
|||
} |
|||
|
|||
|
|||
void Awake() |
|||
{ |
|||
networkCharacter = GetComponent<NetworkCharacterState>(); |
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void FixedUpdate() |
|||
{ |
|||
// EDU Multiplayer games poll update in fixed step because server processes game simulation in a fixed step as well
|
|||
|
|||
// TODO can we use new Unity input system which supports fixed update polling? Right now implementation is broken
|
|||
|
|||
// Is mouse button pressed (not checking for down for continuous input)
|
|||
if (Input.GetMouseButton(0)) |
|||
{ |
|||
RaycastHit hit; |
|||
|
|||
// TODO Camera.main is horrible in Unity < 2020.2
|
|||
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) |
|||
{ |
|||
// TODO Send reliable sequenced
|
|||
// TODO Call syntax is still ugly
|
|||
networkCharacter.InvokeServerRpc(networkCharacter.ServerRpcReceiveMovementInput, hit.point, "MLAPI_INTERNAL"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue