Beispiel #1
0
 public override void Deserialize(NetworkReader reader)
 {
     netId    = reader.ReadNetworkId();
     assetId  = reader.ReadNetworkHash128();
     position = reader.ReadVector3();
     rotation = reader.ReadQuaternion();
     payload  = reader.ReadBytesAndSize();
 }
Beispiel #2
0
 internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
 {
     if (s_UnspawnHandlers.ContainsKey(assetId) && s_UnspawnHandlers[assetId] != null)
     {
         UnSpawnDelegate handler = s_UnspawnHandlers[assetId];
         handler(obj);
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 internal static bool GetSpawnHandler(NetworkHash128 assetId, out SpawnDelegate handler)
 {
     if (s_SpawnHandlers.ContainsKey(assetId))
     {
         handler = s_SpawnHandlers[assetId];
         return(true);
     }
     handler = null;
     return(false);
 }
Beispiel #4
0
 internal static bool GetPrefab(NetworkHash128 assetId, out GameObject prefab)
 {
     prefab = null;
     if (assetId.IsValid() && guidToPrefab.ContainsKey(assetId) && guidToPrefab[assetId] != null)
     {
         prefab = guidToPrefab[assetId];
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 public static void Spawn(GameObject obj, NetworkHash128 assetId)
 {
     if (VerifyCanSpawn(obj))
     {
         NetworkIdentity id;
         if (GetNetworkIdentity(obj, out id))
         {
             id.SetDynamicAssetId(assetId);
         }
         SpawnObject(obj);
     }
 }
Beispiel #6
0
 internal void SetDynamicAssetId(NetworkHash128 newAssetId)
 {
     if (!m_AssetId.IsValid() || m_AssetId.Equals(newAssetId))
     {
         m_AssetId = newAssetId;
     }
     else
     {
         if (LogFilter.logWarn)
         {
             Debug.LogWarning("SetDynamicAssetId object already has an assetId <" + m_AssetId + ">");
         }
     }
 }
Beispiel #7
0
        public static bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, NetworkConnection conn)
        {
            Spawn(obj, assetId);

            var uv = obj.GetComponent <NetworkIdentity>();

            if (uv == null || !uv.isServer)
            {
                // spawning the object failed.
                return(false);
            }

            return(uv.AssignClientAuthority(conn));
        }
Beispiel #8
0
        // ------------------------ NetworkScene pass-throughs ---------------------

        internal static string GetStringForAssetId(NetworkHash128 assetId)
        {
            GameObject prefab;

            if (NetworkScene.GetPrefab(assetId, out prefab))
            {
                return(prefab.name);
            }

            SpawnDelegate handler;

            if (NetworkScene.GetSpawnHandler(assetId, out handler))
            {
                return(handler.GetMethodName());
            }

            return("unknown");
        }
Beispiel #9
0
        void SetupIDs()
        {
            GameObject prefab;

            if (ThisIsAPrefab())
            {
                ForceSceneId(0);
                AssignAssetID(gameObject);
            }
            else if (ThisIsASceneObjectWithPrefabParent(out prefab))
            {
                AssignAssetID(prefab);
            }
            else
            {
                m_AssetId = new NetworkHash128();
            }
        }
Beispiel #10
0
        internal static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            if (spawnHandler == null || unspawnHandler == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId);
                }
                return;
            }

            if (LogFilter.logDebug)
            {
                Debug.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
            }

            s_SpawnHandlers[assetId]   = spawnHandler;
            s_UnspawnHandlers[assetId] = unspawnHandler;
        }
Beispiel #11
0
 public void Write(NetworkHash128 value)
 {
     Write(value.i0);
     Write(value.i1);
     Write(value.i2);
     Write(value.i3);
     Write(value.i4);
     Write(value.i5);
     Write(value.i6);
     Write(value.i7);
     Write(value.i8);
     Write(value.i9);
     Write(value.i10);
     Write(value.i11);
     Write(value.i12);
     Write(value.i13);
     Write(value.i14);
     Write(value.i15);
 }
Beispiel #12
0
        internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
        {
            NetworkIdentity view = prefab.GetComponent <NetworkIdentity>();

            if (view)
            {
                view.SetDynamicAssetId(newAssetId);

                if (LogFilter.logDebug)
                {
                    Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId);
                }
                s_GuidToPrefab[view.assetId] = prefab;
            }
            else
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
                }
            }
        }
Beispiel #13
0
 public static void UnregisterSpawnHandler(NetworkHash128 assetId)
 {
     NetworkScene.UnregisterSpawnHandler(assetId);
 }
Beispiel #14
0
 public static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
 }
Beispiel #15
0
 // this assigns the newAssetId to the prefab. This is for registering dynamically created game objects for already know assetIds.
 public static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
 {
     NetworkScene.RegisterPrefab(prefab, newAssetId);
 }
Beispiel #16
0
        public static bool AddPlayerForConnection(NetworkConnection conn, GameObject player, NetworkHash128 assetId)
        {
            NetworkIdentity id;

            if (GetNetworkIdentity(player, out id))
            {
                id.SetDynamicAssetId(assetId);
            }
            return(InternalAddPlayerForConnection(conn, player));
        }
Beispiel #17
0
 public static void UnregisterSpawnHandler(NetworkHash128 assetId)
 {
     s_SpawnHandlers.Remove(assetId);
     s_UnspawnHandlers.Remove(assetId);
 }
Beispiel #18
0
        void AssignAssetID(GameObject prefab)
        {
            string path = AssetDatabase.GetAssetPath(prefab);

            m_AssetId = NetworkHash128.Parse(AssetDatabase.AssetPathToGUID(path));
        }