Example #1
0
     public static bool Readable(string filename)
     {
 #if UNITY_ANDROID && !UNITY_EDITOR
         try
         {
             using (WWW file = StreamAssetHelper.LoadAsset(StreamAssetRoot.LUA_ROOT, filename))
                 using (MemoryStream stream = new MemoryStream(file.bytes))
                 {
                     return(true);
                 }
         }
 #else
         try
         {
             using (Stream stream = StreamAssetHelper.LoadFile(StreamAssetRoot.LUA_ROOT, filename))
             {
                 return(true);
             }
         }
 #endif
         catch (Exception)
         {
             return(false);
         }
     }
Example #2
0
        public static FileLoadInfo OpenFile(string filename)
        {
            FileLoadInfo ret = null;

    #if UNITY_ANDROID && !UNITY_EDITOR
            WWW file = StreamAssetHelper.LoadAsset(StreamAssetRoot.LUA_ROOT, filename);
            while (!file.isDone && (file.progress < 0.9f))
            {
                Thread.Sleep(100);
            }
            if (file.bytes != null)
            {
                MemoryStream stream = new MemoryStream(file.bytes);
                ret = new FileLoadInfo(stream);
            }
    #else
            Stream stream = StreamAssetHelper.LoadFile(StreamAssetRoot.LUA_ROOT, filename);
            ret = new FileLoadInfo(stream);
    #endif
            return(ret);
        }
Example #3
0
        void Parse(string text)
        {
            if (mParsing)
            {
                return;
            }
            if (!FirstRunning)
            {
                mCacheTrans.localPosition = mLastViewPos;
            }
            else
            {
                mLastViewPos = mCacheTrans.localPosition;
            }
            if (地址.Length > 0 || text.Length > 0)
            {
                mParsing = true;
                HtmlParse reader = new HtmlParse();
                reader.OnReadTagBegin += OnHandleTagBegin;
                reader.OnReadTagEnd   += OnHandleTagEnd;
                reader.OnReadText     += OnCreateText;
                if (地址.Length > 0)
                {
                    byte[] buffer = null;
#if UNITY_ANDROID && !UNITY_EDITOR
                    WWW file = StreamAssetHelper.LoadAsset(StreamAssetRoot.HTML_ROOT, 地址);
                    while (!file.isDone && (file.progress < 0.9f))
                    {
                        Thread.Sleep(100);
                    }
                    if (file.bytes != null)
                    {
                        buffer = file.bytes;
                        内容     = PlatformTools.BS2String_UTF8(buffer);
                    }
                    AssetBundle bdl = file.assetBundle;
                    if (null != bdl)
                    {
                        bdl.Unload(true);
                    }
                    file.Dispose();
                    file = null;
#else
                    Stream stream = StreamAssetHelper.LoadFile(StreamAssetRoot.HTML_ROOT, 地址);
                    buffer = new byte[stream.Length];
                    int len = stream.Read(buffer, 0, (int)stream.Length);
                    if (len != (int)stream.Length)
                    {
                        Debug.LogError("读取页面地址[" + 地址 + "]失败,读取的长度["
                                       + len.ToString() + "]与文件长度[" + stream.Length + "]不匹配!");
                        return;
                    }
                    内容 = PlatformTools.BS2String_UTF8(buffer);
#endif
                }
                else
                {
                    内容 = text;
                }
                StrTreeNode treeNode = null;
                if (内容.Length > 0)
                {
                    reader.DoParseString(内容, out treeNode);
                }
                重新计算边界 = true;
                ClearParam();
                if (null != OnContextChanged)
                {
                    OnContextChanged();
                }
                GetBounds();
                mParsing = false;
                ReposNowLine();
                mNowLineUnits.Clear();
            }
            OnParseOvered();
            if (null != OnContextParseOvered)
            {
                OnContextParseOvered(Bounds, 内容锚定方向);
            }
        }