public void Init()
    {
        AssetParam param = new AssetParam();

        param.listener += OnAssetComplete;

        AssetManager.instance.LoadResource(AssetConfig.CustomMaterialPath, param);
    }
Example #2
0
    IEnumerator DownloadAnimationRes(string prefabName, AnimationData data, LoadAnimationCallback callback, string aniName)
    {
        AssetParam refParam = new AssetParam();

        foreach (string atlas in data.refAtlas)
        {
            if (!mAtlasReferences.ContainsKey(atlas))
            {
                mAtlasReferences.Add(atlas, new AtlasReferenceData());
            }

            //引用计数 +1
            mAtlasReferences[atlas].reference_count += 1;

            if (CheckAtlasComplete(atlas))
            {
                continue;
            }

            AtlasData       atlasData  = mConfig.AtlasDatas[atlas];
            List <AssetPtr> depresList = new List <AssetPtr>();
            ///加载字体依赖的贴图

            AssetParam atlasparam = new AssetParam();

            foreach (string texdep in atlasData.texs)
            {
                yield return(AssetManager.Instance.LoadResource(UI_PATH + "Texture/" + texdep + AssetConfig.AssetSuffix, atlasparam));

                depresList.Add(atlasparam.asset);
            }


            yield return(AssetManager.Instance.LoadResource(UI_PATH + "Atlas/" + atlas + ".ab", refParam));

            if (refParam.asset != null)
            {
                mAtlasReferences[atlas].resources.Add(refParam.asset);

//                 if (!mTempAssetsHolders.ContainsKey(refParam.asset.Data.url))
//                     mTempAssetsHolders.Add(refParam.asset.Data.url, refParam.asset);

                UnityEngine.Object[] objs = refParam.asset.Data.LoadAll();
                CacheUIAtlas(objs);
            }

            foreach (AssetPtr ptr in depresList)
            {
                ptr.Data.UnloadWebStream();
                mAtlasReferences[atlas].resources.Add(ptr);

//                 if (!mTempAssetsHolders.ContainsKey(ptr.Data.url))
//                     mTempAssetsHolders.Add(ptr.Data.url, ptr);
            }
        }
        OnAniLoadComplete(prefabName, callback, aniName);
    }
Example #3
0
    /// <summary>
    /// 加载场景
    /// </summary>
    /// <param name="data"></param>
    private IEnumerator LoadScene_impl(SceneData data, bool additive = false)
    {
        AssetParam param = null;

        //加载依赖资源
        foreach (string depres in data.resources)
        {
            param = new AssetParam();

            yield return(AssetManager.Instance.LoadResource(depres, param));

            if (param.asset != null)
            {
                AssetBundle bundle = param.asset.Data.assetBundle;
                mAssetList.Add(param.asset);
            }
        }


        string scnFile = FantasyEngine.AssetConfig.LevelPath + data.name + FantasyEngine.AssetConfig.AssetSuffix;
        //param = new AssetParam();
        //yield return AssetManager.Instance.LoadResource(scnFile, param);

        //这里临时处理一下先不走AssetManger 现在的内存释放机制还没有做好
        WWW www = new WWW(AssetManager.GetRealPath(scnFile));

        yield return(www);

        AssetBundle    bundled = www.assetBundle;
        AsyncOperation sync    = null;

        if (additive)
        {
            sync = Application.LoadLevelAdditiveAsync(data.name);
        }
        else
        {
            sync = Application.LoadLevelAsync(data.name);
        }

        yield return(sync);

        if (www.assetBundle != null)
        {
            www.assetBundle.Unload(false);
        }
        www.Dispose();

        if (LoadComplete != null)
        {
            LoadComplete();
        }
    }
Example #4
0
    /// <summary>
    /// 播放摄像机器动画
    /// </summary>
    /// <param name="name"></param>
    public void PlayCameraAnimation(string name = null)
    {
        if (FollowAnimator != null && (FollowAnimator.name == name || string.IsNullOrEmpty(name)))
        {
            FollowAnimator.Play();
            return;
        }
        mCurnAnimatorame = name;
        AssetParam param = new AssetParam();

        param.listener = ResourceListener;
        AssetManager.Instance.LoadResource(FantasyEngine.AssetConfig.ScenePath + "animation/" + name + ".xml", param);
    }
Example #5
0
    private void OnLoadComplete(string prefabName, AssetParam param)
    {
        if (!mLoadCallbacks.ContainsKey(prefabName))
        {
            return;
        }
        ArrayList list = mLoadCallbacks[prefabName];

        for (int i = 0; i < list.Count; ++i)
        {
            LoadUICallback callback = list[i] as LoadUICallback;
            if (callback != null)
            {
                GameObject obj = param.asset.Data.Instantiate() as GameObject;
                obj.SetActive(false);
                callback(obj);
            }
        }
        mLoadCallbacks[prefabName].Clear();
        mLoadCallbacks.Remove(prefabName);
    }
Example #6
0
    IEnumerator InitConfigAndFonts()
    {
        AssetParam param = new AssetParam();

        yield return(AssetManager.Instance.LoadResource(UI_CONFIG_FILE, param));

        if (param.asset != null)
        {
            mConfig = JsonMapper.ToObject <UIConfig>(param.asset.Data.text);
            if (!mTempAssetsHolders.ContainsKey(param.asset.Data.url))
            {
                mTempAssetsHolders.Add(param.asset.Data.url, param.asset);
            }
            if (mConfig == null)
            {
                GameDebug.LogError("界面配置信息文件 " + UI_CONFIG_FILE + "读取失败");
            }
        }
        List <AssetPtr> depresList = new List <AssetPtr>();

        ///加载字体依赖的贴图
        foreach (KeyValuePair <string, AtlasData> fontpair in mConfig.AtlasDatas)
        {
            if (fontpair.Value.fontAtlas)
            {
                AssetParam atlasparam = new AssetParam();

                foreach (string texdep in fontpair.Value.texs)
                {
                    yield return(AssetManager.Instance.LoadResource(UI_PATH + "Texture/" + texdep + AssetConfig.AssetSuffix, atlasparam));

                    depresList.Add(atlasparam.asset);
                }
            }
        }


        foreach (string fontres in mConfig.fontRes)
        {
            AssetParam fontresparam = new AssetParam();

            yield return(AssetManager.Instance.LoadResource(UI_PATH + "Texture/" + fontres + AssetConfig.AssetSuffix, fontresparam));

            //depresList.Add(fontresparam.asset);
            mDynamicFonts.Add(fontresparam.asset);
        }

        yield return(AssetManager.Instance.LoadResource(FONTS_ASSET_FILE, param));

        if (param.asset != null)
        {
            if (!mTempAssetsHolders.ContainsKey(param.asset.Data.url))
            {
                mTempAssetsHolders.Add(param.asset.Data.url, param.asset);
            }
            Object[] objs = param.asset.Data.LoadAll();

            //字体里的纹理集 不走界面纹理集的引用销毁机制
            if (objs != null)
            {
                for (int i = 0; i < objs.Length; ++i)
                {
                    Object o = objs[i];
                    if (o is GameObject)
                    {
                        GameObject go   = o as GameObject;
                        UIAtlas    uias = go.GetComponent <UIAtlas>();
                        if (uias == null)
                        {
                            continue;
                        }
                        if (mFontAtlasCaches.ContainsKey(uias.name))
                        {
                            continue;
                        }
                        mFontAtlasCaches.Add(uias.name, uias);
                    }
                }
            }
        }

        foreach (AssetPtr ptr in depresList)
        {
            if (!mTempAssetsHolders.ContainsKey(ptr.Data.url))
            {
                mTempAssetsHolders.Add(ptr.Data.url, ptr);
            }
            ptr.Data.UnloadWebStream();
        }
        depresList.Clear();
        if (mInitCallback != null)
        {
            mInitCallback();
        }
    }
Example #7
0
    IEnumerator DownloadUI(string prefabPath, string prefabName, List <string> refAtlas)
    {
        AssetParam refParam = new AssetParam();


        List <string> wtoa = new List <string>();

        foreach (string atlas in refAtlas)
        {
            if (!mAtlasReferences.ContainsKey(atlas))
            {
                mAtlasReferences.Add(atlas, new AtlasReferenceData());
            }

            //引用计数 +1
            mAtlasReferences[atlas].reference_count += 1;



            wtoa.Add(UI_PATH + "Atlas/" + atlas + ".ab");

            if (CheckAtlasComplete(atlas))
            {
                continue;
            }

            AtlasData       atlasData  = mConfig.AtlasDatas[atlas];
            List <AssetPtr> depresList = new List <AssetPtr>();
            ///加载字体依赖的贴图

            AssetParam atlasparam = new AssetParam();

            foreach (string texdep in atlasData.texs)
            {
                yield return(AssetManager.Instance.LoadResource(UI_PATH + "Texture/" + texdep + AssetConfig.AssetSuffix, atlasparam));

                depresList.Add(atlasparam.asset);
            }

            yield return(AssetManager.Instance.LoadResource(UI_PATH + "Atlas/" + atlas + ".ab", refParam));

            if (refParam.asset != null)
            {
                mAtlasReferences[atlas].resources.Add(refParam.asset);

                UnityEngine.Object[] objs = refParam.asset.Data.LoadAll();
                CacheUIAtlas(objs);
            }

            foreach (AssetPtr ptr in depresList)
            {
                ptr.Data.UnloadWebStream();

                mAtlasReferences[atlas].resources.Add(ptr);
            }
        }

        string downName = UI_PATH + prefabPath + prefabName + ".ab";


        AssetManager.Instance.RecordAssociate(downName, wtoa.ToArray());

        AssetParam param = new AssetParam();

        yield return(AssetManager.Instance.LoadResource(downName, param));

        if (param.asset == null)
        {
            yield break;
        }

        if (!mWindowReferences.ContainsKey(prefabName))
        {
            WindowReferenceData data = new WindowReferenceData();
            data.ptr = param.asset;
            mWindowReferences.Add(prefabName, data);
        }

//         if (!mTempAssetsHolders.ContainsKey(param.asset.Data.url))
//             mTempAssetsHolders.Add(param.asset.Data.url, param.asset);
        param.asset.Data.LoadAll();
        OnLoadComplete(prefabName, param);
    }
Example #8
0
    //------------------------------------------------------------------------------------------
    /// <summary>
    /// 检测资源
    /// </summary>
    //public void CheckResource()
    //{
    //    string path = mLocalDataFolder + "/filelist.config";
    //    if (!File.Exists(path))
    //    {
    //        ///本地目录没有filelist,从服务器下载
    //        BehaviourUtil.StartCoroutine(LoadFileListFromServer());
    //    }
    //    else
    //    {
    //        FileStream stream = new FileStream(path, FileMode.Open);
    //        StreamReader reader = new StreamReader(stream);
    //        try
    //        {
    //            mLocalDataListInfo = JsonMapper.ToObject<Filelist>(reader.ReadToEnd());
    //        }
    //        catch (Exception exception)
    //        {
    //            string str2 = reader.ReadToEnd();
    //            if (str2 == null)
    //            {
    //                GameDebug.Log("reader.ReadToEnd() = null");
    //            }
    //            else
    //            {
    //                GameDebug.Log("reader.ReadToEnd().Len = " + str2.Length);
    //            }
    //            GameDebug.Log(reader.ReadToEnd());
    //            GameDebug.Log(exception.ToString());
    //            reader.Close();
    //            stream.Close();
    //            BehaviourUtil.StartCoroutine(LoadFileListFromServer());
    //            return;
    //        }
    //        reader.Close();
    //        stream.Close();

    //        if (!UpdateTool.CheckAllRes(mLocalDataListInfo))
    //        {
    //            BehaviourUtil.StartCoroutine(LoadFileListFromServer());
    //        }
    //        else
    //        {
    //            UpdateComplete(false);
    //        }
    //    }
    //}


    /// <summary>
    /// 从服务器下载文件列表
    /// </summary>
    /// <returns></returns>
    private IEnumerator LoadFileListFromServer()
    {
        #region 更新miniClient

#if !UNITY_EDITOR && UNITY_ANDROID && False
        //鉴于应用宝平台有增量更新设置,此功能暂时屏蔽
        string appversion = GameConfig.ServerAppURL + GameConfig.AppVersionPath;

        WWW appvWWW = new WWW(appversion);
        yield return(appvWWW);

        if (string.IsNullOrEmpty(appvWWW.error))
        {
            int  serverversion = AppVersion.VersionID;
            bool versionok     = true;

            serverversion = Convert.ToInt32(appvWWW.text);
            AppVersion.ServerAppVersion = serverversion;
            if (versionok)
            {
                if (serverversion != AppVersion.VersionID)
                {
                    //更新客户端
                    string appURL = GameConfig.ServerAppURL + GameConfig.AppPath;
                    UpdateTool.Instance.UpdateClient(appURL);
                    yield break;
                }
            }
        }
#endif
        #endregion

        WWW filelistWWW = null;
        //获取服务器上当前的版本信息
        string sVPath = GameConfig.AssetServerURL + GameConfig.AssetVersion;

        filelistWWW = new WWW(sVPath);
        yield return(filelistWWW);

        if (!string.IsNullOrEmpty(filelistWWW.error))
        {
            UpdateFailed();
            yield break;
        }
        AppVersion.assetVersion = JsonMapper.ToObject <AssetVersion>(filelistWWW.text);

        if (AppVersion.assetVersion == null || string.IsNullOrEmpty(AppVersion.assetVersion.version))
        {
            AppVersion.assetVersion.version = AppSystemInfo.appInfo.versionName;
        }


        string versiondata = GameConfig.GetRealSrvDataPath(AppVersion.assetVersion.version) + GameConfig.DataversionPath;
        filelistWWW = new WWW(versiondata);
        yield return(filelistWWW);

        if (!string.IsNullOrEmpty(filelistWWW.error))
        {
            UpdateFailed();
            yield break;
        }

        //加载本地的config

        mServerRes = JsonMapper.ToObject <ResVersion>(filelistWWW.text);
        AssetParam param = new AssetParam();
        yield return(AssetManager.instance.LoadResource("dataversion.config", param));

        if (param.asset == null || param.asset.Data == null)
        {
            UpdateFailed();
            yield break;
        }

        string     text      = param.asset.Data.text;
        ResVersion localresv = JsonMapper.ToObject <ResVersion>(text);

        if (localresv == null || mServerRes == null)
        {
            UpdateComplete(false);
            NotifyProcess(1, "资源更新失败...");
            yield break;
        }
        //测试:走下面的流程
        if (mServerRes.md5 == localresv.md5)
        {
            UpdateComplete(false);
            yield break;
        }


        NotifyProcess(0, "检查资源更新...");

        //服务器上的filelist
        string filelistpath = string.Format("{0}filelist.config", GameConfig.GetRealSrvDataPath(AppVersion.assetVersion.version));

        filelistWWW = new WWW(filelistpath);
        yield return(filelistWWW);

        if (!string.IsNullOrEmpty(filelistWWW.error))
        {
            //TODO:处理加载失败

            UpdateFailed();
            yield break;
        }

        string configdata = filelistWWW.text;

        if (string.IsNullOrEmpty(configdata))
        {
            //有错误
            UpdateFailed(string.Empty);
            yield break;
        }

        mServerFileListInfo = JsonMapper.ToObject <Filelist>(configdata);

        filelistWWW.Dispose();


        if (mServerFileListInfo != null)
        {
            ParseDownLoadAndUpdateData();
        }
        else
        {
            UpdateFailed(string.Empty);
        }
    }