Exemplo n.º 1
0
        private IEnumerator AddWidgetCor(string path, Action <Widget> onWidgetAdded = null)
        {
            // Create on loaded callback.
            UnityEngine.Object          loadedWidgetObject   = null;
            Action <UnityEngine.Object> onWidgetObjectLoaded = delegate(UnityEngine.Object loadedObject) {
                loadedWidgetObject = loadedObject;
            };

            // Wait for AsyncLoader to load the object.
            yield return(AsyncLoader.LoadResource(path, onLoaded: onWidgetObjectLoaded));

            // InstantiateWidget(loadedWidgetObject, onWidgetAdded);
            yield return(CoroutineRunner.StartCoroutine(InstantiateWidgetCor(loadedWidgetObject, onWidgetAdded)));
        }
        private IEnumerator AddCor(string path, int amount)
        {
            // Get path hash.
            var hash = path.GetHashCode();

            // Save path, we may need it again in the future.
            _paths.Add(hash, path);

            // Create new queue/list in dictionaries if one doesn't already exist.
            if (_poolComplete.ContainsKey(hash) == false)
            {
                _poolComplete.Add(hash, new List <IPoolable>());
                _poolAvailable.Add(hash, new Queue <IPoolable>());
                _poolCheckedOut.Add(hash, new List <IPoolable>());
            }

            // Load resource.
            UnityEngine.Object          loadedObject     = null;
            Action <UnityEngine.Object> onResourceLoaded = delegate(UnityEngine.Object o) {
                loadedObject = o;
            };

            yield return(AsyncLoader.LoadResource(path, onLoaded: onResourceLoaded));

            // Instantiate objects and add to dictionary.
            for (int i = 0; i < amount; i++)
            {
                // Instantiate object using loaded resource.
                var instantiatedObject = (GameObject)Instantiate(loadedObject, _poolContainer);

                // Get the poolable interface.
                var poolable = instantiatedObject.GetComponent <IPoolable>();

                // Save hash in the poolable.
                poolable.Hash = hash;

                // Tell the poolable its being pooled.
                poolable.Pool();

                // Add to lists/queues.
                _poolComplete[hash].Add(poolable);
                _poolAvailable[hash].Enqueue(poolable);
            }
        }