示例#1
0
        public bool NetworkDestroy(uint objectId, DestroyObjectReasons reasons)
        {
            if (!Manager.IsNetworkActive)
            {
                Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkDestroy - Network is not active cannot destroy");
                return(false);
            }

            LiteNetLibIdentity spawnedObject;

            if (SpawnedObjects.TryGetValue(objectId, out spawnedObject))
            {
                // Remove from player spawned objects dictionary
                LiteNetLibPlayer player;
                if (Manager.Players.TryGetValue(spawnedObject.ConnectId, out player))
                {
                    player.SpawnedObjects.Remove(objectId);
                }
                // Remove from asset spawned objects dictionary
                SpawnedObjects.Remove(objectId);
                spawnedObject.OnNetworkDestroy(reasons);
                // If the object is scene object, don't destroy just hide it, else destroy
                if (SceneObjects.ContainsKey(objectId))
                {
                    spawnedObject.gameObject.SetActive(false);
                }
                else
                {
                    Destroy(spawnedObject.gameObject);
                }
                // If this is server, send message to clients to destroy object
                if (Manager.IsServer)
                {
                    Manager.SendServerDestroyObject(objectId, reasons);
                }
                return(true);
            }
            else if (Manager.LogWarn)
            {
                Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkDestroy - Object Id: " + objectId + " is not spawned.");
            }
            return(false);
        }
示例#2
0
        public bool NetworkDestroy(GameObject gameObject, DestroyObjectReasons reasons)
        {
            if (gameObject == null)
            {
                if (Manager.LogWarn)
                {
                    Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkDestroy - gameObject is null.");
                }
                return(false);
            }
            var identity = gameObject.GetComponent <LiteNetLibIdentity>();

            if (identity == null)
            {
                if (Manager.LogWarn)
                {
                    Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawn - identity is null.");
                }
                return(false);
            }
            return(NetworkDestroy(identity.ObjectId, reasons));
        }
示例#3
0
 /// <summary>
 /// This function will be called when object destroy from server
 /// </summary>
 /// <param name="reasons"></param>
 public virtual void OnNetworkDestroy(DestroyObjectReasons reasons)
 {
 }