浏览代码

Support for animation and spawning player in DungeonTest scene

/main
eheimburg 3 年前
当前提交
9b0e2a81
共有 12 个文件被更改,包括 679 次插入586 次删除
  1. 111
      Assets/BossRoom/Prefabs/Player.prefab
  2. 1
      Assets/BossRoom/Prefabs/State/BossRoomState.prefab
  3. 912
      Assets/BossRoom/Scenes/DungeonTest.unity
  4. 4
      Assets/BossRoom/Scenes/MainMenu.unity
  5. 3
      Assets/BossRoom/Scripts/Client/BossRoom.Client.asmdef
  6. 25
      Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs
  7. 50
      Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs
  8. 6
      Assets/BossRoom/Scripts/Server/Net/ServerGNHLogic.cs
  9. 1
      Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs
  10. 1
      Assets/BossRoom/Scripts/Shared/NetworkCharacterState.cs
  11. 143
      Assets/BossRoom/Scenes/DungeonTest/NavMesh.asset
  12. 8
      Assets/BossRoom/Scenes/DungeonTest/NavMesh.asset.meta

111
Assets/BossRoom/Prefabs/Player.prefab


m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1935255767028652502
Transform:
m_ObjectHideFlags: 0

m_Children:
- {fileID: 80535263913599867}
m_Father: {fileID: 4600110157238723791}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4600110157238723781
GameObject:

m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 6174365277840941608}
- {fileID: 1935255767028652502}
m_Father: {fileID: 0}
m_RootOrder: 0

NetworkPosition:
InternalValue: {x: 0, y: 0, z: 0}
NetworkRotationY:
InternalValue: 0
NetworkMovementSpeed:
InternalValue: 0
--- !u!114 &4600110157238723776
MonoBehaviour:

m_Script: {fileID: 11500000, guid: 9520a47fc61d5ab4ca99cdac2d574909, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ClientVisuals: {fileID: 1935255767028652502}
m_ClientVisuals: {fileID: 6174365277840941608}
--- !u!1001 &7872000410579295758
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 4600110157238723791}
m_Modifications:
- target: {fileID: 451019077418353113, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 1275426192112755703, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 1983451975515712793, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 3269992512903255054, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 3736552308919084700, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Name
value: CharacterSet
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4916965965019151265, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 5404400264780765344, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 7415691260465069799, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 7688214084643546559, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 7859571076522411967, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
- target: {fileID: 8474587904930755041, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
--- !u!4 &6174365277840941608 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4076098699203836966, guid: d396ab139e993ee43b2eb29978bba8ff, type: 3}
m_PrefabInstance: {fileID: 7872000410579295758}
m_PrefabAsset: {fileID: 0}

1
Assets/BossRoom/Prefabs/State/BossRoomState.prefab


m_Script: {fileID: 11500000, guid: 927521835ae055247b17e4abe805b4ab, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayerPrefab: {fileID: 4600110157238723790, guid: bb87f9bac2595f8499c048016c4b2e1d, type: 3}

912
Assets/BossRoom/Scenes/DungeonTest.unity
文件差异内容过多而无法显示
查看文件

4
Assets/BossRoom/Scenes/MainMenu.unity


CreatePlayerPrefab: 0
ReceiveTickrate: 0
MaxReceiveEventsPerTickRate: 1000
EventTickrate: 0
EventTickrate: 100
ClientConnectionBufferTimeout: 10
ConnectionApproval: 1
ConnectionData:

EnableNetworkedVar: 0
EnableNetworkedVar: 1
EnsureNetworkedVarLengthSafety: 0
EnableSceneManagement: 1
ForceSamePrefabs: 0

3
Assets/BossRoom/Scripts/Client/BossRoom.Client.asmdef


"rootNamespace": "",
"references": [
"GUID:1491147abca9d7d4bb7105af628b223e",
"GUID:16d7768bae8d50d44b658fc9bb9d4a7d"
"GUID:16d7768bae8d50d44b658fc9bb9d4a7d",
"GUID:4307f53044263cf4b835bd812fc161a4"
],
"includePlatforms": [],
"excludePlatforms": [],

25
Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs


using BossRoom.Shared;
using MLAPI;
using UnityEngine;
using Cinemachine;
namespace BossRoom.Client
{

public class ClientCharacterVisualization : NetworkedBehaviour
{
private NetworkCharacterState networkCharacterState;
private Animator m_ClientVisualsAnimator;
/// <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.

/// <inheritdoc />
public override void NetworkStart()
{
if (!IsClient)
if (!IsClient && !IsHost)
else if (IsLocalPlayer)
{
AttachCamera();
}
m_ClientVisualsAnimator = m_ClientVisuals.GetComponent<Animator>();
}
void Update()

m_ClientVisuals.rotation = Quaternion.Euler(0, networkCharacterState.NetworkRotationY.Value, 0);
if (m_ClientVisualsAnimator)
{
// set Animator variables here
m_ClientVisualsAnimator.SetFloat("Speed", networkCharacterState.NetworkMovementSpeed.Value);
}
}
private void AttachCamera()
{
CinemachineVirtualCamera cam = (CinemachineVirtualCamera)FindObjectOfType(typeof(CinemachineVirtualCamera));
if (cam)
{
cam.Follow = m_ClientVisuals.transform;
cam.LookAt = m_ClientVisuals.transform;
}
}
}
}

50
Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs


using System.Collections.Generic;
using UnityEngine;
using BossRoom;
using System;
using MLAPI;
namespace BossRoom.Server
{

public class ServerBossRoomState : GameStateBehaviour
{
[SerializeField] private NetworkedObject PlayerPrefab;
public override GameState ActiveState { get { return GameState.BOSSROOM; } }

if (!IsServer) { this.enabled = false; }
if (!IsServer && !IsHost)
{
this.enabled = false;
}
else
{
// listen for the client-connect event. This will only happen after
// the ServerGNHLogic's approval-callback is done, meaning that if we get this event,
// the client is officially allowed to be here.
MLAPI.NetworkingManager.Singleton.OnClientConnectedCallback += OnClientConnected;
if (IsHost)
{
// start local "host" character too!
SpawnPlayer(MLAPI.NetworkingManager.Singleton.LocalClientId);
}
}
}
private void OnClientConnected(ulong clientId)
{
// FIXME: this is a work-around for an MLAPI timing problem which happens semi-reliably;
// when it happens, it generates the same errors and has the same behavior as this:
// https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/issues/328
// We can't use the workaround suggested there, which is to avoid using MLAPI's scene manager.
// Instead, we wait a bit for MLAPI to get its state organized, because we can't safely create entities in OnClientConnected().
// (Note: on further explortation, I think this is due to some sort of scene-loading synchronization: the new client is briefly
// "in" the lobby screen, but has already told the server it's in the game scene. Or something similar.)
//
// Note: this workaround doesn't help us when the client connects during the host's scene-load (i.e. when the Host is in char-gen
// screen and gets a new connection) and the ServerBossRoomState doesn't exist yet. That's an unrelated problem, and not an
// MLAPI issue! ... But it generates the same error message ("Cannot find pending soft sync object. Is the projects the same?")
// so wanted to mention it.
StartCoroutine(CoroSpawnPlayer(clientId));
}
private IEnumerator CoroSpawnPlayer(ulong clientId)
{
yield return new WaitForSeconds(1);
SpawnPlayer(clientId);
}
private void SpawnPlayer(ulong clientId)
{
var NewPlayer = Instantiate(PlayerPrefab);
NewPlayer.SpawnAsPlayerObject(clientId);
}
}
}

6
Assets/BossRoom/Scripts/Server/Net/ServerGNHLogic.cs


// used in ApprovalCheck. This is intended as a bit of light protection against DOS attacks that rely on sending silly big buffers of garbage.
private const int k_MaxConnectPayload = 1024;
// note: MonoBehaviours' constructors are *never* called and this should be removed for clarity
public ServerGNHLogic(GameNetHub hub)
{
m_Hub = hub;

{
m_Hub = GetComponent<GameNetHub>();
m_Hub.NetworkStartEvent += this.NetworkStart;
// we add ApprovalCheck callback BEFORE NetworkStart to avoid spurious MLAPI warning:
// "No ConnectionApproval callback defined. Connection approval will timeout"
m_Hub.NetManager.ConnectionApprovalCallback += this.ApprovalCheck;
}
public void NetworkStart()

}
else
{
m_Hub.NetManager.ConnectionApprovalCallback += this.ApprovalCheck;
//The "BossRoom" server always advances to CharSelect immediately on start. Different games
//may do this differently.
MLAPI.SceneManagement.NetworkSceneManager.SwitchScene("CharSelect");

1
Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs


// Send new position values to the client
networkCharacterState.NetworkPosition.Value = transform.position;
networkCharacterState.NetworkRotationY.Value = transform.rotation.eulerAngles.y;
networkCharacterState.NetworkMovementSpeed.Value = movementState == MovementState.Idle ? 0 : movementSpeed;
}
private void Movement()

1
Assets/BossRoom/Scripts/Shared/NetworkCharacterState.cs


{
public NetworkedVarVector3 NetworkPosition;
public NetworkedVarFloat NetworkRotationY;
public NetworkedVarFloat NetworkMovementSpeed;
/// <summary>
/// Gets invoked when inputs are received from the client which own this networked character.

143
Assets/BossRoom/Scenes/DungeonTest/NavMesh.asset
文件差异内容过多而无法显示
查看文件

8
Assets/BossRoom/Scenes/DungeonTest/NavMesh.asset.meta


fileFormatVersion: 2
guid: 91afa6ed596fadc4287b57b410e7abe7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 23800000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存