Exemplo n.º 1
0
        public void Update()
        {
            int count = 0;

            if (instantiateQueue.Count > instantiateLimit)
            {
                count = instantiateLimit;
            }
            else
            {
                count = instantiateQueue.Count;
            }

            for (int i = 0; i < count; i++)
            {
                InstantiateTask task   = instantiateQueue.Dequeue();
                GameObject      result = Instantiate(task.prefab);
                if (task.callback != null)
                {
                    task.callback(result);
                }
                if (task.completion != null)
                {
                    task.completion.TrySetResult(result);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 单线程异步分帧加载
        /// </summary>
        /// <param name="prefab"></param>
        /// <returns></returns>
        public static UniTask <GameObject> InstantiateAsync(GameObject prefab)
        {
            UniTaskCompletionSource <GameObject> source = new UniTaskCompletionSource <GameObject>();
            InstantiateTask task = new InstantiateTask(prefab, source, null);

            Instance.instantiateQueue.Enqueue(task);
            return(source.Task);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 单线程异步分帧加载
        /// </summary>
        /// <param name="prefab"></param>
        /// <returns></returns>
        public static void InstantiateAsync(GameObject prefab, Action <GameObject> callback)
        {
            InstantiateTask task = new InstantiateTask(prefab, null, callback);

            Instance.instantiateQueue.Enqueue(task);
        }