Ejemplo n.º 1
0
        private static void OnReceiveRpc(byte code, object content, int senderId)
        {
            if (code == CustomRpcEventCode)
            {
                if (content == null || (content as Hashtable) == null)
                {
                    Debug.LogError("Received malformed ObjectPooling Rpc from sender=[" + senderId + "]. This should never happen, check that all instantiations and deletes are called properly through ObjectPool");
                }

                Hashtable rpcData    = (Hashtable)content;
                byte      MethodId   = (byte)rpcData[RpcKeys.MethodId];
                int       ObjectId   = (int)rpcData[RpcKeys.ObjectId];
                object    MethodData = rpcData[RpcKeys.MethodData];

                switch (MethodId)
                {
                case MethodIds.Instantiate:
                {
                    InstantiationData i = new InstantiationData((Hashtable)rpcData[RpcKeys.InstantiationData]);

                    if (ObjectPool.objectPool.LogFull)
                    {
                        Debug.Log("Received RPC from " + senderId + " to instantiate object with prefabPath=[" + i.PrefabPath + "]");
                    }

                    ObjectPoolManager.Instantiate(i);
                }
                break;

                case MethodIds.Delete:
                {
                    if (ObjectPool.objectPool.LogFull)
                    {
                        Debug.Log("Received RPC from " + senderId + " to delete object with Id=[" + ObjectId + "]");
                    }
                    ObjectPoolManager.Delete(ObjectPool.Find(ObjectId));
                }
                break;

                case MethodIds.InstantiateAsChild:
                {
                    InstantiationData i = new InstantiationData((Hashtable)rpcData[RpcKeys.InstantiationData]);

                    if (ObjectPool.objectPool.LogFull)
                    {
                        Debug.Log("Received RPC from " + senderId + " to instantiate object with prefabPath=[" + i.PrefabPath + "]");
                    }

                    ObjectPoolManager.InstantiateAsChild(i, (int)MethodData);
                }
                break;

                case MethodIds.InstantiateAsSibling:
                {
                    InstantiationData i = new InstantiationData((Hashtable)rpcData[RpcKeys.InstantiationData]);

                    if (ObjectPool.objectPool.LogFull)
                    {
                        Debug.Log("Received RPC from " + senderId + " to instantiate object with prefabPath=[" + i.PrefabPath + "]");
                    }

                    ObjectPoolManager.InstantiateAsSibling(i, (int)MethodData);
                }
                break;
                }
            }
        }