Instantiating is working
This commit is contained in:
parent
c57476770c
commit
48f13ca4fa
@ -71,4 +71,4 @@ MonoBehaviour:
|
|||||||
_syncTracking: 0
|
_syncTracking: 0
|
||||||
_debug: 1
|
_debug: 1
|
||||||
_sendRate: 25
|
_sendRate: 25
|
||||||
_createLocalRemotes: 1
|
_createLocalRemotes: 0
|
||||||
|
@ -40,7 +40,11 @@ namespace Passer.Humanoid {
|
|||||||
// end temporary dummies
|
// end temporary dummies
|
||||||
|
|
||||||
public ulong nwId {
|
public ulong nwId {
|
||||||
get { return identity.NetworkObjectId; }
|
get {
|
||||||
|
if (identity == null)
|
||||||
|
identity = GetComponent<Unity.Netcode.NetworkObject>();
|
||||||
|
return identity.NetworkObjectId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -70,11 +74,11 @@ namespace Passer.Humanoid {
|
|||||||
Unity.Netcode.NetworkObject nwObject = GetNetworkObject(objIdentity);
|
Unity.Netcode.NetworkObject nwObject = GetNetworkObject(objIdentity);
|
||||||
if (nwObject == null) {
|
if (nwObject == null) {
|
||||||
// Player Objects
|
// Player Objects
|
||||||
nwObject = NetworkManager.Singleton.ConnectedClients[objIdentity].PlayerObject;
|
//nwObject = NetworkManager.Singleton.ConnectedClients[objIdentity].PlayerObject;
|
||||||
if (nwObject != null)
|
//if (nwObject != null)
|
||||||
return nwObject.gameObject;
|
// return nwObject.gameObject;
|
||||||
else
|
//else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
GameObject gameObject = nwObject.gameObject;
|
GameObject gameObject = nwObject.gameObject;
|
||||||
return gameObject;
|
return gameObject;
|
||||||
@ -89,26 +93,52 @@ namespace Passer.Humanoid {
|
|||||||
set { _createLocalRemotes = value; }
|
set { _createLocalRemotes = value; }
|
||||||
}
|
}
|
||||||
protected Vector3 _localRemotePosition = new(0, 0, -1);
|
protected Vector3 _localRemotePosition = new(0, 0, -1);
|
||||||
public Vector3 localRemotePosition { get { return _localRemotePosition; } }
|
public Vector3 localRemotePosition { get { return _localRemotePosition; } }
|
||||||
|
|
||||||
|
|
||||||
#region Init
|
#region Init
|
||||||
|
|
||||||
public void Start() {
|
public void Awake() {
|
||||||
if (identity == null)
|
if (identity == null)
|
||||||
identity = GetComponent<Unity.Netcode.NetworkObject>();
|
identity = GetComponent<Unity.Netcode.NetworkObject>();
|
||||||
|
|
||||||
humanoids = HumanoidNetworking.FindLocalHumanoids();
|
humanoids = HumanoidNetworking.FindLocalHumanoids();
|
||||||
|
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
DebugLog("Found " + humanoids.Count + " Humanoids");
|
DebugLog($"Found {humanoids.Count} Humanoids");
|
||||||
|
|
||||||
|
//if (identity.IsLocalPlayer) {
|
||||||
|
// isLocal = true;
|
||||||
|
// name = "HumanoidPlayer(Local)";
|
||||||
|
|
||||||
|
// humanoids = HumanoidNetworking.FindLocalHumanoids();
|
||||||
|
// if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
|
// DebugLog($"Found {humanoids.Count} Humanoids");
|
||||||
|
//}
|
||||||
|
//DebugLog($"awakened {this}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start() {
|
||||||
|
if (identity.IsLocalPlayer == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isLocal = true;
|
||||||
|
name = "HumanoidPlayer(Local)";
|
||||||
|
|
||||||
|
//humanoids = HumanoidNetworking.FindLocalHumanoids();
|
||||||
|
//if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
|
// DebugLog($"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 || createLocalRemotes == false)
|
if (humanoid.isRemote) // || createLocalRemotes == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
humanoid.nwId = identity.NetworkObjectId;
|
||||||
humanoid.humanoidNetworking = this;
|
humanoid.humanoidNetworking = this;
|
||||||
|
|
||||||
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
|
Debug.Log(humanoid.nwId + ": Send Start Humanoid " + humanoid.humanoidId);
|
||||||
|
|
||||||
((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
|
((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,39 +174,39 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Start
|
//#region Start
|
||||||
|
|
||||||
public virtual void OnStartLocalPlayer() {
|
//public virtual void OnStartLocalPlayer() {
|
||||||
isLocal = true;
|
// isLocal = true;
|
||||||
name = "HumanoidPlayer(Local)";
|
// name = "HumanoidPlayer(Local)";
|
||||||
|
|
||||||
humanoids = HumanoidNetworking.FindLocalHumanoids();
|
// humanoids = HumanoidNetworking.FindLocalHumanoids();
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
// if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
Debug.Log((int)identity.NetworkObjectId + ": 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.NetworkObjectId;
|
// humanoid.nwId = identity.NetworkObjectId;
|
||||||
humanoid.humanoidNetworking = this;
|
// humanoid.humanoidNetworking = this;
|
||||||
|
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
// if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
Debug.Log(humanoid.nwId + ": Send Start Humanoid " + humanoid.humanoidId);
|
// Debug.Log(humanoid.nwId + ": Send Start Humanoid " + humanoid.humanoidId);
|
||||||
|
|
||||||
((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
|
// ((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
|
||||||
}
|
// }
|
||||||
foreach (HumanoidControl humanoid in humanoids)
|
// //foreach (HumanoidControl humanoid in humanoids)
|
||||||
DetectNetworkObjects(humanoid);
|
// // DetectNetworkObjects(humanoid);
|
||||||
|
|
||||||
|
|
||||||
NetworkingSpawner spawner = FindObjectOfType<NetworkingSpawner>();
|
// //NetworkingSpawner spawner = FindObjectOfType<NetworkingSpawner>();
|
||||||
if (spawner != null)
|
// //if (spawner != null)
|
||||||
spawner.OnNetworkingStarted();
|
// // spawner.OnNetworkingStarted();
|
||||||
}
|
//}
|
||||||
|
|
||||||
#endregion
|
//#endregion
|
||||||
|
|
||||||
#region Update
|
#region Update
|
||||||
|
|
||||||
@ -298,7 +328,7 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Rpc(SendTo.NotServer)] // @ remote client
|
[Rpc(SendTo.NotOwner)] // @ remote client
|
||||||
protected virtual void ReceiveInitiateHumanoidRpc(byte[] data) {
|
protected virtual void ReceiveInitiateHumanoidRpc(byte[] data) {
|
||||||
HumanoidNetworking.InstantiateHumanoid instantiateHumanoid = new HumanoidNetworking.InstantiateHumanoid(data);
|
HumanoidNetworking.InstantiateHumanoid instantiateHumanoid = new HumanoidNetworking.InstantiateHumanoid(data);
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
if (debug <= HumanoidNetworking.DebugLevel.Info)
|
||||||
@ -595,9 +625,13 @@ namespace Passer.Humanoid {
|
|||||||
#region Debug
|
#region Debug
|
||||||
|
|
||||||
public void DebugLog(string message) {
|
public void DebugLog(string message) {
|
||||||
Debug.Log(identity.NetworkObjectId + ": " + message);
|
if (identity == null)
|
||||||
|
Debug.Log("??: " + message);
|
||||||
|
else
|
||||||
|
Debug.Log(identity.NetworkObjectId + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void DebugWarning(string message) {
|
public void DebugWarning(string message) {
|
||||||
Debug.LogWarning(identity.NetworkObjectId + ": " + message);
|
Debug.LogWarning(identity.NetworkObjectId + ": " + message);
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ namespace Passer {
|
|||||||
void INetworkingStarter.StartClient(NetworkingStarter nwStarter) {
|
void INetworkingStarter.StartClient(NetworkingStarter nwStarter) {
|
||||||
Debug.Log("start Netcode Client");
|
Debug.Log("start Netcode Client");
|
||||||
//NetworkManager networkManager = nwStarter.GetComponent<NetworkManager>();
|
//NetworkManager networkManager = nwStarter.GetComponent<NetworkManager>();
|
||||||
//NetworkClient nwClient =
|
|
||||||
NetworkManager.Singleton.StartClient();
|
|
||||||
NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
|
NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
|
||||||
nwStarter.serverIpAddress,
|
nwStarter.serverIpAddress,
|
||||||
nwStarter.serverPort
|
nwStarter.serverPort
|
||||||
);
|
);
|
||||||
|
//NetworkClient nwClient =
|
||||||
|
NetworkManager.Singleton.StartClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartClient(string serverIpAddress, ushort serverPort) {
|
public static void StartClient(string serverIpAddress, ushort serverPort) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user