예제 #1
0
 /// <summary>
 /// 注册局部管理器。
 /// </summary>
 /// <param name="local"></param>
 public void registerLocal(LocalManager local)
 {
     if (!localDic.ContainsKey(local.gameObject.scene.path))
     {
         localDic.Add(local.gameObject.scene.path, local);
         local.global = this;
     }
 }
예제 #2
0
        public void unregisterLocal(LocalManager local)
        {
            string scenePath = null;

            foreach (var p in localDic)
            {
                if (p.Value == local)
                {
                    scenePath = p.Key;
                    break;
                }
            }
            if (scenePath != null)
            {
                localDic.Remove(scenePath);
                local.global = null;
            }
        }
예제 #3
0
        private void Operation_onSceneLoaded(LoadSceneOperation operation)
        {
            //按道理来讲场景里的东西应该都Awake过了,以防万一还是检查一下场景里的LocalManager吧。
            Scene        scene        = SceneManager.GetSceneByPath(operation.scenePath);
            LocalManager currentLocal = scene.findInstance <LocalManager>();

            if (currentLocal == null)
            {
                GameObject gameObject = new GameObject("LocalManager");
                SceneManager.MoveGameObjectToScene(gameObject, scene);
                currentLocal = gameObject.AddComponent <LocalManager>();
            }
            registerLocal(currentLocal);
            //触发场景加载完毕事件
            foreach (LocalManager local in locals)
            {
                foreach (Manager manager in local.managers)
                {
                    manager.onSceneLoaded(operation.scenePath);
                }
            }
        }