public LiteNetLibIdentity NetworkSpawn(LiteNetLibIdentity identity, uint objectId = 0, long connectionId = -1) { if (identity == null) { if (Manager.LogWarn) { Logging.LogWarning(LogTag, "NetworkSpawn - identity is null."); } return(null); } identity.gameObject.SetActive(true); identity.Initial(Manager, false, objectId, connectionId); identity.InitTransform(identity.transform.position, identity.transform.rotation); identity.OnSetOwnerClient(connectionId >= 0 && connectionId == Manager.ClientConnectionId); if (Manager.IsServer) { identity.OnStartServer(); } if (Manager.IsClient) { identity.OnStartClient(); } if (connectionId >= 0 && connectionId == Manager.ClientConnectionId) { identity.OnStartOwnerClient(); } if (onObjectSpawn != null) { onObjectSpawn.Invoke(identity); } return(identity); }
public LiteNetLibIdentity NetworkSpawn(GameObject gameObject, uint objectId = 0, long connectionId = -1) { if (gameObject == null) { if (Manager.LogWarn) { Logging.LogWarning(LogTag, "NetworkSpawn - gameObject is null."); } return(null); } LiteNetLibIdentity identity = gameObject.GetComponent <LiteNetLibIdentity>(); if (identity == null) { if (Manager.LogWarn) { Logging.LogWarning(LogTag, "NetworkSpawn - identity is null."); } return(null); } identity.gameObject.SetActive(true); identity.Initial(Manager, false, objectId, connectionId); identity.InitTransform(gameObject.transform.position, gameObject.transform.rotation); identity.SetOwnerClient(connectionId >= 0 && connectionId == Manager.ClientConnectionId); if (onObjectSpawn != null) { onObjectSpawn.Invoke(identity); } if (Manager.IsServer) { identity.OnStartServer(); } if (Manager.IsClient) { identity.OnStartClient(); } if (connectionId >= 0 && connectionId == Manager.ClientConnectionId) { identity.OnStartOwnerClient(); } SpawnedObjects[identity.ObjectId] = identity; // Add to player spawned objects dictionary LiteNetLibPlayer player; if (Manager.TryGetPlayer(connectionId, out player)) { player.SpawnedObjects[identity.ObjectId] = identity; } return(identity); }