Exemplo n.º 1
0
        /// <summary>
        /// 加载UI影射,需要指定UI预制的根目录
        /// </summary>
        public static void LoadUIManifest(string uiRootPath)
        {
            string resIndicator = "Resources/";

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            var files = Directory.GetFiles(uiRootPath, "*.prefab", System.IO.SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                //统一目录分隔符
                string fullpath = files[i].Replace("\\", "/");

                //以Resources.Load方式来加载
                int resIx = fullpath.IndexOf(resIndicator);
                fullpath = fullpath.Substring(resIx + resIndicator.Length);

                var fileInfo = new FileInfo(fullpath);

                string key   = fileInfo.Name.Replace(".prefab", "");
                string value = fullpath.Replace(".prefab", "");

                uiMap.Add(key, value);
                //KLogger.Log("file|i|" + i + "|key|" + key + "|value|" + value);
            }
            sw.Stop();

            KLogger.Log("KUI|加载Map时间|" + sw.ElapsedMilliseconds);
        }
Exemplo n.º 2
0
        public static void LoadByPath(string path, System.Action <AssetBundle> cb)
        {
            //总是先尝试初始化
            Init();

            path = fixedPath(path);
            if (abMap.ContainsKey(path) && null != abMap[path])
            {
                KLogger.Log("使用缓存的AB|" + path);
                cb(abMap[path]);
                return;
            }

            self.StartCoroutine(_loadAB(path, cb));
        }
Exemplo n.º 3
0
        private static void Init()
        {
            //已经初始化则不处理了
            if (null != self)
            {
                return;
            }

            self = GameObject.FindObjectOfType <KAssetBundle>();
            if (self == null)
            {
                KLogger.Log("开始初始化|KAssetBundle");

                GameObject go = new GameObject();
                go.name = "__KAssetBundle__";
                DontDestroyOnLoad(go);                 //场景切换也保留

                self = go.AddComponent <KAssetBundle>();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 这个方法要做成适合Editor与各个平台公用
        /// </summary>
        private static IEnumerator _loadAB(string path, System.Action <AssetBundle> cb)
        {
            path = fixedPath(path);

            WWW www = WWW.LoadFromCacheOrDownload(path, 1);

            yield return(www);

            if (string.IsNullOrEmpty(www.error))
            {
                AssetBundle assetBundle = www.assetBundle;
                abMap.Add(path, assetBundle);

                if (null != cb)
                {
                    cb(assetBundle);
                }
            }
            else
            {
                KLogger.LogError(www.error);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 加载Window
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <example>
        /// var win = KUI.LoadWindow<MainWindow>(null);
        /// </example>
        /// <returns></returns>
        public static T LoadWindow <T>(object data) where T : KUIWindow
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            string uiName = typeof(T).Name;

            if (!uiMap.ContainsKey(uiName))
            {
                KLogger.LogError("KUI|没有找到对应的UI|" + uiName);
                return(default(T));
            }
            string uiPath = uiMap[uiName];

            var swResLoad = new System.Diagnostics.Stopwatch();

            swResLoad.Start();
            var prefab = Resources.Load <T>(uiPath);

            swResLoad.Stop();
            KLogger.LogError("KUI|Resources.Load|时间|" + swResLoad.ElapsedMilliseconds);

            var swInst = new System.Diagnostics.Stopwatch();

            swInst.Start();
            T go = GameObject.Instantiate <T>(prefab);

            swInst.Stop();
            KLogger.LogError("KUI|GameObject.Instantiate|时间|" + swInst.ElapsedMilliseconds);

            sw.Stop();
            KLogger.LogError("KUI|LoadWindow|时间|" + sw.ElapsedMilliseconds);

            return(go);
        }