/// <summary>Queue up an object to be instantiated.</summary> /// <param name="iq">The Object + prefab to be instantiated.</param> public void QueueInstantiate(InstantiateQueue iq) { instantiateQueue.Add(iq); }
IEnumerable CheckQueues() { startTime = Time.realtimeSinceStartup; //Debug.Log("check1"); while ((instantiateQueue.Count + destroyQueue.Count) > 0) { //Debug.Log("check2"); // Are we over our time limit for this frame? if (Time.realtimeSinceStartup - startTime >= maxTime) { yield return 0; } //Debug.Log("check3"); // Check Queues for work to do. if (instantiateQueue.Count > 0) { tempItem = instantiateQueue[0]; tempItem.myObject = (GameObject)Instantiate(tempItem.myPrefab, tempItem.myPosition, tempItem.myQuaternian); instantiateQueue.Remove(tempItem); } else if (destroyQueue.Count > 0) { tempObject = destroyQueue[0]; destroyQueue.Remove(tempObject); GameObject.Destroy(tempObject); } } yield return 0; }
void Update() { //Debug.Log("check0"); //CheckQueues(); //StartCoroutine("CheckQueues"); startTime = Time.realtimeSinceStartup; //Debug.Log("check1"); while ((instantiateQueue.Count + destroyQueue.Count) > 0) { //Debug.Log("check2"); // Are we over our time limit for this frame? if (Time.realtimeSinceStartup - startTime >= maxTime) { return; } //Debug.Log("check3"); // Check Queues for work to do. if (destroyQueue.Count > 0) { tempObject = destroyQueue[0]; instantiateQueue.RemoveAt(0); GameObject.Destroy(tempObject); }else if (instantiateQueue.Count > 0) { tempItem = instantiateQueue[0]; tempItem.myObject = (GameObject)Instantiate(tempItem.myPrefab, tempItem.myPosition, tempItem.myQuaternian); instantiateQueue.RemoveAt(0); } } }