Exemple #1
0
        static void DestroyObject(NetworkIdentity identity, bool destroyServerObject)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("DestroyObject instance:" + identity.netId);
            }
            NetworkIdentity.spawned.Remove(identity.netId);

            identity.clientAuthorityOwner?.RemoveOwnedObject(identity);

            ObjectDestroyMessage msg = new ObjectDestroyMessage
            {
                netId = identity.netId
            };

            SendToObservers(identity, msg);

            identity.ClearObservers();
            if (NetworkClient.active && localClientActive)
            {
                identity.OnNetworkDestroy();
            }

            // when unspawning, dont destroy the server's object
            if (destroyServerObject)
            {
                UnityEngine.Object.Destroy(identity.gameObject);
            }
            identity.MarkForReset();
        }
        void DestroyObject(NetworkIdentity identity, bool destroyServerObject)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("DestroyObject instance:" + identity.NetId);
            }
            spawned.Remove(identity.NetId);

            identity.ConnectionToClient?.RemoveOwnedObject(identity);

            var msg = new ObjectDestroyMessage
            {
                netId = identity.NetId
            };

            SendToObservers(identity, msg);

            identity.ClearObservers();
            if (LocalClientActive)
            {
                identity.OnNetworkDestroy.Invoke();
            }

            // when unspawning, dont destroy the server's object
            if (destroyServerObject)
            {
                UnityEngine.Object.Destroy(identity.gameObject);
            }
            identity.MarkForReset();
        }
Exemple #3
0
        static void DestroyObject(NetworkIdentity uv, bool destroyServerObject)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("DestroyObject instance:" + uv.netId);
            }
            if (objects.ContainsKey(uv.netId))
            {
                objects.Remove(uv.netId);
            }

            if (uv.clientAuthorityOwner != null)
            {
                uv.clientAuthorityOwner.RemoveOwnedObject(uv);
            }

            ObjectDestroyMessage msg = new ObjectDestroyMessage();

            msg.netId = uv.netId;
            SendToObservers(uv.gameObject, (short)MsgType.ObjectDestroy, msg);

            uv.ClearObservers();
            if (NetworkClient.active && s_LocalClientActive)
            {
                uv.OnNetworkDestroy();
                ClientScene.SetLocalObject(msg.netId, null);
            }

            // when unspawning, dont destroy the server's object
            if (destroyServerObject)
            {
                UnityEngine.Object.Destroy(uv.gameObject);
            }
            uv.MarkForReset();
        }
Exemple #4
0
        public void ClearObservers()
        {
            // call OnStartServer so that observers dict is created
            identity.StartServer();

            // add some observers
            identity.observers.Add(new NetworkConnection(tconn42));
            identity.observers.Add(new NetworkConnection(tconn43));

            // call ClearObservers
            identity.ClearObservers();
            Assert.That(identity.observers.Count, Is.EqualTo(0));
        }