예제 #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);
         }
     }
 private void AddUrl()
 {
     //CBUrl.Items.Add("http://www.hao123.com");
     //CBUrl.Items.Add("http://www.sina.com");
     //CBUrl.Items.Add("http://www.heuet.edu.cn");
     mFileFullPath = StreamAssetHelper.AssetsPath(StreamAssetRoot.HTML_ROOT, 页面地址);
 }
예제 #3
0
        IEnumerator DoLoadAtlas(UIAtlas atlas, int aid, string atlasResName)
        {
            while (mUIAtlasLoading)
            {
                yield return(new WaitForFixedUpdate());
            }
            mUIAtlasLoading = true;
            if (null == atlas.texture)
            {
                WWW ui = StreamAssetHelper.LoadAsset(StreamAssetRoot.UIATLASTEX_ROOT, atlasResName + ".tex", 1);
                ui.threadPriority = ThreadPriority.High;
                yield return(ui);

                AssetBundle ab = ui.assetBundle;
                if (null == atlas.texture)
                {
                    if (!string.IsNullOrEmpty(ui.error))
                    {
                        PopupDialogView.PopupAB(PopupDialogType.Confirm, SharedResources.Inst.UIPopup, "错误", ui.error);
                        Debug.LogError(ui.error);
                    }
                    else
                    {
                        if (null == ab)
                        {
                            string error = "图包:" + atlas.name + "[" + atlasResName + "]的assetBundle为空!";
                            PopupDialogView.PopupAB(PopupDialogType.Confirm, SharedResources.Inst.UIPopup, "错误", error);
                            Debug.LogError(error);
                        }
                        else
                        {
                            //float sTime = Time.realtimeSinceStartup;
                            atlas.spriteMaterial.mainTexture = ab.mainAsset as Texture2D;
                            ab.Unload(false);
                            //LogSys.Debug("~~~inst atlas[" + atlasObj.name + "]used:" + (Time.realtimeSinceStartup - sTime).ToString());
                            //mAtlasRefCounts.Add(atlas.name, 0);
                            LogSys.Debug("成功载入图包:" + atlas.name);
                        }
                    }
                }
                else if (null != ab)
                {
                    ab.Unload(false);
                }
                ui.Dispose();
            }
            if (!mAtlasRefCounts.ContainsKey(aid))
            {
                mAtlasRefCounts.Add(aid, 0);
            }
            mUIAtlasLoading = false;
        }
예제 #4
0
        //IEnumerator DoLoadFont(UIHlp.动态字体类型 t, Object lbl)
        //{
        //    string fontName = t.ToString();
        //    if (!mFontList.ContainsKey(fontName))
        //    {
        //        string fontResName = LogicModel.GetResName(ResourceType.Font, fontName);
        //        if (string.IsNullOrEmpty(fontResName))
        //            Debug.LogError("找不到字体[" + t.ToString() + "]对应的资源!");
        //        else
        //            yield return StartCoroutine(DoLoadFont(fontName, fontResName));
        //    }
        //    if (null != lbl)
        //    {
        //        //lblEx.OnFontLoaded(fontName, mFontList[fontName]);
        //    }
        //}
        IEnumerator DoLoadTexture(string path)
        {
            while (mTextureLoading)
            {
                yield return(new WaitForFixedUpdate());
            }
            mTextureLoading = true;
            if (!mTextureList.ContainsKey(path))
            {
                WWW file = StreamAssetHelper.LoadAsset(StreamAssetRoot.TEXTURE_ROOT, path);
                file.threadPriority = ThreadPriority.High;
                yield return(file);

                if (!string.IsNullOrEmpty(file.error))
                {
                    PopupDialogView.PopupAB(PopupDialogType.Confirm, SharedResources.Inst.UIPopup, "错误", file.error);
                    Debug.LogError(file.error);
                }
                else
                {
                    AssetBundle ab  = file.assetBundle;
                    Texture2D   tex = file.texture;
                    if (null == tex)
                    {
                        string error = "贴图" + path + "的texture为空!";
                        PopupDialogView.PopupAB(PopupDialogType.Confirm, SharedResources.Inst.UIPopup, "错误", error);
                        Debug.LogError(error);
                    }
                    else
                    {
                        mTextureList.Add(path, new TwoData <Texture, int>(tex, 0));
                        if (null != ab)
                        {
                            ab.Unload(false);
                        }
                        LogSys.Debug("成功载入贴图:" + path);
                    }
                }
                file.Dispose();
            }
            mTextureLoading = false;
        }
예제 #5
0
        IEnumerator DoLoadUIPacket()
        {
            WWW ui = StreamAssetHelper.LoadAsset("UIView.nui");

            yield return(ui);

            if (!string.IsNullOrEmpty(ui.error))
            {
                Debug.LogError(ui.error);
            }
            else
            {
                AssetBundle assetBundle = ui.assetBundle;
                if (null == assetBundle)
                {
                    string error = "UI集UIView.nui的assetBundle为空!";
                    Debug.LogError(error);
                }
                else
                {
                    Object[] objs = assetBundle.LoadAllAssets(typeof(GameObject));
                    mUIList = new Dictionary <string, GameObject>();
                    for (int i = 0; i < objs.Length; ++i)
                    {
                        mUIList.Add(objs[i].name, objs[i] as GameObject);
                    }
                    assetBundle.Unload(false);
                    mTempFontBundle.Unload(false);
                    mTempAtlasBundle.Unload(false);
                    assetBundle = mTempFontBundle = mTempAtlasBundle = null;
                    for (int i = 0; i < mGlobalAtlasTexName.Count; ++i)
                    {
                        yield return(StartCoroutine(DoLoadAtlas(mGlobalAtlasTexName[i])));
                    }
                    LogSys.Debug("成功载入UI集UIView.nui");
                }
            }
            ui.Dispose();
            ui = null;
            Resources.UnloadUnusedAssets();
        }
예제 #6
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);
        }
예제 #7
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, 内容锚定方向);
            }
        }
예제 #8
0
        //IEnumerator DoLoadFont(string fontName, string fontResName)
        //{
        //    WWW ui = StreamAssetHelper.LoadAsset(StreamAssetRoot.FONT_ROOT, fontResName + ".font");
        //    yield return ui;
        //    if (!string.IsNullOrEmpty(ui.error))
        //    {
        //        PopupDialogView.PopupAB(PopupDialogType.错误提示, SharedResources.Inst.UIPopup, ui.error);
        //        Debug.LogError(ui.error);
        //    }
        //    else
        //    {
        //        mTempFontBundle = ui.assetBundle;
        //        if (null == mTempFontBundle)
        //        {
        //            string error = "字体" + fontResName + "的assetBundle为空!";
        //            PopupDialogView.PopupAB(PopupDialogType.错误提示, SharedResources.Inst.UIPopup, error);
        //            Debug.LogError(error);
        //        }
        //        else
        //        {
        //            // font
        //            Object[] ftObjs = mTempFontBundle.LoadAllAssets(typeof(GameObject));
        //            for (int i = 0; i < ftObjs.Length; ++i)
        //            {
        //                GameObject ftObj = ftObjs[i] as GameObject;
        //                ftObj.name = ftObjs[i].name;
        //                ftObj.transform.parent = transform;
        //                UIFont uifont = ftObj.GetComponent<UIFont>();
        //                if (null != uifont)
        //                    mFontList.Add(ftObj.name, uifont);
        //            }
        //            Object[] shaderObjs = mTempFontBundle.LoadAllAssets(typeof(Shader));
        //            for (int i = 0; i < shaderObjs.Length; ++i)
        //            {
        //                Shader sh = Instantiate(shaderObjs[i]) as Shader;
        //                mShaderPool.Add(sh.name, sh);
        //            }
        //            mFontPacketLoaded = true;
        //            LogSys.Debug("成功载入字体:" + fontResName);
        //        }
        //    }
        //    ui.Dispose();
        //    ui = null;
        //}
        IEnumerator DoLoadAtlasPacket()
        {
            WWW ui = StreamAssetHelper.LoadAsset("UIAtlas.ats");

            yield return(ui);

            if (!string.IsNullOrEmpty(ui.error))
            {
                Debug.LogError(ui.error);
            }
            else
            {
                mTempAtlasBundle = ui.assetBundle;
                if (null == mTempAtlasBundle)
                {
                    string error = "图包集UIAtlas.ats的assetBundle为空!";
                    Debug.LogError(error);
                }
                else
                {
                    mAtlasList = new Dictionary <int, ThreeData <UIAtlas, string, Vector2> >();
                    Dictionary <string, Vector2> texSizeList = new Dictionary <string, Vector2>();
                    Object[] texSizeObjList = mTempAtlasBundle.LoadAllAssets(typeof(TextAsset));
                    for (int i = 0; i < texSizeObjList.Length; ++i)
                    {
                        TextAsset tex = texSizeObjList[i] as TextAsset;
                        if (string.IsNullOrEmpty(tex.text))
                        {
                            continue;
                        }
                        string[] ss    = tex.text.Split(":".ToCharArray());
                        int      sizeX = int.Parse(ss[0]);
                        int      sizeY = int.Parse(ss[1]);
                        texSizeList.Add(tex.name, new Vector2(sizeX, sizeY));
                    }

                    /*
                     * Object[] atlasObjList = mTempAtlasBundle.LoadAllAssets(typeof(GameObject));
                     * Dictionary<string, string> finder = LogicModel.GetResFinder(ResourceType.UIAtlas);
                     * for (int i = 0; i < atlasObjList.Length; ++i)
                     * {
                     * GameObject srcObj = atlasObjList[i] as GameObject;
                     * if (null == srcObj || !finder.ContainsKey(srcObj.name))
                     * {
                     * Debug.LogWarning("不被使用的UI图包:" + srcObj.name);
                     * continue;
                     * }
                     * UIAtlas atlas = srcObj.GetComponent<UIAtlas>();
                     * if(System.Enum.IsDefined(typeof(UIAtlasType), atlas.name))
                     * {
                     * UIAtlasType at = (UIAtlasType)System.Enum.Parse(typeof(UIAtlasType), atlas.name);
                     * int aid = (int)at;
                     * atlas.spriteMaterial = new Material(Shader.Find("Unlit/Transparent Colored"));
                     * mAtlasList.Add(aid, new ThreeData<UIAtlas, string, Vector2>(atlas, finder[atlas.name], texSizeList[atlas.name]));
                     * if (at == UIAtlasType.物品图标图包1)
                     * {
                     * // 缓存物品图标索引
                     * List<UISpriteData> list = atlas.spriteList;
                     * for (int ii = 0, imax = list.Count; ii < imax; ++ii)
                     * {
                     * int key = SharedAtlasMapper.GenItemIconAtlasKey(list[ii].name);
                     * atlas.AddIndexMapper(key, ii);
                     * }
                     * }
                     * if (at == UIAtlasType.UI_主界面通用)
                     * {
                     * // 缓存主界面图标索引
                     * List<UISpriteData> list = atlas.spriteList;
                     * for (int ii = 0, imax = list.Count; ii < imax; ++ii)
                     * {
                     * int key = SharedAtlasMapper.GenCommonMainKey(list[ii].name);
                     * atlas.AddIndexMapper(key, ii);
                     * }
                     * }
                     * }
                     * }
                     * texSizeList.Clear();
                     * for (int i = 0; i < texSizeObjList.Length; ++i)
                     * {
                     * Resources.UnloadAsset(texSizeObjList[i]);
                     * //DestroyImmediate(texSizeObjList[i]);
                     * texSizeObjList[i] = null;
                     * }
                     * texSizeObjList = null;
                     * mAtlasPacketLoaded = true;
                     * LogSys.Debug("成功载入图包集UIAtlas.ats");
                     */
                }
            }
            ui.Dispose();
        }