public static void Delete(GameObject g)
        {
            int objectId = ObjectPool.GetPoolToken(g).tokenId;

            if (!InstantiateDatas.ContainsKey(objectId))
            {
                Debug.LogError("Trying to delete buffered Rpc for object we have no data for. Object Id=[" + objectId + "]");
            }
            else
            {
                Hashtable bufferMask = InstantiateDatas[objectId];
                PhotonNetwork.RaiseEvent(CustomRpcEventCode, bufferMask, true, new RaiseEventOptions()
                {
                    CachingOption = EventCaching.RemoveFromRoomCache
                });
                InstantiateDatas.Remove(objectId);
            }

            Hashtable deleteHash = new Hashtable();

            deleteHash[RpcKeys.MethodId] = MethodIds.Delete;
            deleteHash[RpcKeys.ObjectId] = objectId;
            PhotonNetwork.RaiseEvent(CustomRpcEventCode, deleteHash, true, new RaiseEventOptions()
            {
                CachingOption = EventCaching.DoNotCache, Receivers = ReceiverGroup.Others
            });
        }
        public static void Delete(GameObject g)
        {
            if (ObjectPool.objectPool.LogFull)
            {
                Debug.Log("Deleting " + g.name);
            }
            PoolToken token  = ObjectPool.GetPoolToken(g);
            Pool      myPool = ObjectPool.GetPool(token.poolPrefabString, token.poolType);

            myPool.StoreObject(g);
        }
示例#3
0
        private void deletePlayerObject(GameObject g)
        {
            PoolToken t = ObjectPool.GetPoolToken(g);

            if (playerObjects.ContainsKey(t.ownerId))
            {
                bool listContains = playerObjects[t.ownerId].Contains(g);
                if (listContains)
                {
                    playerObjects[t.ownerId].Remove(g);
                }
                else
                {
                    Debug.LogError("Tried to delete object from List but there was no GameObject g=[" + g.name + "]");
                }
            }
            else
            {
                Debug.LogError("Tried to delete object from Dictionary but there was no Key for player with ownerId=[" + t.ownerId + "]");
            }
        }
示例#4
0
        internal static void AddManagedObject(GameObject g)
        {
            PoolToken token = ObjectPool.GetPoolToken(g);

            //all
            if (AllObjects.ContainsKey(token.tokenId))
            {
                throw new Exception("Trying to add object with existing Id. New Object: " + g.name + " | Current Object: " + AllObjects[token.tokenId]);
            }
            AllObjects[token.tokenId] = g;

            //all by type
            if (!AllObjectsByType.ContainsKey(token.poolPrefabString))
            {
                AllObjectsByType[token.poolPrefabString] = new List <GameObject>();
            }
            AllObjectsByType[token.poolPrefabString].Add(g);

            //player objects
            if (!PlayerObjects.ContainsKey(token.ownerId))
            {
                PlayerObjects[token.ownerId] = new List <GameObject>();
            }
            PlayerObjects[token.ownerId].Add(g);

            //player controller
            if (token.IsPlayerController)
            {
                if (PlayerControllers.ContainsKey(token.ownerId))
                {
                    throw new Exception("Trying to add player controller for player ID " + token.ownerId + " but one already exists.");
                }
                else
                {
                    PlayerControllers[token.ownerId] = g;
                }
            }
        }
示例#5
0
        /// <summary>
        /// stores an object in the pool, removing it from the game world
        /// </summary>
        public void StoreObject(GameObject g)
        {
            PoolToken pt = ObjectPool.GetPoolToken(g);

            SendMessage("PreObjectDeactivate", g, SendMessageOptions.DontRequireReceiver);
            g.BroadcastMessage("OnObjectPoolDestroy", SendMessageOptions.DontRequireReceiver);
            g.BroadcastMessage("OnObjectPoolDelete", SendMessageOptions.DontRequireReceiver);
            if (transform.childCount > MaxPoolSize)
            {
                pt.usable = false;
                Destroy(g);
            }
            else
            {
                g.BroadcastMessage("OnDestroy", SendMessageOptions.DontRequireReceiver);
                g.SetActive(false);
                g.transform.parent   = transform;
                g.transform.position = Vector3.zero;
                g.transform.rotation = Quaternion.identity;
            }
            deletePlayerObject(g);
            ManagedObjects.RemoveManagedObject(g);
            SendMessage("PostObjectDeactivate", g, SendMessageOptions.DontRequireReceiver);
        }
示例#6
0
        internal static void RemoveManagedObject(GameObject g)
        {
            PoolToken token = ObjectPool.GetPoolToken(g);

            //all
            if (!AllObjects.ContainsKey(token.tokenId))
            {
                throw new Exception("Trying to delete nonexistent object with name: " + g.name);
            }
            AllObjects.Remove(token.tokenId);

            //all by type
            if (AllObjectsByType.ContainsKey(token.poolPrefabString))
            {
                bool containsG = AllObjectsByType[token.poolPrefabString].Contains(g);
                if (containsG)
                {
                    AllObjectsByType[token.poolPrefabString].Remove(g);
                    if (AllObjectsByType[token.poolPrefabString].Count == 0)
                    {
                        AllObjectsByType.Remove(token.poolPrefabString);
                    }
                }
                else
                {
                    Debug.LogError("Error removing managed game object. This should never happen, make sure you instantiate and delete everything properly.");
                }
            }
            else
            {
                Debug.LogError("Error removing managed game object. This should never happen, make sure you instantiate and delete everything properly.");
            }

            //player objects
            if (PlayerObjects.ContainsKey(token.ownerId))
            {
                bool containsG = PlayerObjects[token.ownerId].Contains(g);
                if (containsG)
                {
                    PlayerObjects[token.ownerId].Remove(g);
                    if (PlayerObjects[token.ownerId].Count == 0)
                    {
                        PlayerObjects.Remove(token.ownerId);
                    }
                }
                else
                {
                    Debug.LogError("Error removing managed game object. This should never happen, make sure you instantiate and delete everything properly.");
                }
            }
            else
            {
                Debug.LogError("Error removing managed game object. This should never happen, make sure you instantiate and delete everything properly.");
            }

            //player controller
            if (token.IsPlayerController)
            {
                if (!PlayerControllers.ContainsKey(token.ownerId))
                {
                    Debug.LogError("Error removing managed game object. This should never happen, make sure you instantiate and delete everything properly.");
                }
                else
                {
                    PlayerControllers.Remove(token.ownerId);
                }
            }
        }