private void OnNetworkDestroy(NetworkWriter writer)
        {
            if (IsServer)
            {
                return;
            }

            int instanceID = writer.ReadInt16();

            NetworkIdentity identity = NetworkIdentityManager.Instance.Get(instanceID);

            SpawnedObjects?.Remove(identity.gameObject);

            DestroyedGameObject?.Invoke(identity);

            Object.Destroy(identity.gameObject);
        }
        private void OnDestroyPlayer(NetworkConnection conn)
        {
            NetworkPlayerObject playerObject = PlayerObjects?.Find(x => x.ConnectionID == conn.ConnectionID);

            if (playerObject != null)
            {
                if (SpawnedObjects?.Contains(playerObject.GameObject) ?? false)
                {
                    SpawnedObjects.Remove(playerObject.GameObject);
                }

                DestroyedGameObject?.Invoke(playerObject.NetworkIdentity);
                Object.Destroy(playerObject.GameObject);

                PlayerObjects.Remove(playerObject);
                m_PlayerObjectCache?.Remove(conn.ConnectionID);
            }

            if (m_BufferedPlayersCreations?.ContainsKey(conn.ConnectionID) ?? false)
            {
                m_BufferedPlayersCreations.Remove(conn.ConnectionID);
            }

            if (m_BufferedOwnerCreations?.ContainsKey(conn.ConnectionID) ?? false)
            {
                m_BufferedOwnerCreations.Remove(conn.ConnectionID);
            }

            if (m_AuthroityObjects?.ContainsKey(conn) ?? false)
            {
                foreach (NetworkIdentity identity in m_AuthroityObjects[conn])
                {
                    if (identity != null)
                    {
                        Destroy(identity.gameObject);
                    }
                }
                m_AuthroityObjects.Remove(conn);
            }

            m_BufferedPlayerConnections?.Remove(conn);
        }
        /// <summary>
        /// Destroy a networked object.
        /// </summary>
        /// <param name="gameObject"></param>
        public void Destroy(GameObject gameObject)
        {
            if (!IsServer)
            {
                return;
            }

            if (!ServerValidateDestroy(gameObject, out NetworkIdentity identity))
            {
                return;
            }

            byte[] data = BitConverter.GetBytes((short)identity.InstanceID);

            NetworkController.Instance.SendToAll(NetworkController.ReliableSequencedChannel, DestroyMsg, data);

            DestroyedGameObject?.Invoke(identity);

            SpawnedObjects.Remove(identity.gameObject);

            Object.Destroy(gameObject);
        }