コード例 #1
0
    static Dictionary <string, ResmapInfo> InitResmap(string resmapName)
    {
        Dictionary <string, ResmapInfo> dic = new Dictionary <string, ResmapInfo>();

        if (!File.Exists(DataDir + resmapName))
        {
            return(dic);
        }
        TableHandler handler = TableHandler.OpenFromData(resmapName);

        for (int row = 0; row < handler.GetRecordsNum(); row++)
        {
            string key = handler.GetValue(row, 0);
            if (dic.ContainsKey(key))
            {
                Debug.LogErrorFormat("{0}中有重名的键,键名{1}", resmapName, key);
                continue;
            }
            ResmapInfo info = new ResmapInfo()
            {
                key        = key,
                editorPath = handler.GetValue(row, 1),
                abName     = handler.GetValue(row, 2),
            };
            dic.Add(key, info);
        }
        return(dic);
    }
コード例 #2
0
    //1:Sprite   2:Prefab    3:obj
    public T LoadAsset <T>(string assetName, int type, string moduleName, bool isTry = false) where T : UnityEngine.Object
    {
        if (string.IsNullOrEmpty(moduleName))
        {
            Debugger.LogError("<ResourceManager> 模块名不能为空,请检查!资源名:" + assetName);
            return(null);
        }
        ResmapInfo info = GetMapInfo(assetName, type, isTry);

        if (info == null)
        {
            return(null);
        }
        if (GameMain.Inst.ResourceMode == 0)
        {
#if UNITY_EDITOR
            return(UnityEditor.AssetDatabase.LoadAssetAtPath <T>(info.editorPath));
#else
            Debugger.LogError("<ResourceManager> 错误的运行环境,应该是编辑器模式");
            return(null);
#endif
        }
        else
        {
            return(LoadAsset <T>(info.abName, assetName, moduleName));
        }
    }
コード例 #3
0
    //增加预加载资源
    public void AddPreLoadAsset(string reskeyname, int resType)
    {
        ResmapInfo info = GetMapInfo(reskeyname, resType);

        _preLoadAssets.Add(new AssetInfo(reskeyname, info.abName, info.editorPath, resType));
        if (GameMain.Inst.ResourceMode == 0)
        {
            return;
        }
        AddPreLoadAB(info.abName);
    }
コード例 #4
0
    /// 初始化Resmap
    Dictionary <string, ResmapInfo> InitResmap(string resmapName)
    {
        Dictionary <string, ResmapInfo> dic = new Dictionary <string, ResmapInfo>();
        TableHandler handler = TableHandler.OpenFromData(resmapName);

        for (int row = 0; row < handler.GetRecordsNum(); row++)
        {
            ResmapInfo info = new ResmapInfo()
            {
                key        = handler.GetValue(row, 0),
                editorPath = handler.GetValue(row, 1),
                abName     = handler.GetValue(row, 2),
            };
            dic.Add(info.key, info);
        }
        return(dic);
    }
コード例 #5
0
    public ResmapInfo GetMapInfo(string assetName, int resType, bool isTry = false)
    {
        assetName = GetResName(assetName);
        ResmapInfo info = null;

        switch (resType)
        {
        case 1:
            if (_resmap_sprite == null || !_resmap_sprite.TryGetValue(assetName, out info))
            {
                if (!isTry)
                {
                    Debug.LogError("<ResMgr> 映射表中没有这个资源: " + assetName);
                }
                return(null);
            }
            break;

        case 2:
            if (_resmap_prefab == null || !_resmap_prefab.TryGetValue(assetName, out info))
            {
                if (!isTry)
                {
                    Debug.LogError("<ResMgr> 映射表中没有这个资源: " + assetName);
                }
                return(null);
            }
            break;

        case 3:
            if (_resmap_obj == null || !_resmap_obj.TryGetValue(assetName, out info))
            {
                if (!isTry)
                {
                    Debug.LogError("<ResMgr> 映射表中没有这个资源: " + assetName);
                }
                return(null);
            }
            break;
        }

        return(info);
    }
コード例 #6
0
    // 修改完之后,自动完成读写操作
    static void Deal(bool isAdd, string mapTxtName, List <string> assetList)
    {
        Dictionary <string, ResmapInfo> dic = InitResmap(mapTxtName);
        bool isModify = false;

        for (int i = 0; i < assetList.Count; i++)
        {
            string filePath = NormalizePath(assetList[i]);
            string fileName = Path.GetFileNameWithoutExtension(filePath);
            //多语言文件需要拼接出文件名
            int    index;
            string subfix = GetLocalResSubfix(filePath, out index);
            if (index >= 0)
            {
                fileName = fileName + subfix;
            }
            //重新设置信息
            ResmapInfo info = null;
            dic.TryGetValue(fileName, out info);
            if (isAdd) //增加
            {
                if (info == null)
                {
                    info            = new ResmapInfo();
                    info.key        = fileName;
                    info.editorPath = filePath;
                    info.abName     = ABNameUtility.GetResABName(filePath);
                    if (!string.IsNullOrEmpty(info.abName))
                    {
                        dic.Add(fileName, info);
                        isModify = true;
                    }
                }
                else
                {
                    if (info.editorPath.Equals(filePath))
                    {
                        continue;
                    }
                    if (!info.editorPath.Equals(filePath))
                    {
                        if (File.Exists(info.editorPath))
                        {
                            Debug.LogErrorFormat("添加的资源已经有重名的键名{0},请检查!已存在路径{1},添加的路径{2}", fileName, info.editorPath, filePath);
                            continue;
                        }
                        else
                        {
                            string abName = ABNameUtility.GetResABName(filePath);
                            if (string.IsNullOrEmpty(abName))
                            {
                                continue;
                            }
                            info.abName     = abName;
                            info.editorPath = filePath;
                            isModify        = true;
                        }
                    }
                }
                DealLocalConfig(true, Path.GetFileNameWithoutExtension(filePath), index, subfix);
            }
            else //删除操作
            {
                if (info != null)
                {
                    if (info.editorPath.Equals(filePath)) //保证是同一条
                    {
                        dic.Remove(fileName);
                        isModify = true;
                        DealLocalConfig(false, Path.GetFileNameWithoutExtension(filePath), index, subfix);
                    }
                }
            }
        }

        //对不存在的文件,再一次删除
        List <string> keyList = new List <string>(dic.Keys);

        for (int i = 0; i < keyList.Count; i++)
        {
            ResmapInfo info     = dic[keyList[i]];
            string     filePath = info.editorPath;
            if (!File.Exists(filePath))
            {
                string fileName = Path.GetFileNameWithoutExtension(filePath);
                int    index;
                string subfix = GetLocalResSubfix(filePath, out index);
                DealLocalConfig(false, fileName, index, subfix);
                //从字典中删除该条信息
                dic.Remove(keyList[i]);
                isModify = true;
            }
        }

        if (isModify)
        {
            //对资源进行名称排序
            dic = dic.OrderBy(pair => pair.Key).ToDictionary(k => k.Key, v => v.Value);

            //重新生成文件
            GenerateTxt(mapTxtName, dic);
        }

        if (!File.Exists(DataDir + mapTxtName))
        {
            GenerateTxt(mapTxtName, null);
        }
    }