コード例 #1
0
 public void Push(GameObject obj)
 {
     ReservedInstances.Enqueue(obj);
     if (EventPush != null)
     {
         EventPush(this, obj);
     }
 }
コード例 #2
0
        private void Generate()
        {
            var instance = Instantiate(Prototype, transform);

            instance.SetActive(false);
            ReservedInstances.Enqueue(instance);

            CurrentSize++;

            if (EventGenerate != null)
            {
                EventGenerate(this, instance);
            }
        }
コード例 #3
0
        public GameObject Pop()
        {
            if (ReservedInstances.Count == 0)
            {
                Generate();
            }

            var instance = ReservedInstances.Dequeue();

            ActiveInstances.Add(instance);

            if (EventPop != null)
            {
                EventPop(this, instance);
            }

            return(instance);
        }
コード例 #4
0
        public void Clear()
        {
            var listActive = new Queue <GameObject>(ActiveInstances.ToList());

            while (listActive.Count > 0)
            {
                GameObject.DestroyImmediate(listActive.Dequeue());
            }


            var listReserv = new Queue <GameObject>(ReservedInstances.ToList());

            while (listReserv.Count > 0)
            {
                GameObject.DestroyImmediate(listReserv.Dequeue());
            }

            ReservedInstances = null;
            ActiveInstances   = null;
        }