// ------------------------ NetworkScene pass-throughs ---------------------

        static internal 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());
            }

            SpawnExDelegate exHandler;

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

            return("unknown");
        }
Exemple #2
0
        /// <summary>
        ///   <para>This parses the string representation of a NetworkHash into a binary object.</para>
        /// </summary>
        /// <param name="text">A hex string to parse.</param>
        /// <returns>
        ///   <para>A 128 bit network hash object.</para>
        /// </returns>
        public static NetworkHash128 Parse(string text)
        {
            int length = text.Length;

            if (length < 32)
            {
                string empty = string.Empty;
                for (int index = 0; index < 32 - length; ++index)
                {
                    empty += "0";
                }
                text = empty + text;
            }
            NetworkHash128 networkHash128;

            networkHash128.i0  = (byte)(NetworkHash128.HexToNumber(text[0]) * 16 + NetworkHash128.HexToNumber(text[1]));
            networkHash128.i1  = (byte)(NetworkHash128.HexToNumber(text[2]) * 16 + NetworkHash128.HexToNumber(text[3]));
            networkHash128.i2  = (byte)(NetworkHash128.HexToNumber(text[4]) * 16 + NetworkHash128.HexToNumber(text[5]));
            networkHash128.i3  = (byte)(NetworkHash128.HexToNumber(text[6]) * 16 + NetworkHash128.HexToNumber(text[7]));
            networkHash128.i4  = (byte)(NetworkHash128.HexToNumber(text[8]) * 16 + NetworkHash128.HexToNumber(text[9]));
            networkHash128.i5  = (byte)(NetworkHash128.HexToNumber(text[10]) * 16 + NetworkHash128.HexToNumber(text[11]));
            networkHash128.i6  = (byte)(NetworkHash128.HexToNumber(text[12]) * 16 + NetworkHash128.HexToNumber(text[13]));
            networkHash128.i7  = (byte)(NetworkHash128.HexToNumber(text[14]) * 16 + NetworkHash128.HexToNumber(text[15]));
            networkHash128.i8  = (byte)(NetworkHash128.HexToNumber(text[16]) * 16 + NetworkHash128.HexToNumber(text[17]));
            networkHash128.i9  = (byte)(NetworkHash128.HexToNumber(text[18]) * 16 + NetworkHash128.HexToNumber(text[19]));
            networkHash128.i10 = (byte)(NetworkHash128.HexToNumber(text[20]) * 16 + NetworkHash128.HexToNumber(text[21]));
            networkHash128.i11 = (byte)(NetworkHash128.HexToNumber(text[22]) * 16 + NetworkHash128.HexToNumber(text[23]));
            networkHash128.i12 = (byte)(NetworkHash128.HexToNumber(text[24]) * 16 + NetworkHash128.HexToNumber(text[25]));
            networkHash128.i13 = (byte)(NetworkHash128.HexToNumber(text[26]) * 16 + NetworkHash128.HexToNumber(text[27]));
            networkHash128.i14 = (byte)(NetworkHash128.HexToNumber(text[28]) * 16 + NetworkHash128.HexToNumber(text[29]));
            networkHash128.i15 = (byte)(NetworkHash128.HexToNumber(text[30]) * 16 + NetworkHash128.HexToNumber(text[31]));
            return(networkHash128);
        }
    private GameObject OnSpawnEntity(Vector3 position, NetworkHash128 assetId)
    {
        var networkEntity = Instantiate<NetworkIdentity>(_networkStateEntityProtoType);

        networkEntity.transform.SetParent(this.transform);
        return networkEntity.gameObject;
    }
Exemple #4
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);
         }
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[]
             {
                 "RegisterSpawnHandler asset '",
                 assetId,
                 "' ",
                 spawnHandler.GetMethodName(),
                 "/",
                 unspawnHandler.GetMethodName()
             }));
         }
         NetworkScene.s_SpawnHandlers[assetId]   = spawnHandler;
         NetworkScene.s_UnspawnHandlers[assetId] = unspawnHandler;
     }
 }
        public static NetworkHash128 Parse(string text)
        {
            int length = text.Length;

            if (length < 32)
            {
                string str = string.Empty;
                for (int i = 0; i < 32 - length; i++)
                {
                    str += "0";
                }
                text = str + text;
            }
            NetworkHash128 result;

            result.i0  = (byte)(NetworkHash128.HexToNumber(text[0]) * 16 + NetworkHash128.HexToNumber(text[1]));
            result.i1  = (byte)(NetworkHash128.HexToNumber(text[2]) * 16 + NetworkHash128.HexToNumber(text[3]));
            result.i2  = (byte)(NetworkHash128.HexToNumber(text[4]) * 16 + NetworkHash128.HexToNumber(text[5]));
            result.i3  = (byte)(NetworkHash128.HexToNumber(text[6]) * 16 + NetworkHash128.HexToNumber(text[7]));
            result.i4  = (byte)(NetworkHash128.HexToNumber(text[8]) * 16 + NetworkHash128.HexToNumber(text[9]));
            result.i5  = (byte)(NetworkHash128.HexToNumber(text[10]) * 16 + NetworkHash128.HexToNumber(text[11]));
            result.i6  = (byte)(NetworkHash128.HexToNumber(text[12]) * 16 + NetworkHash128.HexToNumber(text[13]));
            result.i7  = (byte)(NetworkHash128.HexToNumber(text[14]) * 16 + NetworkHash128.HexToNumber(text[15]));
            result.i8  = (byte)(NetworkHash128.HexToNumber(text[16]) * 16 + NetworkHash128.HexToNumber(text[17]));
            result.i9  = (byte)(NetworkHash128.HexToNumber(text[18]) * 16 + NetworkHash128.HexToNumber(text[19]));
            result.i10 = (byte)(NetworkHash128.HexToNumber(text[20]) * 16 + NetworkHash128.HexToNumber(text[21]));
            result.i11 = (byte)(NetworkHash128.HexToNumber(text[22]) * 16 + NetworkHash128.HexToNumber(text[23]));
            result.i12 = (byte)(NetworkHash128.HexToNumber(text[24]) * 16 + NetworkHash128.HexToNumber(text[25]));
            result.i13 = (byte)(NetworkHash128.HexToNumber(text[26]) * 16 + NetworkHash128.HexToNumber(text[27]));
            result.i14 = (byte)(NetworkHash128.HexToNumber(text[28]) * 16 + NetworkHash128.HexToNumber(text[29]));
            result.i15 = (byte)(NetworkHash128.HexToNumber(text[30]) * 16 + NetworkHash128.HexToNumber(text[31]));
            return(result);
        }
 public override void Deserialize(NetworkReader reader)
 {
     this.netId = reader.ReadNetworkId();
     this.assetId = reader.ReadNetworkHash128();
     this.position = reader.ReadVector3();
     this.payload = reader.ReadBytesAndSize();
 }
 static public void UnregisterSpawnHandler(NetworkHash128 assetId)
 {
     s_SpawnHandlers.Remove(assetId);
     //add by linaibin
     s_SpawnExHandlers.Remove(assetId);
     s_UnspawnHandlers.Remove(assetId);
 }
Exemple #8
0
 internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
 {
     if (!NetworkScene.s_UnspawnHandlers.ContainsKey(assetId) || NetworkScene.s_UnspawnHandlers[assetId] == null)
     {
         return(false);
     }
     NetworkScene.s_UnspawnHandlers[assetId](obj);
     return(true);
 }
 internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
 {
     if (NetworkScene.s_UnspawnHandlers.ContainsKey(assetId) && NetworkScene.s_UnspawnHandlers[assetId] != null)
     {
         UnSpawnDelegate unSpawnDelegate = NetworkScene.s_UnspawnHandlers[assetId];
         unSpawnDelegate(obj);
         return true;
     }
     return false;
 }
Exemple #10
0
 static internal 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);
 }
 static internal bool GetSpawnHandler(NetworkHash128 assetId, out SpawnDelegate handler)
 {
     if (s_SpawnHandlers.ContainsKey(assetId))
     {
         handler = s_SpawnHandlers[assetId];
         return(true);
     }
     handler = null;
     return(false);
 }
 static internal 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);
 }
Exemple #13
0
 internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
 {
     if (NetworkScene.s_UnspawnHandlers.ContainsKey(assetId) && NetworkScene.s_UnspawnHandlers[assetId] != null)
     {
         UnSpawnDelegate unSpawnDelegate = NetworkScene.s_UnspawnHandlers[assetId];
         unSpawnDelegate(obj);
         return(true);
     }
     return(false);
 }
 internal static bool GetSpawnHandler(NetworkHash128 assetId, out SpawnDelegate handler)
 {
     if (NetworkScene.s_SpawnHandlers.ContainsKey(assetId))
     {
         handler = NetworkScene.s_SpawnHandlers[assetId];
         return true;
     }
     handler = null;
     return false;
 }
Exemple #15
0
    public void CmdSendGamePrefab(NetworkHash128 vHash)
    {
        //Debug.Log(vHash.ToString());
        //LobbyManager.Instance.spawnPrefabs.ForEach(x => Debug.Log(x.GetComponent<NetworkIdentity>().assetId.ToString()));

        GameObject hGamePrefab = LobbyManager.Instance.spawnPrefabs.Where(x => x.GetComponent<NetworkIdentity>().assetId.ToString() == vHash.ToString()).FirstOrDefault();
        if (hGamePrefab == null)
            throw new Exception("Requested Prefab Not Found!");

        PrefabToSpawn = hGamePrefab;
    }
Exemple #16
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 + ">");
     }
 }
Exemple #17
0
 internal static string GetStringForAssetId(NetworkHash128 assetId)
 {
     if (NetworkScene.GetPrefab(assetId, out GameObject prefab))
     {
         return(prefab.name);
     }
     if (NetworkScene.GetSpawnHandler(assetId, out SpawnDelegate handler))
     {
         return(handler.Method.Name);
     }
     return("unknown");
 }
 public override void Deserialize(NetworkReader reader)
 {
     this.netId = reader.ReadNetworkId();
     this.assetId = reader.ReadNetworkHash128();
     this.position = reader.ReadVector3();
     this.payload = reader.ReadBytesAndSize();
     uint num = 0x10;
     if ((reader.Length - reader.Position) >= num)
     {
         this.rotation = reader.ReadQuaternion();
     }
 }
Exemple #19
0
    void Start()
    {
        assetId = m_Prefab.GetComponent<NetworkIdentity>().assetId;
        m_Pool = new GameObject[m_ObjectPoolSize];
        for (int i = 0; i < m_ObjectPoolSize; ++i)
        {
            m_Pool[i] = (GameObject)Instantiate(m_Prefab, Vector3.zero, Quaternion.identity);
            m_Pool[i].name = "PoolObject" + i;
            m_Pool[i].SetActive(false);
        }

        ClientScene.RegisterSpawnHandler(assetId, SpawnObject, UnSpawnObject);
    }
        internal static string GetStringForAssetId(NetworkHash128 assetId)
        {
            GameObject    obj2;
            SpawnDelegate delegate2;

            if (NetworkScene.GetPrefab(assetId, out obj2))
            {
                return(obj2.name);
            }
            if (NetworkScene.GetSpawnHandler(assetId, out delegate2))
            {
                return(delegate2.GetMethodName());
            }
            return("unknown");
        }
 internal void SetDynamicAssetId(NetworkHash128 newAssetId)
 {
     if (!this.m_AssetId.IsValid() || this.m_AssetId.Equals((object)newAssetId))
     {
         this.m_AssetId = newAssetId;
     }
     else
     {
         if (!LogFilter.logWarn)
         {
             return;
         }
         Debug.LogWarning((object)("SetDynamicAssetId object already has an assetId <" + (object)this.m_AssetId + ">"));
     }
 }
Exemple #22
0
 internal static bool GetPrefab(NetworkHash128 assetId, out GameObject prefab)
 {
     if (!assetId.IsValid())
     {
         prefab = null;
         return(false);
     }
     if (s_GuidToPrefab.ContainsKey(assetId) && s_GuidToPrefab[assetId] != null)
     {
         prefab = s_GuidToPrefab[assetId];
         return(true);
     }
     prefab = null;
     return(false);
 }
 internal static bool GetPrefab(NetworkHash128 assetId, out GameObject prefab)
 {
     if (!assetId.IsValid())
     {
         prefab = null;
         return false;
     }
     if (NetworkScene.s_GUIDToPrefab.ContainsKey(assetId) && NetworkScene.s_GUIDToPrefab[assetId] != null)
     {
         prefab = NetworkScene.s_GUIDToPrefab[assetId];
         return true;
     }
     prefab = null;
     return false;
 }
Exemple #24
0
        internal static bool GetSpawnHandler(NetworkHash128 assetId, out SpawnDelegate handler)
        {
            bool result;

            if (NetworkScene.s_SpawnHandlers.ContainsKey(assetId))
            {
                handler = NetworkScene.s_SpawnHandlers[assetId];
                result  = true;
            }
            else
            {
                handler = null;
                result  = false;
            }
            return(result);
        }
        internal static string GetStringForAssetId(NetworkHash128 assetId)
        {
            GameObject gameObject;

            if (NetworkScene.GetPrefab(assetId, out gameObject))
            {
                return(gameObject.name);
            }
            SpawnDelegate spawnDelegate;

            if (NetworkScene.GetSpawnHandler(assetId, out spawnDelegate))
            {
                return(spawnDelegate.Method.Name);
            }
            return("unknown");
        }
Exemple #26
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;
 }
Exemple #27
0
        internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
        {
            NetworkIdentity component = prefab.GetComponent <NetworkIdentity>();

            if ((bool)component)
            {
                component.SetDynamicAssetId(newAssetId);
                if (LogFilter.logDebug)
                {
                    Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + component.assetId);
                }
                s_GuidToPrefab[component.assetId] = prefab;
            }
            else if (LogFilter.logError)
            {
                Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
            }
        }
Exemple #28
0
        void SetupIDs()
        {
            GameObject prefab;

            if (ThisIsAPrefab())
            {
                ForceSceneId(0);
                AssignAssetID(gameObject);
            }
            else if (ThisIsASceneObjectWithPrefabParent(out prefab))
            {
                AssignAssetID(prefab);
            }
            else
            {
                m_AssetId = new NetworkHash128();
            }
        }
Exemple #29
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);
 }
Exemple #30
0
        internal static string GetStringForAssetId(NetworkHash128 assetId)
        {
            GameObject    gameObject;
            string        result;
            SpawnDelegate func;

            if (NetworkScene.GetPrefab(assetId, out gameObject))
            {
                result = gameObject.name;
            }
            else if (NetworkScene.GetSpawnHandler(assetId, out func))
            {
                result = func.GetMethodName();
            }
            else
            {
                result = "unknown";
            }
            return(result);
        }
Exemple #31
0
 internal static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     if (spawnHandler == null || unspawnHandler == null)
     {
         if (!LogFilter.logError)
         {
             return;
         }
         Debug.LogError((object)("RegisterSpawnHandler custom spawn function null for " + (object)assetId));
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log((object)("RegisterSpawnHandler asset '" + (object)assetId + "' " + spawnHandler.Method.Name + "/" + unspawnHandler.Method.Name));
         }
         NetworkScene.s_SpawnHandlers[assetId]   = spawnHandler;
         NetworkScene.s_UnspawnHandlers[assetId] = unspawnHandler;
     }
 }
Exemple #32
0
        internal static bool GetPrefab(NetworkHash128 assetId, out GameObject prefab)
        {
            bool result;

            if (!assetId.IsValid())
            {
                prefab = null;
                result = false;
            }
            else if (NetworkScene.s_GuidToPrefab.ContainsKey(assetId) && NetworkScene.s_GuidToPrefab[assetId] != null)
            {
                prefab = NetworkScene.s_GuidToPrefab[assetId];
                result = true;
            }
            else
            {
                prefab = null;
                result = false;
            }
            return(result);
        }
Exemple #33
0
        /// <summary>
        /// Reads a NetworkHash128 assetId.
        /// </summary>
        /// <returns>The assetId object read from the stream.</returns>
        public NetworkHash128 ReadNetworkHash128()
        {
            NetworkHash128 hash = default(NetworkHash128);

            hash.i0  = ReadByte();
            hash.i1  = ReadByte();
            hash.i2  = ReadByte();
            hash.i3  = ReadByte();
            hash.i4  = ReadByte();
            hash.i5  = ReadByte();
            hash.i6  = ReadByte();
            hash.i7  = ReadByte();
            hash.i8  = ReadByte();
            hash.i9  = ReadByte();
            hash.i10 = ReadByte();
            hash.i11 = ReadByte();
            hash.i12 = ReadByte();
            hash.i13 = ReadByte();
            hash.i14 = ReadByte();
            hash.i15 = ReadByte();
            return(hash);
        }
Exemple #34
0
        public NetworkHash128 ReadNetworkHash128()
        {
            NetworkHash128 result = default(NetworkHash128);

            result.i0  = ReadByte();
            result.i1  = ReadByte();
            result.i2  = ReadByte();
            result.i3  = ReadByte();
            result.i4  = ReadByte();
            result.i5  = ReadByte();
            result.i6  = ReadByte();
            result.i7  = ReadByte();
            result.i8  = ReadByte();
            result.i9  = ReadByte();
            result.i10 = ReadByte();
            result.i11 = ReadByte();
            result.i12 = ReadByte();
            result.i13 = ReadByte();
            result.i14 = ReadByte();
            result.i15 = ReadByte();
            return(result);
        }
 internal void SetDynamicAssetId(NetworkHash128 assetId)
 {
     if (!this.m_AssetId.IsValid() || this.m_AssetId.Equals((object) assetId))
       {
     this.m_AssetId = assetId;
       }
       else
       {
     if (!LogFilter.logWarn)
       return;
     Debug.LogWarning((object) ("SetDynamicAssetId object already has an assetId <" + (object) this.m_AssetId + ">"));
       }
 }
 static public void UnregisterSpawnHandler(NetworkHash128 assetId)
 {
     NetworkScene.UnregisterSpawnHandler(assetId);
 }
 //add by linaibin
 static public void RegisterSpawnHandler(NetworkHash128 assetId, SpawnExDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
 }
 internal void SetDynamicAssetId(NetworkHash128 newAssetId)
 {
     if (!this.m_AssetId.IsValid() || this.m_AssetId.Equals(newAssetId))
     {
         this.m_AssetId = newAssetId;
     }
     else if (LogFilter.logWarn)
     {
         Debug.LogWarning("SetDynamicAssetId object already has an assetId <" + this.m_AssetId + ">");
     }
 }
 internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
 {
   if (!NetworkScene.s_UnspawnHandlers.ContainsKey(assetId) || NetworkScene.s_UnspawnHandlers[assetId] == null)
     return false;
   NetworkScene.s_UnspawnHandlers[assetId](obj);
   return true;
 }
 public static void UnregisterSpawnHandler(NetworkHash128 assetId)
 {
   NetworkScene.s_SpawnHandlers.Remove(assetId);
   NetworkScene.s_UnspawnHandlers.Remove(assetId);
 }
 internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
 {
     NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
     if (component != null)
     {
         component.SetDynamicAssetId(newAssetId);
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "Registering prefab '", prefab.name, "' as asset:", component.assetId }));
         }
         s_GuidToPrefab[component.assetId] = prefab;
     }
     else if (LogFilter.logError)
     {
         Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
     }
 }
Exemple #42
0
    // get assetId on an existing prefab
    //NetworkHash128 bulletAssetId = bulletPrefab.GetComponent<NetworkIdentity>().assetId;
    // register handlers for an existing prefab you'd like to custom spawn
    //ClientScene.RegisterSpawnHandler(bulletAssetId, SpawnBullet, UnSpawnBullet);
    // spawn a bullet - SpawnBullet will be called on client.
    //NetworkServer.Spawn(gameObject, creatureAssetId);
    void Start()
    {
        //		NetworkHash128 bulletAssetId = m_Prefab.GetComponent<NetworkIdentity>().assetId;
        assetId = m_Prefab.GetComponent<NetworkIdentity> ().assetId;
        //		m_Prefab.GetComponent<NetworkIdentity> ().RemoveClientAuthority (NetworkConnection conn);
        //     	m_Prefab.GetComponent<NetworkIdentity> ().serverOnly = true;
        //     	m_Prefab.GetComponent<NetworkIdentity> ().hasAuthority = true;
        m_Pool = new GameObject[m_ObjectPoolSize];
        for (int i = 0; i < m_ObjectPoolSize; ++i)
        {
            m_Pool[i] = (GameObject)Instantiate(m_Prefab, Vector3.up * 5, Quaternion.identity);
            m_Pool[i].name = "PoolObject" + i;
            m_Pool[i].tag = "enemy1";
        //            m_Pool[i].GetComponent<"weapon"> ().SetActive (true);
            m_Pool[i].GetComponent<SinglePlayerEnemyController> ().enabled = true;
        //			m_Pool[i].GetComponent<EnemyController1> ().enabled = true;
            m_Pool[i].SetActive(true);
        //			SetUpWeapon(i);
        //			SetUpHat(i);
            SetUpGear(i);

        //			m_Pool[i].GetComponent<Animator> ().SetLayerWeight (2, 1);
        //			m_Pool[i].GetComponent<SealControl2> ().hasAxe = true;
        //			m_Pool[i].GetComponent<SealControl2> ().PowerUp_Axe_Callback (true);

        }

        ClientScene.RegisterSpawnHandler(assetId, SpawnObject, UnSpawnObject);
    }
 public void Write(NetworkHash128 value)
 {
   this.Write(value.i0);
   this.Write(value.i1);
   this.Write(value.i2);
   this.Write(value.i3);
   this.Write(value.i4);
   this.Write(value.i5);
   this.Write(value.i6);
   this.Write(value.i7);
   this.Write(value.i8);
   this.Write(value.i9);
   this.Write(value.i10);
   this.Write(value.i11);
   this.Write(value.i12);
   this.Write(value.i13);
   this.Write(value.i14);
   this.Write(value.i15);
 }
 /// <summary>
 ///   <para>This is an advanced spawning funciotn that registers a custom assetId with the UNET spawning system.</para>
 /// </summary>
 /// <param name="assetId">Custom assetId string.</param>
 /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
 /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
 public static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
   NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
 }
 /// <summary>
 ///   <para>Removes a registered spawn handler function.</para>
 /// </summary>
 /// <param name="assetId"></param>
 public static void UnregisterSpawnHandler(NetworkHash128 assetId)
 {
   NetworkScene.UnregisterSpawnHandler(assetId);
 }
Exemple #46
0
 public GameObject SpawnObject(Vector3 position, NetworkHash128 assetId)
 {
     return GetFromPool(position);
 }
 internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
 {
     if (s_UnspawnHandlers.ContainsKey(assetId) && (s_UnspawnHandlers[assetId] != null))
     {
         UnSpawnDelegate delegate2 = s_UnspawnHandlers[assetId];
         delegate2(obj);
         return true;
     }
     return false;
 }
 private void AssignAssetID(GameObject prefab)
 {
     this.m_AssetId = NetworkHash128.Parse(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath((UnityEngine.Object) prefab)));
 }
 /// <summary>
 ///   <para>Registers a prefab with the UNET spawning system.</para>
 /// </summary>
 /// <param name="prefab">A Prefab that will be spawned.</param>
 /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
 /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
 /// <param name="newAssetId">An assetId to be assigned to this prefab. This allows a dynamically created game object to be registered for an already known asset Id.</param>
 public static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
 {
   NetworkScene.RegisterPrefab(prefab, newAssetId);
 }
 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(string.Concat(new object[]
         {
             "RegisterSpawnHandler asset '",
             assetId,
             "' ",
             spawnHandler.Method.Name,
             "/",
             unspawnHandler.Method.Name
         }));
     }
     NetworkScene.s_SpawnHandlers[assetId] = spawnHandler;
     NetworkScene.s_UnspawnHandlers[assetId] = unspawnHandler;
 }
Exemple #51
0
        void AssignAssetID(GameObject prefab)
        {
            string path = AssetDatabase.GetAssetPath(prefab);

            m_AssetId = NetworkHash128.Parse(AssetDatabase.AssetPathToGUID(path));
        }
 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.Method.Name;
   return "unknown";
 }
Exemple #53
0
    private GameObject SpawnPoolable(Vector3 position, NetworkHash128 assetId)
    {
        for (int i = 0; i < localInstances.Count; i ++) {
            if (localInstances[i].position == position &&
                localInstances[i].GetComponent<NetworkIdentity>().assetId.ToString() == assetId.ToString())
            {
                if (i > 0) {
                    Debug.LogWarning ("The local instance we found as not the first one.  That's odd.");
                }
                Transform inst = localInstances[i];
                localInstances.RemoveAt (i);
        /*
                if (callbacks[i] != null) {
                    callbacks[i](inst);
                }
                callbacks.RemoveAt (i);
        */
                return inst.gameObject;
            }
        }

        for (int i = 0; i < queuedInstances.Count; i ++) {
            if (queuedInstances[i].index == assetIdToIndex[assetId] && queuedInstances[i].position == position) {
                Transform newInst = InstantiateInternal (assetIdToIndex[assetId], queuedInstances[i].tag, queuedInstances[i].layer, position, queuedInstances[i].rotation);
                return newInst.gameObject;
            }
        }

        Debug.LogWarning ("No queued info available for Spawned prefab");
        return null;
    }
 public static void Spawn(GameObject obj, NetworkHash128 assetId)
 {
     NetworkIdentity view;
       if (NetworkServer.GetNetworkIdentity(obj, out view))
     view.SetDynamicAssetId(assetId);
       NetworkServer.instance.SpawnObject(obj);
 }
 internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
 {
   NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
   if ((bool) ((Object) component))
   {
     component.SetDynamicAssetId(newAssetId);
     if (LogFilter.logDebug)
       Debug.Log((object) ("Registering prefab '" + prefab.name + "' as asset:" + (object) component.assetId));
     NetworkScene.s_GuidToPrefab[component.assetId] = prefab;
   }
   else
   {
     if (!LogFilter.logError)
       return;
     Debug.LogError((object) ("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"));
   }
 }
 public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId)
 {
     NetworkIdentity view;
       if (NetworkServer.GetNetworkIdentity(player, out view))
     view.SetDynamicAssetId(assetId);
       return NetworkServer.instance.InternalReplacePlayerForConnection(conn, player, playerControllerId);
 }
 internal static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
   if (spawnHandler == null || unspawnHandler == null)
   {
     if (!LogFilter.logError)
       return;
     Debug.LogError((object) ("RegisterSpawnHandler custom spawn function null for " + (object) assetId));
   }
   else
   {
     if (LogFilter.logDebug)
       Debug.Log((object) ("RegisterSpawnHandler asset '" + (object) assetId + "' " + spawnHandler.Method.Name + "/" + unspawnHandler.Method.Name));
     NetworkScene.s_SpawnHandlers[assetId] = spawnHandler;
     NetworkScene.s_UnspawnHandlers[assetId] = unspawnHandler;
   }
 }
 // this assigns the newAssetId to the prefab. This is for registering dynamically created game objects for already know assetIds.
 static public void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
 {
     NetworkScene.RegisterPrefab(prefab, newAssetId);
 }
 private void AssignAssetID(GameObject prefab)
 {
     string assetPath = AssetDatabase.GetAssetPath(prefab);
     this.m_AssetId = NetworkHash128.Parse(AssetDatabase.AssetPathToGUID(assetPath));
 }
 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);
         }
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "RegisterSpawnHandler asset '", assetId, "' ", DotNetCompatibility.GetMethodName(spawnHandler), "/", DotNetCompatibility.GetMethodName(unspawnHandler) }));
         }
         s_SpawnHandlers[assetId] = spawnHandler;
         s_UnspawnHandlers[assetId] = unspawnHandler;
     }
 }