Exemplo n.º 1
0
        private void UnSpawn(NetworkIdentity identity)
        {
            logger.Assert(!Client.IsLocalClient, "UnSpawn should not be called in host mode");
            // it is useful to remove authority when destroying the object
            // this can be useful to clean up stuff after a local player is destroyed
            // call before StopClient, but dont reset the HasAuthority bool, people might want to use HasAuthority from stopclient or destroy
            if (identity.HasAuthority)
            {
                identity.CallStopAuthority();
            }

            identity.StopClient();

            if (_unspawnHandlers.TryGetValue(identity.PrefabHash, out var handler) && handler != null)
            {
                handler(identity);
            }
            else if (!identity.IsSceneObject)
            {
                Destroy(identity.gameObject);
            }
            else
            {
                identity.NetworkReset();
                identity.gameObject.SetActive(false);
                spawnableObjects[identity.SceneId] = identity;
            }

            Client.World.RemoveIdentity(identity);
        }
Exemplo n.º 2
0
        void UnSpawn(NetworkIdentity identity)
        {
            identity.StopClient();
            if (unspawnHandlers.TryGetValue(identity.PrefabHash, out UnSpawnDelegate handler) && handler != null)
            {
                handler(identity);
            }
            else if (!identity.IsSceneObject)
            {
                Destroy(identity.gameObject);
            }
            else
            {
                identity.NetworkReset();
                identity.gameObject.SetActive(false);
                spawnableObjects[identity.SceneId] = identity;
            }

            Client.World.RemoveIdentity(identity);
        }