public override void OnStopClient() { base.OnStopClient(); Assets.ClearSpawnedObjects(); LiteNetLibIdentity.ResetObjectId(); LiteNetLibAssets.ResetSpawnPositionCounter(); }
public LiteNetLibIdentity NetworkSpawn(string assetId, Vector3 position, uint objectId = 0, long connectId = 0) { if (!Manager.IsNetworkActive) { Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawn - Network is not active cannot spawn"); return(null); } // Scene objects cannot be spawned if (SceneObjects.ContainsKey(objectId)) { return(null); } LiteNetLibIdentity spawningObject = null; if (GuidToPrefabs.TryGetValue(assetId, out spawningObject)) { var spawnedObject = Instantiate(spawningObject); spawnedObject.gameObject.SetActive(true); spawnedObject.transform.position = position; spawnedObject.Initial(Manager, objectId, connectId); SpawnedObjects[spawnedObject.ObjectId] = spawnedObject; if (Manager.IsServer) { Manager.SendServerSpawnObject(spawnedObject); } return(spawnedObject); } else if (Manager.LogWarn) { Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawn - Asset Id: " + assetId + " is not registered."); } return(null); }
public void SendServerSpawnObject(LiteNetLibIdentity identity) { if (!IsServer) { return; } foreach (var peer in Peers.Values) { SendServerSpawnObject(peer, identity); } }
public void SendServerSpawnSceneObject(NetPeer peer, LiteNetLibIdentity identity) { if (!IsServer) { return; } var message = new ServerSpawnSceneObjectMessage(); message.objectId = identity.ObjectId; message.position = identity.transform.position; SendPacket(SendOptions.ReliableOrdered, peer, GameMsgTypes.ServerSpawnSceneObject, message); }
public bool UnregisterPrefab(LiteNetLibIdentity prefab) { if (prefab == null) { if (Manager.LogWarn) { Debug.LogWarning("[" + name + "] LiteNetLibAssets::UnregisterPrefab - prefab is null."); } return(false); } return(GuidToPrefabs.Remove(prefab.AssetId)); }
public void RegisterPrefab(LiteNetLibIdentity prefab) { if (prefab == null) { if (Manager.LogWarn) { Debug.LogWarning("[" + name + "] LiteNetLibAssets::RegisterPrefab - prefab is null."); } return; } GuidToPrefabs[prefab.AssetId] = prefab; }
public LiteNetLibIdentity NetworkSpawnScene(uint objectId, Vector3 position) { if (!Manager.IsNetworkActive) { Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawnScene - Network is not active cannot spawn"); return(null); } LiteNetLibIdentity sceneObject = null; if (SceneObjects.TryGetValue(objectId, out sceneObject)) { sceneObject.gameObject.SetActive(true); sceneObject.transform.position = position; sceneObject.Initial(Manager); SpawnedObjects[sceneObject.ObjectId] = sceneObject; return(sceneObject); } else if (Manager.LogWarn) { Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawnScene - Object Id: " + objectId + " is not registered."); } return(null); }