Exemple #1
0
        UIAtlas _getAtlasByName(string atlasName)
        {
            try
            {
                string tmpPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a("upgradeRes").
                                 a("/priority/atlas/").a(CLPathCfg.self.platform).a("/").a(atlasName).a(".unity3d").end();
#if UNITY_EDITOR
                if (CLCfgBase.self.isEditMode)
                {
                    tmpPath = tmpPath.Replace("/upgradeRes/", "/upgradeRes4Publish/");
                }
#endif

                AssetBundle atlasBundel = AssetBundle.LoadFromMemory(FileEx.readNewAllBytes(tmpPath));
                if (atlasBundel != null)
                {
                    GameObject go = atlasBundel.mainAsset as GameObject;
                    atlasBundel.Unload(false);
                    atlasBundel = null;
                    if (go != null)
                    {
                        UIAtlas atlas = go.GetComponent <UIAtlas>();
                        atlasMap[atlasName] = atlas;
                        return(atlas);
                    }
                }
                return(null);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e + "===" + atlasName);
                return(null);
            }
        }
Exemple #2
0
 UIFont _getFontByName(string fontName)
 {
     try {
         string tmpPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a("upgradeRes").
                          a("/priority/font/").a(CLPathCfg.self.platform).a("/").a(fontName).a(".unity3d").end();
                         #if UNITY_EDITOR
         if (CLCfgBase.self.isEditMode)
         {
             tmpPath = tmpPath.Replace("/upgradeRes/", "/upgradeRes4Publish/");
         }
                         #endif
         AssetBundle atlasBundel = AssetBundle.LoadFromMemory(FileEx.readNewAllBytes(tmpPath));
         if (atlasBundel != null)
         {
             GameObject go = atlasBundel.mainAsset as GameObject;
             atlasBundel.Unload(false);
             atlasBundel = null;
             if (go != null)
             {
                 UIFont font = go.GetComponent <UIFont> ();
                 fontMap [fontName] = font;
                 if (!string.IsNullOrEmpty(font.atlasName))
                 {
                     font.atlas = getAtlasByName(font.atlasName);
                 }
                 return(font);
             }
         }
         return(null);
     } catch (System.Exception e) {
         Debug.LogError(e);
         return(null);
     }
 }
Exemple #3
0
        /// <summary>
        /// Reads the new all text. 同步步读取。优先从persistentDataPath目录取得,再从streamingAssetsPath读书
        /// </summary>
        /// <returns>The new all text.</returns>
        /// <param name="fName">F name.</param>
        public static byte[] readNewAllBytes(string fName)
        {
            try {
                byte[] buff = null;

#if UNITY_WEBGL
                if (!CLCfgBase.self.isEditMode)
                {
                    return(CLPreLoadRes4Webgl.getContent(fName));
                }
#endif
                string fPath = CLPathCfg.persistentDataPath + "/" + fName;
                if (File.Exists(fPath))
                {
                    buff = FileEx.ReadAllBytes(fPath);
                }
                else
                {
                    fPath = Application.streamingAssetsPath + "/" + fName;
                    buff  = FileEx.ReadAllBytes(fPath);
                }
                                #if UNITY_EDITOR
                if (buff == null)
                {
                    Debug.LogError("Get null content == " + fPath);
                }
                                #endif
                return(buff);
            } catch (Exception e) {
                Debug.LogError(e);
                return(null);
            }
        }
Exemple #4
0
        public virtual void setLanguage(string language)
        {
            string languageFile = PStr.b(
                CLPathCfg.self.localizationPath,
                language, ".txt").e();

            byte[] buff = null;
#if UNITY_EDITOR
            if (CLCfgBase.self.isEditMode)
            {
                languageFile = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(languageFile).e();
                languageFile = languageFile.Replace("/upgradeRes/", "/upgradeRes4Dev/");
                buff         = File.ReadAllBytes(languageFile);
            }
            else
            {
#if UNITY_WEBGL
                languageFile = languageFile.Replace(".txt", "");
#endif
                buff = FileEx.readNewAllBytes(languageFile);
            }
#else
    #if UNITY_WEBGL
            languageFile = languageFile.Replace(".txt", "");
    #endif
            buff = FileEx.readNewAllBytes(languageFile);
#endif
            Localization.Load(language, buff);
        }
Exemple #5
0
 /// <summary>
 /// Reads the new all text. 同步步读取。优先从persistentDataPath目录取得,再从streamingAssetsPath读书
 /// </summary>
 /// <returns>The new all text.</returns>
 /// <param name="fName">F name.</param>
 public static byte[] readNewAllBytes(string fName)
 {
     try {
         byte[] buff  = null;
         string fPath = CLPathCfg.persistentDataPath + "/" + fName;
         if (File.Exists(fPath))
         {
             buff = FileEx.ReadAllBytes(fPath);
         }
         else
         {
             fPath = Application.streamingAssetsPath + "/" + fName;
             buff  = FileEx.ReadAllBytes(fPath);
         }
                         #if UNITY_EDITOR
         if (buff == null)
         {
             Debug.LogError("Get null content == " + fPath);
         }
                         #endif
         return(buff);
     } catch (Exception e) {
         Debug.LogError(e);
         return(null);
     }
 }
Exemple #6
0
        public bool init()
        {
            clean();
#if !UNITY_EDITOR && !UNITY_WEBGL
            //取得最新的语言
            Callback cb = onGetLocalize;
            StartCoroutine(FileEx.readNewAllBytesAsyn(
                               PStr.b(CLPathCfg.self.localizationPath).a(Localization.language).a(".txt").e(),
                               cb));
#endif

            return(initAtlas());
        }
Exemple #7
0
        /// <summary>
        /// Inits the streaming assets packge.
        /// 将流目录中优先需要加载的资源集解压到可读写目录
        /// </summary>
        /// <param name="onFinisInitStreaming">On finis init streaming.</param>
        public void initStreamingAssetsPackge(Callback onFinisInitStreaming)
        {
            this.onFinisInitStreaming = onFinisInitStreaming;
            // clean cache
#if UNITY_EDITOR
            if (CLCfgBase.self.isEditMode)
            {
                onFinisInitStreaming();
                return;
            }
#endif
            try
            {
                // 当版本不同时, clean cache
                if (string.Compare(Application.version, clientVersion) != 0)
                {
                    string path = Application.persistentDataPath;
                    // 先删掉目录下的文件
                    string[] fEntries = Directory.GetFiles(path);
                    foreach (string f in fEntries)
                    {
                        File.Delete(f);
                    }
                    // 再删掉所有文件夹
                    string[] dirEntries = Directory.GetDirectories(path);
                    foreach (string dir in dirEntries)
                    {
                        Directory.Delete(dir, true);
                    }
                    clientVersion = Application.version;
                }

                // 处理资源释放
                if (!File.Exists(hadPoc))
                {
                    string   path = "priority.r";
                    Callback cb   = onGetStreamingAssets;
                    StartCoroutine(FileEx.readNewAllBytesAsyn(path, cb));
                }
                else
                {
                    onFinisInitStreaming();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
                onFinisInitStreaming();
            }
        }
Exemple #8
0
 public static byte[] getBytesFromCache(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         return(null);
     }
     byte[] ret = MapEx.getBytes(FileBytesMap, path);
     if (ret == null)
     {
         ret = FileEx.ReadAllBytes(path);
         FileBytesMap [path] = ret;
     }
     return(ret);
 }
Exemple #9
0
        public static string getTextFromCache(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            string ret = MapEx.getString(FileTextMap, path);

            if (string.IsNullOrEmpty(ret))
            {
                ret = FileEx.ReadAllText(path);
                FileTextMap [path] = ret;
            }
            return(ret);
        }
Exemple #10
0
 public static byte[] ReadAllBytes(string fn)
 {
     try {
         if (fn.StartsWith("jar:file:"))
         {
             return(FileEx.readBytesFromStreamingAssetsPath(fn));
         }
         else
         {
             return(File.ReadAllBytes(fn));
         }
     } catch (Exception e) {
         Debug.Log(e.Message);
     }
     return(null);
 }
Exemple #11
0
        public static string ReadAllText(string fn)
        {
            try {
                if (fn.StartsWith("jar:file:"))
                {
                    return(FileEx.readTextFromStreamingAssetsPath(fn));
                }
                else
                {
                    if (!FileEx.FileExists(fn))
                    {
                        return(null);
                    }
                    return(File.ReadAllText(fn));
                }
            } catch (Exception e) {
                Debug.Log(e.Message);
            }

            return("");
        }
Exemple #12
0
        public static Hashtable readMaterialTexRefCfg()
        {
            Hashtable ret = null;

#if UNITY_EDITOR
            byte[] buffer = File.Exists(materialTexRefCfgPath) ? File.ReadAllBytes(materialTexRefCfgPath) : null;
#else
            byte[] buffer = FileEx.readNewAllBytes(materialTexRefCfgPath);
#endif
            if (buffer != null)
            {
                MemoryStream ms = new MemoryStream();
                ms.Write(buffer, 0, buffer.Length);
                ms.Position = 0;
                object obj = B2InputStream.readObject(ms);
                if (obj != null)
                {
                    ret = obj as Hashtable;
                }
            }
            ret = ret == null ? new Hashtable() : ret;
            return(ret);
        }
Exemple #13
0
 public virtual void doRestart()
 {
     CLPanelManager.destoryAllPanel();
     FileEx.cleanCache();
     CLUtlLua.cleanFileBytesCacheMap();
     //CLUtlLua.isFinishAddLoader = false;
     CLUIInit.self.clean();
     //重新把配置清空
     CLMaterialPool.materialTexRefCfg = null;
     if (mainLua != null)
     {
         destoryLua();
         //				mainLua.Dispose ();
         //				mainLua = null;
         resetMainLua();
     }
     else
     {
         resetMainLua();
     }
     luaTable = null;
     lua      = null;
     Start();
 }
Exemple #14
0
        public static byte[] myLuaLoader(ref string filepath)
        {
            byte[] bytes   = null;
            string luaPath = "";
            string strs    = "";

            try {
                if (!filepath.StartsWith(CLPathCfg.self.basePath))
                {
                    //说明是通过require进来的
                    filepath = filepath.Replace(".", "/");
                    filepath = PStr.b().a(CLPathCfg.self.basePath).a("/upgradeRes/priority/lua/").a(filepath).a(".lua").e();
                }
                                #if UNITY_EDITOR
                if (CLCfgBase.self.isEditMode)
                {
                    filepath = filepath.Replace("/upgradeRes/", "/upgradeRes4Dev/");
                    luaPath  = PStr.b().a(Application.dataPath).a("/").a(filepath).e();
                    bytes    = MapEx.getBytes(FileBytesCacheMap, luaPath);
                    if (bytes != null)
                    {
                        filepath = luaPath;
                        return(bytes);
                    }
                    if (File.Exists(luaPath))
                    {
                        strs     = FileEx.getTextFromCache(luaPath);
                        bytes    = System.Text.Encoding.UTF8.GetBytes(strs);
                        filepath = luaPath;
                        return(bytes);
                    }
                }
                                #endif

                //=======================================================
                //1.first  load from CLPathCfg.persistentDataPath;
                luaPath = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(filepath).e();
                bytes   = MapEx.getBytes(FileBytesCacheMap, luaPath);
                if (bytes != null)
                {
                    filepath = luaPath;
                    return(bytes);
                }
                if (File.Exists(luaPath))
                {
                    bytes = FileEx.getBytesFromCache(luaPath);
                    if (bytes != null)
                    {
//					bytes = System.Text.Encoding.UTF8.GetBytes(strs);
                        bytes = deCodeLua(bytes);
                        FileBytesCacheMap [luaPath] = bytes;
                        filepath = luaPath;
                        return(bytes);
                    }
                }
                //=======================================================
                //2.second load from  Application.streamingAssetsPath;
                luaPath = PStr.b().a(Application.streamingAssetsPath).a("/").a(filepath).e();
                bytes   = MapEx.getBytes(FileBytesCacheMap, luaPath);
                if (bytes != null)
                {
                    filepath = luaPath;
                    return(bytes);
                }

                bytes = FileEx.getBytesFromCache(luaPath);
                if (bytes != null)
                {
//				bytes = System.Text.Encoding.UTF8.GetBytes(strs);
                    bytes = deCodeLua(bytes);
                    FileBytesCacheMap [luaPath] = bytes;
                    filepath = luaPath;
                    return(bytes);
                }
                //=======================================================
                //3.third load from Resources.Load ();
                luaPath = filepath;
                bytes   = MapEx.getBytes(FileBytesCacheMap, luaPath);
                if (bytes != null)
                {
                    filepath = luaPath;
                    return(bytes);
                }

                TextAsset text = Resources.Load <TextAsset> (filepath);
                if (text != null)
                {
                    bytes = text.bytes;                    // System.Text.Encoding.UTF8.GetBytes(text.text);
                    if (bytes != null)
                    {
                        bytes = deCodeLua(bytes);
                        FileBytesCacheMap [luaPath] = bytes;
                        filepath = luaPath;
                        return(bytes);
                    }
                }
                //==========================
                return(bytes);
            } catch (System.Exception e) {
                Debug.LogError(luaPath + ":" + e);
                return(null);
            }
        }