Exemplo n.º 1
0
        /// <summary>
        /// 加载跳转到某一场景
        /// TODO 跳转到自己会是怎么样呢?
        /// 暂时未用到
        /// </summary>
        /// <param name="showLoading">默认是TRUE,大概只有在Splash后的跳转,才是FALSE吧</param>
        private static void GotoScene <T>(object data, bool showLoading = true) where T : KSceneManager
        {
            string typeName = typeof(T).Name;

            Debug.Log("开始加载|" + new System.Exception().StackTrace);

            Debug.Break();

            if (showLoading)
            {
                //显示Loading的处理方法
            }

            KSceneManager ks = GetCurKScene();

            if (null != ks)
            {
                DestroyImmediate(ks.gameObject);
                ks = null;
            }

            SceneManager.LoadSceneAsync(typeName);

            if (null == ks)
            {
                GameObject go = new GameObject();
                go.name = "__" + typeName + "__";
                DontDestroyOnLoad(go);                 //这里的组件需要手动来删除了

                ks = go.AddComponent <T>();
            }

            ks.data = data;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 切换场景的统一调用,简化切换场景的代码
        /// </summary>
        public static void SwitchScene(string[] preloadABs, string sceneName)
        {
            KSceneManager ks = GetCurKScene();

            ks.StartCoroutine(KAssetBundle.LoadPersistentAB(preloadABs, () => {
                SceneManager.LoadSceneAsync(sceneName);
            }));
        }
Exemplo n.º 3
0
        private void onSucc()
        {
            LoadingProgressWindow loadingProgressWindow = KAssetBundle.InstantiateView <LoadingProgressWindow>();

            loadingProgressWindow.SetContent(null);

            KSceneManager.SwitchScene();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 当场景加载完后,调用此方法来处理
        /// </summary>
        public static void Load()
        {
            Scene scene = SceneManager.GetActiveScene();             //默认组件与场景名一致

            KAssetBundle.ApplyShaderForEditorMode(scene);

            // 添加EventSystem
            EventSystem eventSystem = GameObject.FindObjectOfType <EventSystem>();

            Debug.Log("eventSystem|" + eventSystem);
            if (eventSystem == null)
            {
                Debug.Log("load|EventSystem|Prefab");
                GameObject origGo = Resources.Load <GameObject>("EventSystem");
                GameObject newGo  = GameObject.Instantiate <GameObject>(origGo);
                newGo.name = origGo.name;
            }

            //如果没有,则先添加组件
            KSceneManager ks = GetCurKScene();

            if (null == ks)
            {
                GameObject go = new GameObject();
                go.name = "__" + scene.name + "__";

                System.Type t = null;

                string defaultClassName = "KScene." + scene.name + "Manager";

                // 场景管理组件钩子
                t = KSceneHook.GetManagerType(scene.name);

                if (t == null)
                {
                    Debug.Log("use|default|type|" + defaultClassName);
                    t = System.Type.GetType(defaultClassName);
                }

                if (t == null)
                {
                    Debug.LogError("cannot|find|default|type|" + defaultClassName);
                }
                else
                {
                    ks = (KSceneManager)go.AddComponent(t);
                }
            }

            if (ks != null)
            {
                ks.LoadData();
            }
            else
            {
                Debug.LogError("cannot|find|ks");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 取得当前场景的KScene组件,不允许在同个场景有两个KScene组件
        /// </summary>
        /// <returns></returns>
        private static KSceneManager GetCurKScene()
        {
            KSceneManager ks = GameObject.FindObjectOfType <KSceneManager>();

            return(ks);
        }