예제 #1
0
 public override void OnStopClient()
 {
     base.OnStopClient();
     Assets.ClearSpawnedObjects();
     LiteNetLibIdentity.ResetObjectId();
     LiteNetLibAssets.ResetSpawnPositionCounter();
 }
예제 #2
0
        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);
        }
예제 #3
0
 public void SendServerSpawnObject(LiteNetLibIdentity identity)
 {
     if (!IsServer)
     {
         return;
     }
     foreach (var peer in Peers.Values)
     {
         SendServerSpawnObject(peer, identity);
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
 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));
 }
예제 #6
0
 public void RegisterPrefab(LiteNetLibIdentity prefab)
 {
     if (prefab == null)
     {
         if (Manager.LogWarn)
         {
             Debug.LogWarning("[" + name + "] LiteNetLibAssets::RegisterPrefab - prefab is null.");
         }
         return;
     }
     GuidToPrefabs[prefab.AssetId] = prefab;
 }
예제 #7
0
        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);
        }