示例#1
0
    private static void LoadSceneConfig()
    {
        string patch           = FullAssetPackagePathRoot + SceneConfigPatch;
        string stSchemeAllText = DeCodeAssetFile(patch);

        if (stSchemeAllText.Equals(string.Empty))
        {
            Debug.LogError("加载场景配置失败!");
            return;
        }

        //去掉\n,因为ScpReader以"\r"分割
        stSchemeAllText = stSchemeAllText.Replace("\n", "");
        //再干掉最后的"\r"
        stSchemeAllText = stSchemeAllText.Remove(stSchemeAllText.Length - 1, 1);
        AssetBundleConfigReader SceneConfigReader = new AssetBundleConfigReader(stSchemeAllText, "SceneConfig", 2);

        // 遍歷整個表并存儲起來
        for (int i = 0; i < SceneConfigReader.GetRecordCount(); ++i)
        {
            ResConfigData cof = new ResConfigData();
            cof.AssetName       = SceneConfigReader.GetString(i, (int)SceneConfig.COL_SCENE_NAME, "");
            cof.AssetGUID       = SceneConfigReader.GetString(i, (int)SceneConfig.COL_GUID, "");
            cof.AssetBundleName = SceneConfigReader.GetString(i, (int)SceneConfig.COL_ASSETBUNDLENAME, "");
            SceneConfigTable.Add(cof.AssetName, cof);
        }

        SceneConfigReader.Dispose();
        SceneConfigReader = null;
    }
示例#2
0
    static void LoadCSVConfig()
    {
        string patch = AssetBundleManager.GetUICSVConfigPatch();

        if (!File.Exists(patch))
        {
            return;
        }
        m_UIConfigTable.Clear();
        //m_UIPackageTable.Clear();
        string stSchemeAllText = DeCodeAssetFile(patch);

        //去掉\n,因为ScpReader以"\r"分割
        stSchemeAllText = stSchemeAllText.Replace("\n", "");
        //再干掉最后的"\r"
        stSchemeAllText = stSchemeAllText.Remove(stSchemeAllText.Length - 1, 1);
        AssetBundleConfigReader UIReader = new AssetBundleConfigReader(stSchemeAllText, "UIConfig", 2);

        // 遍歷整個表并存儲起來
        for (int i = 0; i < UIReader.GetRecordCount(); ++i)
        {
            ResConfigData data = new ResConfigData();
            //int id = UIReader.GetInt(i, (int)UIConfigCol.COL_ID, -1);
            data.AssetBundleName = UIReader.GetString(i, (int)AssetConfigCol.COL_AssetBundleName, string.Empty);
            data.AssetName       = UIReader.GetString(i, (int)AssetConfigCol.COL_AssetName, string.Empty);
            data.AssetGUID       = UIReader.GetString(i, (int)AssetConfigCol.COL_AssetGUID, string.Empty);
            data.AssetSize_X     = UIReader.GetFloat(i, (int)AssetConfigCol.COL_AssetSize_X, -1.0f);
            data.AssetSize_Y     = UIReader.GetFloat(i, (int)AssetConfigCol.COL_AssetSize_Y, -1.0f);
            if (data.AssetName.Equals(string.Empty))
            {
                Debug.LogError("包名为空!");
                continue;
            }
            ////ID与包名对应表
            //if (!m_UIPackageTable.ContainsKey(id))
            //{
            //    m_UIPackageTable.Add(id, data.AssetBundleName);
            //}

            //包名已经存在了
            if (m_UIConfigTable.ContainsKey(data.AssetBundleName))
            {
                Dictionary <string, ResConfigData> ta = m_UIConfigTable[data.AssetBundleName];
                if (ta.ContainsKey(data.AssetName))
                {
                    Debug.LogError("重复的资源名:" + data.AssetName + ",包:" + data.AssetBundleName);
                    continue;
                }
                ta.Add(data.AssetName, data);
            }
            else
            {
                Dictionary <string, ResConfigData> ta = new Dictionary <string, ResConfigData>();
                ta.Add(data.AssetName, data);
                m_UIConfigTable.Add(data.AssetBundleName, ta);
            }
        }
        UIReader.Dispose();
        UIReader = null;
    }
示例#3
0
    private static void LoadDependenciesResConfig(Dictionary <string, ResConfigData> Result = null)
    {
        string patch = AssetBundleManager.GetDependenicesResConfigPath();

        if (!File.Exists(patch))
        {
            if (Application.isPlaying)
            {
                Debug.LogError("找不到预制体资源表!!!-" + patch);
            }
            return;
        }

        string stSchemeAllText = DeCodeAssetFile(patch);

        if (stSchemeAllText.Equals(string.Empty))
        {
            return;
        }

        if (null == Result)
        {
            Result = m_DependenciesResConfigTable;
        }

        ////去掉\n,因为ScpReader以"\r"分割
        //stSchemeAllText = stSchemeAllText.Replace("\n", "");
        ////再干掉最后的"\r"
        //stSchemeAllText = stSchemeAllText.Remove(stSchemeAllText.Length - 1, 1);
        AssetBundleConfigReader ResReader = new AssetBundleConfigReader(stSchemeAllText, "DependenicesResConfig", 0);

        for (int i = 0; i < ResReader.GetRecordCount(); ++i)
        {
            ResConfigData depconf = new ResConfigData();
            depconf.AssetBundleName = StringHelper.CopyString(ResReader.GetString(i, (int)AssetConfigCol.COL_AssetBundleName, string.Empty));
            depconf.AssetName       = StringHelper.CopyString(ResReader.GetString(i, (int)AssetConfigCol.COL_AssetName, string.Empty));
            depconf.AssetGUID       = StringHelper.CopyString(ResReader.GetString(i, (int)AssetConfigCol.COL_AssetGUID, string.Empty));
            depconf.AssetSize_X     = ResReader.GetFloat(i, (int)AssetConfigCol.COL_AssetSize_X, -1.0f);
            depconf.AssetSize_Y     = ResReader.GetFloat(i, (int)AssetConfigCol.COL_AssetSize_Y, -1.0f);
            if (m_DependenciesResConfigTable.ContainsKey(depconf.AssetGUID))
            {
                Debug.LogWarning(StringHelper.BuildString("依赖资源表有重复的配置:", depconf.AssetGUID, depconf.AssetName, depconf.AssetBundleName));
                continue;
            }
            else
            {
                m_DependenciesResConfigTable.Add(StringHelper.CopyString(depconf.AssetGUID), depconf);
            }
        }

        ResReader.Dispose();
        ResReader = null;
    }
示例#4
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="path"></param>
    /// <param name="ResResult">为空,则加载到自身的表里</param>
    /// <param name="OtherResult">为空,则加载到自身的表里</param>
    public static void LoadPackageList(string path, Dictionary <string, PackageNode> ResResult = null,
                                       Dictionary <string, PackageNode> OtherResult            = null)
    {
        if (!File.Exists(path))
        {
            return;
        }
        string stSchemeAllText = DeCodeAssetFile(path);

        if (stSchemeAllText.Equals(string.Empty))
        {
            return;
        }
        if (null == ResResult)
        {
            ResResult = m_RespackageTable;
        }
        if (null == OtherResult)
        {
            OtherResult = m_OtherpackageTable;
        }

        //去掉\n,因为ScpReader以"\r"分割
        stSchemeAllText = stSchemeAllText.Replace("\n", "");
        //再干掉最后的"\r"
        stSchemeAllText = stSchemeAllText.Remove(stSchemeAllText.Length - 1, 0);
        AssetBundleConfigReader packageReader = new AssetBundleConfigReader(stSchemeAllText, "packageList", 0);

        int currentIndex = 0;

        string lowerArtistCommonPatch = ArtistCommonPatch.ToLower();

        #region Res
        //先读取资源的
        for (int i = currentIndex; i < packageReader.GetRecordCount(); ++i)
        {
            string SplitKey = packageReader.GetString(i, 0, string.Empty);
            if (SplitKey.Contains(SplitCSVKey))
            {
                currentIndex = i + 1;
                break;
            }
            PackageNode data = new PackageNode();
            data.md5 = packageReader.GetString(i, (int)PackageNodeCol.COL_MD5, string.Empty);
            data.assetBundlePatch = packageReader.GetString(i, (int)PackageNodeCol.COL_AB_NAME, string.Empty);
            data.fileSize         = packageReader.GetFloat(i, (int)PackageNodeCol.COL_FILESIZE, 0);
            string fullpath = FullAssetPackagePathRoot + data.assetBundlePatch;
            if (!File.Exists(fullpath))
            {
                continue;
            }
            if (!ResResult.ContainsKey(data.assetBundlePatch))
            {
                ResResult.Add(data.assetBundlePatch, data);
                InsertUnionDependenicesAssetBundle(data.assetBundlePatch);
                if (data.assetBundlePatch.Contains(lowerArtistCommonPatch))
                {
                    ArtistCommonAssetBundleNames.Add(data.assetBundlePatch);
                }
                else if (data.assetBundlePatch.Contains(FontAssetBundlePatch))
                {
                    FontAssetBundleNames.Add(data.assetBundlePatch);
                }

                if (data.assetBundlePatch.EndsWith(UIVariant))
                {
                    m_UIAssetBundleTable.Add(data.assetBundlePatch);
                }

                if (data.assetBundlePatch.EndsWith(ShaderAssetVariant))
                {
                    if (data.assetBundlePatch.Contains(FirstLoadPatchKey))
                    {
                        m_FirstLoadAssetBundlePath.Add(data.assetBundlePatch);
                    }
                    else
                    {
                        m_NormalShaderAssetBundlePath.Add(data.assetBundlePatch);
                    }
                }
            }
            else
            {
                Debug.LogWarning("资源列表里有重复的文件:" + data.assetBundlePatch);
            }
        }
        #endregion

        #region Other

        //先读取资源的
        for (int i = currentIndex; i < packageReader.GetRecordCount(); ++i)
        {
            string SplitKey = packageReader.GetString(i, 0, string.Empty);
            if (SplitKey.Contains(SplitCSVKey))
            {
                currentIndex = i + 1;
                break;
            }
            PackageNode data = new PackageNode();
            data.md5 = packageReader.GetString(i, (int)PackageNodeCol.COL_MD5, string.Empty);
            data.assetBundlePatch = packageReader.GetString(i, (int)PackageNodeCol.COL_AB_NAME, string.Empty);
            data.fileSize         = packageReader.GetFloat(i, (int)PackageNodeCol.COL_FILESIZE, 0);
            if (!OtherResult.ContainsKey(data.assetBundlePatch))
            {
                OtherResult.Add(data.assetBundlePatch, data);
            }
            else
            {
                Debug.LogWarning("资源列表里有重复的文件:" + data.assetBundlePatch);
            }
        }

        #endregion
    }
示例#5
0
    /// <summary>
    /// 加载预制体配置
    /// </summary>
    private static void LoadPrefabSelfConfig(Dictionary <string, Dictionary <string, UnionResConfigData> > result = null,
                                             Dictionary <string, PrefabDependenicesResConfigData> depedenceResult = null)
    {
        string patch = AssetBundleManager.GetPrefabConfigPath();

        if (!File.Exists(patch))
        {
            if (Application.isPlaying)
            {
                Debug.LogError("找不到预制体配置!!!-" + patch);
            }
            return;
        }
        string stSchemeAllText = DeCodeAssetFile(patch);

        if (stSchemeAllText.Equals(string.Empty))
        {
            return;
        }

        if (result == null || depedenceResult == null)
        {
            result          = m_PrefabConfigTable;
            depedenceResult = m_PrefabDependenciesConfigTable;
        }

        ////去掉\n,因为ScpReader以"\r"分割
        //stSchemeAllText = stSchemeAllText.Replace("\n", "");
        ////再干掉最后的"\r"
        //stSchemeAllText = stSchemeAllText.Remove(stSchemeAllText.Length - 1, 1);

        AssetBundleConfigReader PrefabReader = new AssetBundleConfigReader(stSchemeAllText, "PrefabConfig", 0);


        bool isNeedLoadDependenices          = false; //是否需要加载依赖配置
        UnionResConfigData currLoadingPrefab = null;  //当前正在加载的Prefab
        int texcount        = 0;                      //贴图数目
        int fbxcount        = 0;                      //fbx数目
        int clipcount       = 0;                      //clip数目
        int controllercount = 0;                      //animatorcontroller数目
        int shadercount     = 0;                      //shader数目
        int materialcount   = 0;                      //材质球数目

        string lowerPrefabCommonPatch = PrefabCommonPatch.ToLower();

        for (int i = 0; i < PrefabReader.GetRecordCount(); ++i)
        {
            isNeedLoadDependenices = !(texcount == 0 && fbxcount == 0 &&
                                       clipcount == 0 && controllercount == 0 &&
                                       shadercount == 0 && materialcount == 0);
            if (!isNeedLoadDependenices)
            {
                UnionResConfigData prefabConfig = new UnionResConfigData();
                prefabConfig.AssetBundleName = PrefabReader.GetString(i, (int)PrefabConfigCol.COL_AssetBundleName, string.Empty);
                prefabConfig.AssetName       = PrefabReader.GetString(i, (int)PrefabConfigCol.COL_AssetName, string.Empty);
                prefabConfig.AssetGUID       = PrefabReader.GetString(i, (int)PrefabConfigCol.COL_AssetGUID, string.Empty);
                prefabConfig.unionIndx       = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_UnionIndex, -1);
                prefabConfig.startIndex      = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_StartIndex, -1);
                prefabConfig.dataLength      = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_DataLength, -1);


                if (!prefabConfig.AssetBundleName.EndsWith(PrefabVariant))
                {
                    Debug.LogWarning("预制体配置中有冗余的配置:" + prefabConfig.AssetBundleName + ",名字:" + prefabConfig.AssetName + ",重新生成资源可解决此问题 -- not gameobject");
                    continue;
                }

                texcount        = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_TextureCount, 0);
                fbxcount        = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_FBXCount, 0);
                clipcount       = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_ClipCount, 0);
                controllercount = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_ControllerCount, 0);
                shadercount     = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_ShaderCount, 0);
                materialcount   = PrefabReader.GetInt(i, (int)PrefabConfigCol.COL_MaterialCount, 0);

                isNeedLoadDependenices = !(texcount == 0 && fbxcount == 0 &&
                                           clipcount == 0 && controllercount == 0 &&
                                           shadercount == 0 && materialcount == 0);

                if (Application.isPlaying)
                {
                    if (isOnRunTimeMode)
                    {
                        if (prefabConfig.unionIndx < 0 || prefabConfig.startIndex < 0 || prefabConfig.dataLength <= 0)
                        {
                            Debug.LogWarning("无效的预制体配置中有冗余的配置:" + prefabConfig.AssetBundleName + ",名字:" + prefabConfig.AssetName + ",重新生成资源可解决此问题--uniondex < 0");
                            i                     += texcount;
                            i                     += fbxcount;
                            i                     += clipcount;
                            i                     += controllercount;
                            i                     += shadercount;
                            i                     += materialcount;
                            texcount               = 0;
                            fbxcount               = 0;
                            clipcount              = 0;
                            controllercount        = 0;
                            shadercount            = 0;
                            materialcount          = 0;
                            isNeedLoadDependenices = false;
                            currLoadingPrefab      = null;
                            continue;
                        }
                    }
                }

                currLoadingPrefab = prefabConfig;
                int InstanceID = GUIDToInstanceID(prefabConfig.AssetGUID);
                if (m_PrefabGUIDConfigTable.ContainsKey(InstanceID))
                {
                    Debug.LogWarning("重复的预制体配置,GUID:" + prefabConfig.AssetGUID +
                                     "资源名:" + prefabConfig.AssetName);
                    i                     += texcount;
                    i                     += fbxcount;
                    i                     += clipcount;
                    i                     += controllercount;
                    i                     += shadercount;
                    i                     += materialcount;
                    texcount               = 0;
                    fbxcount               = 0;
                    clipcount              = 0;
                    controllercount        = 0;
                    shadercount            = 0;
                    materialcount          = 0;
                    isNeedLoadDependenices = false;
                    currLoadingPrefab      = null;
                    continue;
                }
                else
                {
                    m_PrefabGUIDConfigTable.Add(InstanceID, prefabConfig);
                }

                //把预制体资源先加载进去
                Dictionary <string, UnionResConfigData> assetTable = null;
                if (result.TryGetValue(prefabConfig.AssetBundleName, out assetTable))
                {
                    if (assetTable.ContainsKey(prefabConfig.AssetName))
                    {
                        Debug.LogWarning("预制体:" + prefabConfig.AssetBundleName + "有重复的依赖资源:" + prefabConfig.AssetName);
                        continue;
                    }
                    assetTable.Add(prefabConfig.AssetName, prefabConfig);
                }
                else
                {
                    assetTable = new Dictionary <string, UnionResConfigData>();
                    assetTable.Add(prefabConfig.AssetName, prefabConfig);
                    result.Add(prefabConfig.AssetBundleName, assetTable);

                    //通用预制体
                    if (prefabConfig.AssetBundleName.Contains(lowerPrefabCommonPatch))
                    {
                        PrefabCommonAssetBundleNames.Add(prefabConfig.AssetBundleName);
                    }
                }
                //直接destroy GameObject类型的资源

                //没有依赖的,给一个空配置即可
                if (!isNeedLoadDependenices)
                {
                    depedenceResult.Add(currLoadingPrefab.AssetGUID, new PrefabDependenicesResConfigData());
                }
                continue;
            }

            /*开始加载配置依赖表*/



            //1.先创建类
            PrefabDependenicesResConfigData dependenicesConfig = null;
            if (!depedenceResult.TryGetValue(currLoadingPrefab.AssetGUID, out dependenicesConfig))
            {
                dependenicesConfig = new PrefabDependenicesResConfigData();
                depedenceResult.Add(currLoadingPrefab.AssetGUID, dependenicesConfig);
            }

            //先是贴图
            if (texcount > 0)
            {
                texcount--;
                string guid = StringHelper.CopyString(PrefabReader.GetString(i, 0, string.Empty));
                PushPrefabUnionRes(guid, dependenicesConfig.TextureResConfigDatas);
                continue;
            }

            //再加载FBX
            if (fbxcount > 0)
            {
                fbxcount--;
                string guid = StringHelper.CopyString(PrefabReader.GetString(i, 0, string.Empty));
                PushPrefabUnionRes(guid, dependenicesConfig.FBXResConfigDatas);
                continue;
            }

            //再加载clip
            if (clipcount > 0)
            {
                clipcount--;
                string guid = StringHelper.CopyString(PrefabReader.GetString(i, 0, string.Empty));
                PushPrefabUnionRes(guid, dependenicesConfig.AnimatonClipResConfigDatas);

                continue;
            }

            //再加载controller
            if (controllercount > 0)
            {
                controllercount--;
                string guid = StringHelper.CopyString(PrefabReader.GetString(i, 0, string.Empty));
                PushPrefabUnionRes(guid, dependenicesConfig.AnimatorControllerResConfigDatas);

                continue;
            }

            //再加载shader
            if (shadercount > 0)
            {
                shadercount--;
                string guid = StringHelper.CopyString(PrefabReader.GetString(i, 0, string.Empty));
                PushPrefabUnionRes(guid, dependenicesConfig.ShaderResConfigDatas);
                continue;
            }

            //再加载material
            if (materialcount > 0)
            {
                materialcount--;
                string guid = StringHelper.CopyString(PrefabReader.GetString(i, 0, string.Empty));

                PushPrefabUnionRes(guid, dependenicesConfig.MaterialResConfigDatas);
                continue;
            }
        }

        PrefabReader.Dispose();
        PrefabReader = null;
    }