Exemplo n.º 1
0
        /**********************************************************************/
        // Initialize Managers in order, layer by layer
        IEnumerator InitLayers()
        {
            // Go through the layers
            int layerNum = 1;

            foreach (ManagerInitLayer layer in m_managerInitLayers)
            {
                Debug.Log("Initializing Managers Layer " + layerNum + ": " + layer.LayerName);
                List <ManagerBase> workMgr = new List <ManagerBase>(); // List of Managers currently initializing

                // Instantiate GameObjects from Manager prefabs and Initialize
                foreach (ManagerBase mgr in layer.m_mgrs)
                {
                    ManagerBase newMgr = mgr.gameObject.GetComponent <ManagerBase>();

                    if (newMgr != null)
                    {
                        workMgr.Add(newMgr);

                        AddManagerToCache(newMgr);
                        newMgr.InitState = InitState.Initializing;
                        StartCoroutine(newMgr.RunInitialization());
                    }
                    else
                    {
                        Debug.LogError("ManagerLocator.InitLayers: Unable to Init Manager due to missing ManagerBase component - " + mgr.name);
                    }
                }

                // Wait for all Managers on this layer to finish
                bool layerFinished = false;
                while (!layerFinished)
                {
                    layerFinished = true;
                    foreach (ManagerBase mgr in workMgr)
                    {
                        if (mgr.InitState == InitState.Failed)
                        {
                            InitState = InitState.Failed;
                            break;
                        }
                        if (mgr.InitState != InitState.Initialized)
                        {
                            layerFinished = false;
                            break;
                        }
                    }

                    yield return(null);
                }

                Debug.Log("ManagerInitLayer: Layer " + layerNum + " Finished");
                if (InitState == InitState.Failed)
                {
                    // Initialization has failed.
                    RunInitializationFail();
                    yield break;
                }
                layerNum++;
            }
            _initComplete = true;
        }