Beispiel #1
0
        public bool Register(GameObject _object)
        {
            if (_object == null || !Enabled)
            {
                return(false);
            }

            bool _added = false;

            if (!IsRegistered(_object))
            {
                ActiveObjects.Add(_object);
                _added = true;

                ICECreatureEntity _entity = _object.GetComponent <ICECreatureEntity>();

                // if the object is an ICE entity we have to adapt the parent according to it's hierarchy settings
                if (_entity != null && _entity.UseHierarchyManagement)
                {
                    _object.transform.SetParent(UpdateGroupParent(), true);
                }

                if (_entity != null)
                {
                    OnGroupMessage += _entity.Message.ReceiveGroupMessage;
                }
            }

            return(_added);
        }
Beispiel #2
0
        public GameObject GetNewEnemyFromType(Enumerations.EnemyType enemyType)
        {
            if (InactiveObjects.Exists(x => x.GetComponent(enemyType.ToString())))
            {
                var poolObject = InactiveObjects.Find(x => x.GetComponent(enemyType.ToString()));
                var anim       = GetComponentInChildren <Animator> ();
                anim.SetBool("isDead", false);
                ActiveObjects.Add(poolObject);
                InactiveObjects.Remove(poolObject);
                poolObject.transform.parent = transform;
                // Initialize happens later
                Enemy pooledEnemy = poolObject.GetComponent <Enemy>();
                pooledEnemy.Repool();
                poolObject.SetActive(true);
                return(poolObject);
            }
            //Debug.LogWarning(enemyType);
            var GO = PrefabPool.Find(x => x.GetComponent(enemyType.ToString()) != null);

            if (GO == null)
            {
                var msg = string.Format("No object found with type '{0}'.", enemyType);
                Debug.LogError(msg, gameObject);
            }
            var resultGO = GameObject.Instantiate(GO) as GameObject;

            ActiveObjects.Add(resultGO.gameObject);
            resultGO.transform.parent = transform;
            return(resultGO);
        }
Beispiel #3
0
    public GameObject GetObject()
    {
        GameObject obj;

        if (AvailableObjects.Count > 0)
        {
            obj = AvailableObjects[0];
            AvailableObjects.RemoveAt(0);
            try
            {
                obj.SetActive(true);
            }
            catch (MissingReferenceException e)
            {
                Debug.LogError("MRE from " + gameObject.name);
                throw e;
            }
        }
        else
        {
            //None available, so create a new one
            obj = Instantiate(prefab);
        }
        //Prep the object for the game world before returning
        obj.transform.parent     = null;
        obj.transform.position   = Vector3.zero;
        obj.transform.rotation   = Quaternion.identity;
        obj.transform.localScale = Vector3.one;
        ActiveObjects.Add(obj);
        return(obj);
    }
Beispiel #4
0
        public GameObject GetNewProjectileFromType(Enumerations.ProjectileTypes bulletType, Vector3 startPos, Quaternion startRot)
        {
            //Debug.Log(string.Format("Fetching object with type '{0}'.", bulletType));
            if (InactiveObjects.Exists(x => x.GetComponent(bulletType.ToString())))
            {
                Debug.Log(string.Format("Object found in pool."));
                var poolObject = InactiveObjects.Find(x => x.GetComponent(bulletType.ToString()));
                ActiveObjects.Add(poolObject);
                InactiveObjects.Remove(poolObject);
                poolObject.transform.parent   = transform;
                poolObject.transform.rotation = startRot;
                poolObject.SetActive(true);
                return(poolObject);
            }
            var GO = PrefabPool.Find(x => x.GetComponent(bulletType.ToString()) != null);

            if (GO == null)
            {
                var msg = string.Format("No object found with type '{0}'.", bulletType);
                Debug.LogError(msg, gameObject);
            }
            var resultGO = GameObject.Instantiate(GO, startPos, startRot) as GameObject;

            ActiveObjects.Add(resultGO.gameObject);
            resultGO.transform.parent = transform;

            return(resultGO);
        }
Beispiel #5
0
 public void Initialize()
 {
     ActiveObjects.Add(new Player(PlayerStart));
     ActiveObjects.AddRange(StaticObjects);
     ActiveObjects.AddRange(EnemyDots);
     ActiveObjects.AddRange(Coins);
     ActiveObjects.Add(Goal);
 }
Beispiel #6
0
        /// <summary>
        /// Adds the given GameObject to this pool. If despawn is true, also despawns the object.
        /// </summary>
        private void Bind(GameObject gameObject, bool despawn)
        {
            ActiveObjects.Add(gameObject);

            if (despawn)
            {
                Despawn(gameObject);
            }
        }
Beispiel #7
0
        public ReplayGameObject SpawnObject(GameObject go)
        {
            int newObjectId = NextIdentifier;

            var result = new ReplayGameObject(newObjectId, go);

            ActiveObjects.Add(result);

            return(result);
        }
        void UpdatePossiblePosition(GameObject obj, Vector2 newPos, bool recycle)
        {
            bool isStatic = IsStaticObject(obj.tag);

            //Check the has-object-pos dictionary
            if (recycle) // reuse
            {
                //In the possible position, add the current pos stored in the object dict and remove the new pos
                if (isStatic)
                {
                    //Debug.Log("Add " + staticObjectDicts[obj] + " Remove " + newPos + " Obj name:" + obj.name);


                    possiblePositions.Add(staticObjectDicts[obj]);
                    staticObjectDicts[obj] = newPos;
                    RemovePossiblePosition(possiblePositions, newPos);
                }
                else
                {
                    //Debug.Log("Add " + dynamicObjectDicts[obj] + " Remove " + newPos + " Obj name:" + obj.name);
                    possiblePositions.Add(dynamicObjectDicts[obj]);
                    dynamicObjectDicts[obj] = newPos;
                    RemovePossiblePosition(possiblePositions, newPos);
                }
            }
            else //Instantiate new object
            {
                //In the possible positions list, just remove the current pos
                if (isStatic)
                {
                    if (IsExists(newPos, staticObjectDicts))
                    {
                        return;
                    }
                    staticObjectDicts.Add(obj, newPos);
                    RemovePossiblePosition(possiblePositions, newPos);
                    //Debug.Log("remove: " + newPos);
                }
                else
                {
                    if (IsExists(newPos, dynamicObjectDicts))
                    {
                        return;
                    }
                    dynamicObjectDicts.Add(obj, newPos);
                    RemovePossiblePosition(possiblePositions, newPos);
                    ActiveObjects.Add(obj);
                }

                //Debug.Log("Remove " + newPos + "Obj name:  " + obj.name + "status: " + status);
            }
        }
Beispiel #9
0
        /// <summary>
        ///     对象活动时登记
        /// </summary>
        public static void OnObjectActive(IService obj)
        {
            bool can;

            Logger.Information("[OnObjectActive] {0}", obj.ServiceName);
            lock (ActiveObjects)
            {
                ActiveObjects.Add(obj);
            }
            can = ActiveObjects.Count + FailedObjects.Count == FlowServices.Length;
            if (can)
            {
                ActiveSemaphore.Release(); //发出完成信号
            }
        }
Beispiel #10
0
        public GameObject GetNewEnemyFromType(Enumerations.EnemyType enemyType)
        {
            Debug.Log(string.Format("Fetching object with type '{0}'.", enemyType), gameObject);
            var GO = PrefabPool.Find(x => x.GetComponent(Enumerations.PowerupType.DamagePowerup.ToString()) != null);

            if (GO == null)
            {
                var msg = string.Format("No object found with type '{0}'.", enemyType);
                Debug.LogError(msg, gameObject);
            }
            var resultGO = GameObject.Instantiate(GO) as GameObject;

            ActiveObjects.Add(resultGO.gameObject);
            resultGO.transform.parent = transform;
            return(resultGO);
        }
Beispiel #11
0
 public static void VUIObjectsUpdate(bool StartObject)
 {
     ActiveObjects.Clear();
     foreach (var O in VUIObjects)
     {
         if (O.Value["Active"] == "true")
         {
             ActiveObjects.Add(O.Key);
         }
     }
     Count = ActiveObjects.Count - 1;
     if (StartObject == true)
     {
         Section = 0;
     }
 }
Beispiel #12
0
        private GameObject _Spawn(Vector3 position, Quaternion rotation)
        {
            GameObject toSpawn = GetInactiveOrInstantiate();

            toSpawn.transform.parent   = null;
            toSpawn.transform.position = position;
            toSpawn.transform.rotation = rotation;
            toSpawn.SetActive(true);

            InactiveObjects.Remove(toSpawn);
            ActiveObjects.Add(toSpawn);

            PopulateIfRequired();

            return(toSpawn);
        }
Beispiel #13
0
    private PooledObject Pop(int requestedIndex = -1)
    {
        int index = requestedIndex >= 0 && requestedIndex < PooledObjects.Length ? requestedIndex : Random.Range(0, PooledObjects.Length);

        if (PooledObjects[index].Count > 0)
        {
            PooledObject obj = PooledObjects[index].Pop();
            ActiveObjects.Add(obj);
            return(obj);
        }

        if (canGrow)
        {
            PooledObject obj = Grow(true, requestedIndex);
            ActiveObjects.Add(obj);
            return(obj);
        }

        return(null);
    }
Beispiel #14
0
 public void SpawnObject(IGameObject obj)
 {
     ActiveObjects.Add(obj);
 }
Beispiel #15
0
 public void SpawnObject<T>() where T : IGameObject
 {
     ActiveObjects.Add(Activator.CreateInstance<T>());
 }