The networkstarter starts in host mode
This commit is contained in:
parent
fcffefc794
commit
8cf6002858
@ -1,9 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
#if !UNITY_2019_1_OR_NEWER
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
@ -28,6 +25,9 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateHumanoidPrefab(GameObject prefab, string prefabPath) {
|
public static void UpdateHumanoidPrefab(GameObject prefab, string prefabPath) {
|
||||||
|
if (prefab == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!Application.isPlaying) {
|
if (!Application.isPlaying) {
|
||||||
Debug.Log("UpdateHumanoidPrefab " + Application.isFocused + " " + Application.isBatchMode + " " + Application.isEditor);
|
Debug.Log("UpdateHumanoidPrefab " + Application.isFocused + " " + Application.isBatchMode + " " + Application.isEditor);
|
||||||
if (Application.isFocused && !Application.isBatchMode && Application.isEditor) {
|
if (Application.isFocused && !Application.isBatchMode && Application.isEditor) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 2d90d19d1758e7640a802a318b83849a
|
guid: 1e00cb872f4ac3e4086b96d4e9ccdc7a
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
@ -1,33 +1,34 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
#if !UNITY_2019_1_OR_NEWER
|
using UnityEditor;
|
||||||
using UnityEngine.Networking;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
|
|
||||||
public class OnLoadHumanoidPlayerNetcode {
|
public class OnLoadHumanoidPlayerNetcode {
|
||||||
|
|
||||||
public static void CheckHumanoidPlayer() {
|
public static void CheckHumanoidPlayer() {
|
||||||
#if !UNITY_2019_1_OR_NEWER
|
|
||||||
string prefabPath = OnLoadHumanoidPlayer.GetHumanoidPlayerPrefabPath();
|
string prefabPath = OnLoadHumanoidPlayer.GetHumanoidPlayerPrefabPath();
|
||||||
GameObject playerPrefab = OnLoadHumanoidPlayer.GetHumanoidPlayerPrefab(prefabPath);
|
GameObject playerPrefab = OnLoadHumanoidPlayer.GetHumanoidPlayerPrefab(prefabPath);
|
||||||
|
|
||||||
#pragma warning disable 0618
|
#if hNETCODE
|
||||||
NetworkManager nwManager = Object.FindObjectOfType<NetworkManager>();
|
Unity.Netcode.NetworkManager nwManager = Object.FindObjectOfType<Unity.Netcode.NetworkManager>();
|
||||||
#if hNW_UNET
|
|
||||||
if (nwManager == null) {
|
if (nwManager == null) {
|
||||||
NetworkingStarter nwStarter = Object.FindObjectOfType<NetworkingStarter>();
|
NetworkingStarter nwStarter = Object.FindObjectOfType<NetworkingStarter>();
|
||||||
if (nwStarter != null)
|
if (nwStarter != null)
|
||||||
nwManager = nwStarter.gameObject.AddComponent<NetworkManager>();
|
nwManager = nwStarter.gameObject.AddComponent<Unity.Netcode.NetworkManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nwManager != null && nwManager.playerPrefab == null)
|
Unity.Netcode.NetworkConfig nwConfig = nwManager.NetworkConfig;
|
||||||
nwManager.playerPrefab = (GameObject)Resources.Load("HumanoidPlayer");
|
if (nwConfig.NetworkTransport == null) {
|
||||||
|
Unity.Netcode.Transports.UTP.UnityTransport unityTransport = new();
|
||||||
|
nwConfig.NetworkTransport = unityTransport;
|
||||||
|
}
|
||||||
|
if (nwConfig.PlayerPrefab == null)
|
||||||
|
nwConfig.PlayerPrefab = (GameObject)Resources.Load("HumanoidPlayer");
|
||||||
|
|
||||||
if (playerPrefab != null) {
|
if (playerPrefab != null) {
|
||||||
NetworkIdentity nwId = playerPrefab.GetComponent<NetworkIdentity>();
|
Unity.Netcode.NetworkObject nwId = playerPrefab.GetComponent<Unity.Netcode.NetworkObject>();
|
||||||
if (nwId == null)
|
if (nwId == null)
|
||||||
nwId = playerPrefab.AddComponent<NetworkIdentity>();
|
nwId = playerPrefab.AddComponent<Unity.Netcode.NetworkObject>();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (nwManager != null)
|
if (nwManager != null)
|
||||||
@ -39,9 +40,7 @@ namespace Passer.Humanoid {
|
|||||||
Object.DestroyImmediate(nwId, true);
|
Object.DestroyImmediate(nwId, true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#pragma warning restore 0618
|
|
||||||
OnLoadHumanoidPlayer.UpdateHumanoidPrefab(playerPrefab, prefabPath);
|
OnLoadHumanoidPlayer.UpdateHumanoidPrefab(playerPrefab, prefabPath);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "PasserVR.HumanoidControl.Editor",
|
"name": "PasserVR.HumanoidControl.Editor",
|
||||||
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"PasserVR.HumanoidControl",
|
"PasserVR.HumanoidControl",
|
||||||
"Passer.Visitors.Editor",
|
"Passer.Visitors.Editor",
|
||||||
@ -8,7 +9,8 @@
|
|||||||
"PhotonVoice.PUN",
|
"PhotonVoice.PUN",
|
||||||
"PhotonRealtime",
|
"PhotonRealtime",
|
||||||
"PhotonVoice.API",
|
"PhotonVoice.API",
|
||||||
"SteamVR"
|
"SteamVR",
|
||||||
|
"Unity.Netcode.Runtime"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
|
@ -17,7 +17,9 @@ namespace Passer.Humanoid {
|
|||||||
public virtual void OnEnable() {
|
public virtual void OnEnable() {
|
||||||
nwStarter = (NetworkingStarter)target;
|
nwStarter = (NetworkingStarter)target;
|
||||||
|
|
||||||
#if hUNET
|
#if hNETCODE
|
||||||
|
OnLoadHumanoidPlayerNetcode.CheckHumanoidPlayer();
|
||||||
|
#elif hUNET
|
||||||
OnLoadHumanoidPlayerUnet.CheckHumanoidPlayer();
|
OnLoadHumanoidPlayerUnet.CheckHumanoidPlayer();
|
||||||
#endif
|
#endif
|
||||||
#if hPHOTON1 || hPHOTON2
|
#if hPHOTON1 || hPHOTON2
|
||||||
@ -34,7 +36,7 @@ namespace Passer.Humanoid {
|
|||||||
public override void OnInspectorGUI() {
|
public override void OnInspectorGUI() {
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
#if !hNW_UNET && !hNW_PHOTON && !hNW_MIRROR && !hNW_BOLT
|
#if !hNW_PHOTON && !hNETCODE
|
||||||
EditorGUILayout.HelpBox("Networking Support is disabled. Check Preferences to enable it.", MessageType.Warning);
|
EditorGUILayout.HelpBox("Networking Support is disabled. Check Preferences to enable it.", MessageType.Warning);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -57,7 +59,10 @@ namespace Passer.Humanoid {
|
|||||||
private void Inspector() {
|
private void Inspector() {
|
||||||
autoStartProp = serializedObject.FindProperty("autoStart");
|
autoStartProp = serializedObject.FindProperty("autoStart");
|
||||||
autoStartProp.boolValue = EditorGUILayout.Toggle("Auto Start", autoStartProp.boolValue);
|
autoStartProp.boolValue = EditorGUILayout.Toggle("Auto Start", autoStartProp.boolValue);
|
||||||
#if hNW_UNET
|
#if hNETCODE
|
||||||
|
NetworkingPrefabInspector();
|
||||||
|
ServerTypeInspector();
|
||||||
|
#elif hNW_UNET
|
||||||
NetworkingPrefabInspector();
|
NetworkingPrefabInspector();
|
||||||
ServerTypeInspector();
|
ServerTypeInspector();
|
||||||
#elif hNW_PHOTON
|
#elif hNW_PHOTON
|
||||||
@ -82,11 +87,13 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ServerTypeInspector() {
|
private void ServerTypeInspector() {
|
||||||
|
#if !hNETCODE
|
||||||
SerializedProperty serverTypeProp = serializedObject.FindProperty("serverType");
|
SerializedProperty serverTypeProp = serializedObject.FindProperty("serverType");
|
||||||
serverTypeProp.intValue = (int)(NetworkingStarter.ServerType)EditorGUILayout.EnumPopup("Server Type", (NetworkingStarter.ServerType)serverTypeProp.intValue);
|
serverTypeProp.intValue = (int)(NetworkingStarter.ServerType)EditorGUILayout.EnumPopup("Server Type", (NetworkingStarter.ServerType)serverTypeProp.intValue);
|
||||||
if ((NetworkingStarter.ServerType)serverTypeProp.intValue == NetworkingStarter.ServerType.CloudServer)
|
if ((NetworkingStarter.ServerType)serverTypeProp.intValue == NetworkingStarter.ServerType.CloudServer)
|
||||||
CloudServerInspector();
|
CloudServerInspector();
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
OwnServerInspector();
|
OwnServerInspector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +107,7 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
private void OwnServerInspector() {
|
private void OwnServerInspector() {
|
||||||
SerializedProperty serverIpAddressProp = serializedObject.FindProperty("serverIpAddress");
|
SerializedProperty serverIpAddressProp = serializedObject.FindProperty("serverIpAddress");
|
||||||
|
SerializedProperty serverPortProp = serializedObject.FindProperty("serverPort");
|
||||||
SerializedProperty useRoleFileProp = serializedObject.FindProperty("useRoleFile");
|
SerializedProperty useRoleFileProp = serializedObject.FindProperty("useRoleFile");
|
||||||
SerializedProperty roleFileName = serializedObject.FindProperty("roleFileName");
|
SerializedProperty roleFileName = serializedObject.FindProperty("roleFileName");
|
||||||
SerializedProperty roleProp = serializedObject.FindProperty("role");
|
SerializedProperty roleProp = serializedObject.FindProperty("role");
|
||||||
@ -109,7 +117,7 @@ namespace Passer.Humanoid {
|
|||||||
if (useRoleFileProp.boolValue) {
|
if (useRoleFileProp.boolValue) {
|
||||||
roleFileName.stringValue = EditorGUILayout.TextField("Role File Name", roleFileName.stringValue);
|
roleFileName.stringValue = EditorGUILayout.TextField("Role File Name", roleFileName.stringValue);
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
#if hNW_UNET || hMIRROR
|
#if hNETCODE || hMIRROR
|
||||||
serverIpAddressProp.stringValue = EditorGUILayout.TextField("Server IP Address", serverIpAddressProp.stringValue);
|
serverIpAddressProp.stringValue = EditorGUILayout.TextField("Server IP Address", serverIpAddressProp.stringValue);
|
||||||
#endif
|
#endif
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
@ -124,19 +132,22 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
roleProp.intValue = (int)(NetworkingStarter.Role)EditorGUILayout.EnumPopup("Role", (NetworkingStarter.Role)roleProp.intValue);
|
roleProp.intValue = (int)(NetworkingStarter.Role)EditorGUILayout.EnumPopup("Role", (NetworkingStarter.Role)roleProp.intValue);
|
||||||
#if hNW_UNET || hMIRROR
|
#if hNETCODE || hMIRROR
|
||||||
serverIpAddressProp.stringValue = EditorGUILayout.TextField("Server IP Address", serverIpAddressProp.stringValue);
|
serverIpAddressProp.stringValue = EditorGUILayout.TextField("Server IP Address", serverIpAddressProp.stringValue);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if hNW_UNET || hMIRROR
|
#if hNETCODE || hMIRROR
|
||||||
else
|
else
|
||||||
serverIpAddressProp.stringValue = EditorGUILayout.TextField("Server IP Address", serverIpAddressProp.stringValue);
|
serverIpAddressProp.stringValue = EditorGUILayout.TextField("Server IP Address", serverIpAddressProp.stringValue);
|
||||||
#endif
|
#endif
|
||||||
#if hMIRROR
|
#if hMIRROR
|
||||||
Mirror.NetworkManager nwManager = nwStarter.GetComponent<Mirror.NetworkManager>();
|
NetworkManager nwManager = nwStarter.GetComponent<Mirror.NetworkManager>();
|
||||||
nwManager.networkAddress = serverIpAddressProp.stringValue;
|
nwManager.networkAddress = serverIpAddressProp.stringValue;
|
||||||
|
#elif hNETCODE
|
||||||
|
serverPortProp.intValue = EditorGUILayout.IntField("Server Port", serverPortProp.intValue);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteToRoleFile(string roleFileName, string roleText, string ipAddress) {
|
private void WriteToRoleFile(string roleFileName, string roleText, string ipAddress) {
|
||||||
|
@ -10,6 +10,7 @@ GameObject:
|
|||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 4191195719973714}
|
- component: {fileID: 4191195719973714}
|
||||||
- component: {fileID: 114636771493283014}
|
- component: {fileID: 114636771493283014}
|
||||||
|
- component: {fileID: 1251152422678924623}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: HumanoidPlayer
|
m_Name: HumanoidPlayer
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -27,6 +28,7 @@ Transform:
|
|||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
@ -43,4 +45,30 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: eb69cd2012a95b549a6c414c3619432c, type: 3}
|
m_Script: {fileID: 11500000, guid: eb69cd2012a95b549a6c414c3619432c, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
_syncFingerSwing: 0
|
||||||
|
_syncFace: 0
|
||||||
|
_syncTracking: 0
|
||||||
_debug: 3
|
_debug: 3
|
||||||
|
_sendRate: 25
|
||||||
|
_createLocalRemotes: 0
|
||||||
|
--- !u!114 &1251152422678924623
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1810220956971058}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
GlobalObjectIdHash: 2555736071
|
||||||
|
InScenePlacedSourceGlobalObjectIdHash: 0
|
||||||
|
AlwaysReplicateAsRoot: 0
|
||||||
|
SynchronizeTransform: 1
|
||||||
|
ActiveSceneSynchronization: 0
|
||||||
|
SceneMigrationSynchronization: 1
|
||||||
|
SpawnWithObservers: 1
|
||||||
|
DontDestroyWithOwner: 0
|
||||||
|
AutoObjectParentSync: 1
|
||||||
|
@ -7,7 +7,7 @@ using Unity.Netcode.Components;
|
|||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
|
|
||||||
#pragma warning disable 0618
|
#pragma warning disable 0618
|
||||||
[RequireComponent(typeof(NetworkObject))]
|
[RequireComponent(typeof(Unity.Netcode.NetworkObject))]
|
||||||
public partial class HumanoidPlayer : NetworkBehaviour, IHumanoidNetworking {
|
public partial class HumanoidPlayer : NetworkBehaviour, IHumanoidNetworking {
|
||||||
|
|
||||||
// temporary (?) dummies
|
// temporary (?) dummies
|
||||||
@ -40,7 +40,7 @@ namespace Passer.Humanoid {
|
|||||||
// end temporary dummies
|
// end temporary dummies
|
||||||
|
|
||||||
public ulong nwId {
|
public ulong nwId {
|
||||||
get { return identity.objectIdentity; }
|
get { return identity.NetworkObjectId; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -55,14 +55,14 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
public List<HumanoidControl> humanoids { get; set; }
|
public List<HumanoidControl> humanoids { get; set; }
|
||||||
|
|
||||||
protected NetworkObject identity;
|
protected Unity.Netcode.NetworkObject identity;
|
||||||
|
|
||||||
public ulong GetObjectIdentity(GameObject obj) {
|
public ulong GetObjectIdentity(GameObject obj) {
|
||||||
NetworkObject identity = obj.GetComponent<NetworkObject>();
|
Unity.Netcode.NetworkObject identity = obj.GetComponent<Unity.Netcode.NetworkObject>();
|
||||||
if (identity == null)
|
if (identity == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return identity.objectIdentity;
|
return identity.NetworkObjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameObject GetGameObject(ulong objIdentity) {
|
public GameObject GetGameObject(ulong objIdentity) {
|
||||||
@ -88,23 +88,23 @@ namespace Passer.Humanoid {
|
|||||||
public virtual void OnStartClient() {
|
public virtual void OnStartClient() {
|
||||||
//name = name + " " + netId;
|
//name = name + " " + netId;
|
||||||
|
|
||||||
//NetworkManager nwManager = FindObjectOfType<NetworkManager>();
|
NetworkManager nwManager = FindObjectOfType<NetworkManager>();
|
||||||
//short msgType = MsgType.Highest + 2;
|
//short msgType = MsgType.Highest + 2;
|
||||||
//nwManager.client.RegisterHandler(msgType, ClientProcessAvatarPose);
|
//nwManager.client.RegisterHandler(msgType, ClientProcessAvatarPose);
|
||||||
|
|
||||||
// No idea how this works with Netcode
|
//No idea how this works with Netcode
|
||||||
//if (identity.isServer) {
|
if (IsServer) {
|
||||||
// IHumanoidNetworking[] nwHumanoids = FindObjectsOfType<HumanoidPlayer>();
|
IHumanoidNetworking[] nwHumanoids = FindObjectsOfType<HumanoidPlayer>();
|
||||||
// foreach (IHumanoidNetworking nwHumanoid in nwHumanoids) {
|
foreach (IHumanoidNetworking nwHumanoid in nwHumanoids) {
|
||||||
// foreach (HumanoidControl humanoid in nwHumanoid.humanoids) {
|
foreach (HumanoidControl humanoid in nwHumanoid.humanoids) {
|
||||||
// if (humanoid.isRemote)
|
if (humanoid.isRemote)
|
||||||
// continue;
|
continue;
|
||||||
|
|
||||||
// DebugLog("Server Instantiate " + humanoid.nwId + " " + humanoid.humanoidId);
|
DebugLog("Server Instantiate " + humanoid.nwId + " " + humanoid.humanoidId);
|
||||||
// ((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
|
((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnStartServer() {
|
public virtual void OnStartServer() {
|
||||||
@ -122,14 +122,14 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
humanoids = HumanoidNetworking.FindLocalHumanoids();
|
humanoids = HumanoidNetworking.FindLocalHumanoids();
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
Debug.Log((int)identity.objectIdentity + ": Found " + humanoids.Count + " Humanoids");
|
Debug.Log((int)identity.NetworkObjectId + ": Found " + humanoids.Count + " Humanoids");
|
||||||
|
|
||||||
for (int i = 0; i < humanoids.Count; i++) {
|
for (int i = 0; i < humanoids.Count; i++) {
|
||||||
HumanoidControl humanoid = humanoids[i];
|
HumanoidControl humanoid = humanoids[i];
|
||||||
if (humanoid.isRemote)
|
if (humanoid.isRemote)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
humanoid.nwId = identity.objectIdentity;
|
humanoid.nwId = identity.NetworkObjectId;
|
||||||
humanoid.humanoidNetworking = this;
|
humanoid.humanoidNetworking = this;
|
||||||
|
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
@ -173,6 +173,9 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
public virtual void LateUpdate() {
|
public virtual void LateUpdate() {
|
||||||
if (Time.time > lastSend + 1 / sendRate) {
|
if (Time.time > lastSend + 1 / sendRate) {
|
||||||
|
if (humanoids == null)
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (HumanoidControl humanoid in humanoids) {
|
foreach (HumanoidControl humanoid in humanoids) {
|
||||||
if (!humanoid.isRemote) {
|
if (!humanoid.isRemote) {
|
||||||
UpdateHumanoidPose(humanoid);
|
UpdateHumanoidPose(humanoid);
|
||||||
@ -190,7 +193,7 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
override public void OnDestroy() {
|
override public void OnDestroy() {
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
Debug.Log((int)identity.objectIdentity + ": Destroy Remote Humanoid");
|
Debug.Log((int)identity.NetworkObjectId + ": Destroy Remote Humanoid");
|
||||||
|
|
||||||
foreach (HumanoidControl humanoid in humanoids) {
|
foreach (HumanoidControl humanoid in humanoids) {
|
||||||
if (humanoid == null)
|
if (humanoid == null)
|
||||||
@ -269,7 +272,7 @@ namespace Passer.Humanoid {
|
|||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
DebugLog("Received Instantiate Humanoid " + instantiateHumanoid.nwId + "/" + instantiateHumanoid.humanoidId);
|
DebugLog("Received Instantiate Humanoid " + instantiateHumanoid.nwId + "/" + instantiateHumanoid.humanoidId);
|
||||||
|
|
||||||
if (instantiateHumanoid.nwId != identity.objectIdentity) {
|
if (instantiateHumanoid.nwId != identity.NetworkObjectId) {
|
||||||
// Get the right HumanoidPlayer for this humanoid
|
// Get the right HumanoidPlayer for this humanoid
|
||||||
//NetworkInstanceId netId = new NetworkInstanceId((uint)instantiateHumanoid.nwId);
|
//NetworkInstanceId netId = new NetworkInstanceId((uint)instantiateHumanoid.nwId);
|
||||||
//GameObject gameObject = ClientScene.FindLocalObject(netId);
|
//GameObject gameObject = ClientScene.FindLocalObject(netId);
|
||||||
@ -560,15 +563,15 @@ namespace Passer.Humanoid {
|
|||||||
#region Debug
|
#region Debug
|
||||||
|
|
||||||
public void DebugLog(string message) {
|
public void DebugLog(string message) {
|
||||||
Debug.Log(identity.objectIdentity + ": " + message);
|
Debug.Log(identity.NetworkObjectId + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DebugWarning(string message) {
|
public void DebugWarning(string message) {
|
||||||
Debug.LogWarning(identity.objectIdentity + ": " + message);
|
Debug.LogWarning(identity.NetworkObjectId + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DebugError(string message) {
|
public void DebugError(string message) {
|
||||||
Debug.LogError(identity.objectIdentity + ": " + message);
|
Debug.LogError(identity.NetworkObjectId + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
#if hNW_UNET && !UNITY_2019_1_OR_NEWER
|
#if hNETCODE
|
||||||
#pragma warning disable 0618
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using Unity.Netcode;
|
||||||
using UnityEngine.Networking.Match;
|
using Unity.Netcode.Transports.UTP;
|
||||||
|
|
||||||
namespace Passer {
|
namespace Passer {
|
||||||
|
|
||||||
public class UnetStarter : INetworkingStarter {
|
public class NetcodeStarter : INetworkingStarter {
|
||||||
private string roomName;
|
private string roomName;
|
||||||
private int gameVersion;
|
private int gameVersion;
|
||||||
|
|
||||||
|
public ushort serverPort;
|
||||||
|
|
||||||
bool matchCreated;
|
bool matchCreated;
|
||||||
private NetworkManager networkManager;
|
private NetworkManager networkManager;
|
||||||
private NetworkMatch networkMatch;
|
//private NetworkMatch networkMatch;
|
||||||
|
|
||||||
GameObject INetworkingStarter.GetHumanoidPrefab() {
|
GameObject INetworkingStarter.GetHumanoidPrefab() {
|
||||||
GameObject humanoidPrefab = Resources.Load<GameObject>("HumanoidPlayer");
|
GameObject humanoidPrefab = Resources.Load<GameObject>("HumanoidPlayer");
|
||||||
@ -22,42 +21,54 @@ namespace Passer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void INetworkingStarter.StartHost(NetworkingStarter nwStarter) {
|
void INetworkingStarter.StartHost(NetworkingStarter nwStarter) {
|
||||||
Debug.Log("start Unet Host");
|
Debug.Log("start Netcode Host");
|
||||||
NetworkManager networkManager = nwStarter.GetComponent<NetworkManager>();
|
NetworkManager networkManager = nwStarter.GetComponent<NetworkManager>();
|
||||||
if (networkManager == null) {
|
if (networkManager == null) {
|
||||||
Debug.LogError("Could not start host: NetworkManager is missing");
|
Debug.LogError("Could not start host: NetworkManager is missing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
networkManager.StartHost();
|
//networkManager.StartHost();
|
||||||
|
NetworkManager.Singleton.StartHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INetworkingStarter.StartClient(NetworkingStarter nwStarter) {
|
void INetworkingStarter.StartClient(NetworkingStarter nwStarter) {
|
||||||
Debug.Log("start Unet Client");
|
Debug.Log("start Netcode Client");
|
||||||
NetworkManager networkManager = nwStarter.GetComponent<NetworkManager>();
|
//NetworkManager networkManager = nwStarter.GetComponent<NetworkManager>();
|
||||||
NetworkClient nwClient = networkManager.StartClient();
|
//NetworkClient nwClient =
|
||||||
nwClient.Connect(nwStarter.serverIpAddress, networkManager.networkPort);
|
NetworkManager.Singleton.StartClient();
|
||||||
|
NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
|
||||||
|
nwStarter.serverIpAddress,
|
||||||
|
nwStarter.serverPort
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartClient(string serverIpAddress) {
|
public static void StartClient(string serverIpAddress, ushort serverPort) {
|
||||||
Debug.Log("start Unet Client");
|
Debug.Log("start Netcode Client");
|
||||||
NetworkManager networkManager = Object.FindObjectOfType<NetworkManager>();
|
//NetworkManager networkManager = Object.FindObjectOfType<NetworkManager>();
|
||||||
NetworkClient nwClient = networkManager.StartClient();
|
//NetworkClient nwClient =
|
||||||
nwClient.Connect(serverIpAddress, networkManager.networkPort);
|
NetworkManager.Singleton.StartClient();
|
||||||
|
NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
|
||||||
|
serverIpAddress,
|
||||||
|
serverPort
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void INetworkingStarter.StartClient(NetworkingStarter networking, string _roomName, int _gameVersion) {
|
void INetworkingStarter.StartClient(NetworkingStarter networking, string _roomName, int _gameVersion) {
|
||||||
roomName = _roomName;
|
roomName = _roomName;
|
||||||
gameVersion = _gameVersion;
|
gameVersion = _gameVersion;
|
||||||
|
|
||||||
networkMatch = networking.gameObject.AddComponent<NetworkMatch>();
|
//networkMatch = networking.gameObject.AddComponent<NetworkMatch>();
|
||||||
networkManager = networking.GetComponent<NetworkManager>();
|
//networkManager = networking.GetComponent<NetworkManager>();
|
||||||
|
|
||||||
networkMatch.ListMatches(0, 10, "", true, 0, gameVersion, OnMatchList);
|
//networkMatch.ListMatches(0, 10, "", true, 0, gameVersion, OnMatchList);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Events
|
public void StopClient() {; }
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
/*
|
||||||
public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches) {
|
public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches) {
|
||||||
if (success && matches != null) {
|
if (success && matches != null) {
|
||||||
int foundRoom = -1;
|
int foundRoom = -1;
|
||||||
@ -108,7 +119,7 @@ namespace Passer {
|
|||||||
Debug.LogError("Join match failed " + extendedInfo);
|
Debug.LogError("Join match failed " + extendedInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"SteamVR",
|
"SteamVR",
|
||||||
"Unity.XR.OpenVR",
|
"Unity.XR.OpenVR",
|
||||||
"Unity.Netcode.Runtime",
|
"Unity.Netcode.Runtime",
|
||||||
"Unity.Netcode.Components"
|
"Unity.Netcode.Components",
|
||||||
|
"Unity.Networking.Transport"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Unity.Netcode;
|
||||||
|
|
||||||
#if hNW_BOLT
|
#if hNW_BOLT
|
||||||
using UdpKit;
|
using UdpKit;
|
||||||
#endif
|
#endif
|
||||||
@ -26,6 +28,8 @@ namespace Passer {
|
|||||||
#endif
|
#endif
|
||||||
#elif hNW_BOLT
|
#elif hNW_BOLT
|
||||||
public class NetworkingStarter : Bolt.GlobalEventListener
|
public class NetworkingStarter : Bolt.GlobalEventListener
|
||||||
|
#elif hNETCODE
|
||||||
|
public class NetworkingStarter : NetworkBehaviour
|
||||||
#else
|
#else
|
||||||
public class NetworkingStarter : MonoBehaviour
|
public class NetworkingStarter : MonoBehaviour
|
||||||
#endif
|
#endif
|
||||||
@ -33,6 +37,8 @@ namespace Passer {
|
|||||||
public bool autoStart = true;
|
public bool autoStart = true;
|
||||||
#if hNW_UNET
|
#if hNW_UNET
|
||||||
protected INetworkingStarter starter = new UnetStarter();
|
protected INetworkingStarter starter = new UnetStarter();
|
||||||
|
#elif hNETCODE
|
||||||
|
protected INetworkingStarter starter = new NetcodeStarter();
|
||||||
#elif hNW_PHOTON
|
#elif hNW_PHOTON
|
||||||
protected INetworkingStarter starter = new PunStarter();
|
protected INetworkingStarter starter = new PunStarter();
|
||||||
#elif hNW_BOLT
|
#elif hNW_BOLT
|
||||||
@ -47,6 +53,7 @@ namespace Passer {
|
|||||||
/// The IP address of the host
|
/// The IP address of the host
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string serverIpAddress = "127.0.0.1";
|
public string serverIpAddress = "127.0.0.1";
|
||||||
|
public ushort serverPort = 1234;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the environment shared by all the users
|
/// The name of the environment shared by all the users
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 86153051f48cf8c488177d8f1b7aedaa
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
x
Reference in New Issue
Block a user