예제 #1
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);
            }
        }
예제 #2
0
        /// <summary>
        /// Reads the new all text. 异步读取。优先从persistentDataPath目录取得,再从streamingAssetsPath读书
        /// </summary>
        /// <returns>The new all text.</returns>
        /// <param name="fName">F name.</param>
        public static IEnumerator readNewAllTextAsyn(string fName, object OnGet)
        {
            string buff = "";

#if UNITY_WEBGL
            if (!CLCfgBase.self.isEditMode)
            {
                byte[] bytes = CLPreLoadRes4Webgl.getContent(fName);
                if (bytes != null)
                {
                    buff = Encoding.UTF8.GetString(bytes);
                }
            }
            else
            {
                buff = readNewAllText(fName);
            }
            yield return(null);
#else
            string fPath = CLPathCfg.persistentDataPath + "/" + fName;
            if (File.Exists(fPath))
            {
                yield return(null);

                buff = File.ReadAllText(fPath);
            }
            else
            {
                fPath = Application.streamingAssetsPath + "/" + fName;
                if (Application.platform == RuntimePlatform.Android)
                {
                    WWW www = new WWW(Utl.urlAddTimes(fPath));
                    yield return(www);

                    buff = www.text;
                    www.Dispose();
                    www = null;
                }
                else
                {
                    yield return(null);

                    if (File.Exists(fPath))
                    {
                        buff = File.ReadAllText(fPath);
                    }
                }
            }
#if UNITY_EDITOR
            if (buff == null)
            {
                Debug.LogError("Get null content == " + fPath);
            }
#endif
#endif
            Utl.doCallback(OnGet, buff);
        }
예제 #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 string readNewAllText(string fName)
        {
            try {
                string buff = "";
#if UNITY_WEBGL
                if (!CLCfgBase.self.isEditMode)
                {
                    byte[] bytes = CLPreLoadRes4Webgl.getContent(fName);
                    if (bytes != null)
                    {
                        buff = Encoding.UTF8.GetString(bytes);
                    }
                    return(buff);
                }
#endif
                string fPath = CLPathCfg.persistentDataPath + "/" + fName;
                if (File.Exists(fPath))
                {
                    buff = File.ReadAllText(fPath);
                }
                else
                {
                    fPath = Application.streamingAssetsPath + "/" + fName;
                    buff  = ReadAllText(fPath);
                }
                                #if UNITY_EDITOR
                if (buff == null)
                {
                    Debug.LogError("Get null content == " + fPath);
                }
                                #endif
                return(buff);
            } catch (Exception e) {
                Debug.LogError(e);
                return("");
            }
        }
예제 #4
0
 public virtual void preLoadRes4Webgl(object callback)
 {
     CLPreLoadRes4Webgl.init(null, callback, true, null);
 }