private int _count;                       // Кол-во обрабатываемых вещей.

        #region Public Methods

        public void StartLoading()
        {
            A.Assert((pools == null || pools.Length == 0), "Pool Loader is empty!", true);

            var root = new GameObject();

            root.name = "Pools";
            AntPoolManager.SetParent(root.transform);

            _count   = 0;
            _current = 0;
            for (int i = 0, n = pools.Length; i < n; i++)
            {
                _count += pools[i].items.Length;
            }

            _currentPoolIndex = 0;
            _currentPool      = pools[_currentPoolIndex];

            if (EventStart != null)
            {
                EventStart(this, 0.0f);
            }

            StartCoroutine(DoProgress());
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUILayout.BeginVertical(EditorStyles.helpBox);
            AntPoolList newPool = null;

            newPool = EditorGUILayout.ObjectField("Add Pool List", newPool, typeof(AntPoolList), true) as AntPoolList;
            if (newPool != null)
            {
                if (!AlreadyAdded(newPool))
                {
                    AntArray.Add <AntPoolList>(ref _self.pools, newPool);
                }
                else
                {
                    EditorUtility.DisplayDialog("Oops!", string.Format("Object `{0}` already added to the pool list!", newPool.name), "Ok");
                }
            }

            GUILayout.Space(3.0f);
            if (_self.pools.Length > 0)
            {
                EditorGUI.indentLevel++;
                int delIndex = -1;
                for (int i = 0, n = _self.pools.Length; i < n; i++)
                {
                    GUILayout.BeginHorizontal();

                    _self.pools[i] = EditorGUILayout.ObjectField(_self.pools[i], typeof(AntPoolList), true) as AntPoolList;

                    if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(18.0f), GUILayout.MaxHeight(16.0f)))
                    {
                        delIndex = i;
                    }

                    GUILayout.EndHorizontal();
                }

                if (delIndex > -1)
                {
                    AntArray.RemoveAt <AntPoolList>(ref _self.pools, delIndex);
                }
                EditorGUI.indentLevel--;
            }
            else
            {
                EditorGUILayout.LabelField("<Empty>", EditorStyles.centeredGreyMiniLabel);
            }
            GUILayout.Space(3.0f);
            GUILayout.EndVertical();

            _self.countPerStep = EditorGUILayout.IntField("Count Per Step", _self.countPerStep);
        }
        private IEnumerator DoProgress()
        {
            while (true)
            {
                int n = (_current + countPerStep > _count) ? _count - _current : countPerStep;
                for (int i = 0; i < n; i++)
                {
                    if (_currentItemIndex == _currentPool.items.Length)
                    {
                        _currentPoolIndex++;
                        _currentPool      = pools[_currentPoolIndex];
                        _currentItemIndex = 0;
                    }

                    AntPoolManager.AddPool(_currentPool.items[_currentItemIndex].prefab, _currentPool.items[_currentItemIndex].initialSize);
                    _currentItemIndex++;
                    _current++;
                }

                if (EventProcess != null)
                {
                    EventProcess(this, (float)_current / (float)_count);
                }

                if (_current < _count)
                {
                    yield return(null);
                }
                else
                {
                    break;
                }
            }

            if (EventComplete != null)
            {
                EventComplete(this, 1.0f);
            }
        }
 private void OnEnable()
 {
     _self = (AntPoolList)target;
 }
Пример #5
0
        private bool AlreadyAdded(AntPoolList aObject)
        {
            int index = System.Array.FindIndex(_self.pools, x => System.Object.ReferenceEquals(x, aObject));

            return(index >= 0 && index < _self.pools.Length);
        }