浏览代码

Merge pull request #17 from Unity-Technologies/eh_integratecharacterset

Support for animation and spawning player in DungeonTest scene
/main
GitHub 4 年前
当前提交
5458ac01
共有 12 个文件被更改,包括 601 次插入265 次删除
  1. 137
      Assets/BossRoom/Prefabs/Player.prefab
  2. 1
      Assets/BossRoom/Prefabs/State/BossRoomState.prefab
  3. 486
      Assets/BossRoom/Scenes/DungeonTest.unity
  4. 4
      Assets/BossRoom/Scenes/MainMenu.unity
  5. 3
      Assets/BossRoom/Scripts/Client/BossRoom.Client.asmdef
  6. 23
      Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs
  7. 52
      Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs
  8. 6
      Assets/BossRoom/Scripts/Server/Net/ServerGNHLogic.cs
  9. 2
      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

137
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:

- component: {fileID: 4600110157238723777}
- component: {fileID: 4600110157238723776}
- component: {fileID: 4600110157238723779}
- component: {fileID: 4093145920273822261}
- component: {fileID: 4093145920273822261}
m_Layer: 0
m_Name: Player
m_TagString: Untagged

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

m_Script: {fileID: 11500000, guid: fdad0914904cc1e47933ecd7a58514ac, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MovementSpeed: 3
--- !u!114 &4093145920273822261
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4600110157238723781}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9520a47fc61d5ab4ca99cdac2d574909, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ClientVisuals: {fileID: 1935255767028652502}
m_MovementSpeed: 4
--- !u!54 &4470766618279719912
Rigidbody:
m_ObjectHideFlags: 0

m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 1, z: 0}
--- !u!114 &4093145920273822261
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4600110157238723781}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9520a47fc61d5ab4ca99cdac2d574909, type: 3}
m_Name:
m_EditorClassIdentifier:
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}

486
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": [],

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


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

public class ClientCharacterVisualization : NetworkedBehaviour
{
private NetworkCharacterState m_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.

if (!IsClient)
{
enabled = false;
}
else if (IsLocalPlayer)
{
AttachCamera();
}
}

m_ClientVisualsAnimator = m_ClientVisuals.GetComponent<Animator>();
}
void Update()

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

52
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)
{
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.
NetworkingManager.Singleton.OnClientConnectedCallback += OnClientConnected;
// if any other players are already connected to us (i.e. they connected while we were
// in the login screen), give them player characters
foreach (var connection in NetworkingManager.Singleton.ConnectedClientsList)
{
SpawnPlayer(connection.ClientId);
}
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.)
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");

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


// Recalculate navigation path only on target change.
m_NavMeshAgent.CalculatePath(position, m_DesiredMovementPath);
}
private void Awake()

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

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


/// The networked rotation of this Character. This reflects the authorative rotation on the server.
/// </summary>
public NetworkedVarFloat NetworkRotationY { get; } = new NetworkedVarFloat();
public NetworkedVarFloat NetworkMovementSpeed { get; } = new NetworkedVarFloat();
/// <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:
正在加载...
取消
保存