浏览代码

Add movement replication

/main
Luke Stampfli 4 年前
当前提交
77d8f673
共有 4 个文件被更改,包括 38 次插入7 次删除
  1. 19
      Assets/Scenes/SampleScene.unity
  2. 15
      Assets/Scripts/Character.cs
  3. 7
      Assets/Scripts/PositionInterpolation.cs
  4. 4
      ProjectSettings/ProjectSettings.asset

19
Assets/Scenes/SampleScene.unity


- component: {fileID: 1069853760}
- component: {fileID: 1069853759}
- component: {fileID: 1069853758}
- component: {fileID: 1069853761}
m_Layer: 0
m_Name: NetworkingManager
m_TagString: Untagged

LogLevel: 1
NetworkConfig:
ProtocolVersion: 0
NetworkTransport: {fileID: 1069853758}
NetworkTransport: {fileID: 1069853760}
RegisteredScenes:
- SampleScene
AllowRuntimeSceneChanges: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1069853755}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 52c005b32a68a254cbe502a4e5cb8eb6, type: 3}
m_Name:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1069853755}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b84c2d8dfe509a34fb59e2b81f8e1319, type: 3}
m_Name:

MLAPIRelayAddress: 184.72.104.138
MLAPIRelayPort: 8888
MessageSendMode: 0
--- !u!114 &1069853761
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1069853755}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e26f82009f8f36d45a99adae79eab7b9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1233618360
GameObject:
m_ObjectHideFlags: 0

15
Assets/Scripts/Character.cs


using MLAPI;
using MLAPI.Messaging;
using System;
using System.IO;
using System.Linq;

private void SyncNetworkEvents(float time, float deltaTime)
{
_interpolation.AddValue(time, transform.position);
if (IsServer)
{
_interpolation.AddValue(time, transform.position);
InvokeClientRpcOnEveryoneExcept<float, Vector3>(ReplicatePosition, NetworkingManager.Singleton.ServerClientId, time, transform.position);
}
}
public void SetMovementTarget(Vector3 position)

var movement = direction * movementSpeed * deltaTime;
_navMeshAgent.Move(movement);
}
[ClientRPC]
private void ReplicatePosition(float time, Vector3 value)
{
// The time which we receive here is server time. TODO We need to match it with our client time.
_interpolation.AddValue(time, value);
}
}

7
Assets/Scripts/PositionInterpolation.cs


private void Update()
{
transform.position = GetValueForTime(NetworkingManager.Singleton.NetworkTime);
var value = GetValueForTime(NetworkingManager.Singleton.NetworkTime);
if (!float.IsNaN(value.x))
{
transform.position = value;
}
}
}

4
ProjectSettings/ProjectSettings.asset


bakeCollisionMeshes: 0
forceSingleInstance: 0
useFlipModelSwapchain: 1
resizableWindow: 0
resizableWindow: 1
useMacAppStoreValidation: 0
macAppStoreCategory: public.app-category.games
gpuSkinning: 1

xboxEnableFitness: 0
visibleInBackground: 1
allowFullscreenSwitch: 1
fullscreenMode: 1
fullscreenMode: 3
xboxSpeechDB: 0
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0

正在加载...
取消
保存