Example #1
0
        public static void Export()
        {
            string[] tileAssetPath = new string[] { Setting.ConfigSearchPath };
            string[] guids         = AssetDatabase.FindAssets("t:ScriptableObject", tileAssetPath);

            Dictionary <string, List <IConfig> > configDict = new Dictionary <string, List <IConfig> >();

            foreach (var guid in guids)
            {
                string           path   = AssetDatabase.GUIDToAssetPath(guid);
                ConfigAssetGroup config = AssetDatabase.LoadAssetAtPath <ConfigAssetGroup>(path);
                if (string.IsNullOrEmpty(config.configTypeName))
                {
                    Debug.LogError($"p配置导出失败,没有对应配置类》》》{config.name}");
                    return;
                }
                List <IConfig> configs = new List <IConfig>();
                if (config != null)
                {
                    foreach (var item in config.GetAllAsset())
                    {
                        List <IConfig> datas = item.Load();
                        if (datas != null)
                        {
                            configs.AddRange(datas);
                        }
                    }
                }
                if (configDict.ContainsKey(config.configTypeName))
                {
                    configDict[config.configTypeName].AddRange(configs);
                }
                else
                {
                    configDict.Add(config.configTypeName, configs);
                }
            }

            foreach (var item in configDict)
            {
                string filePath = Setting.ConfigExportPath + ConfigDef.GetCnfName(item.Key);
                IOHelper.WriteText(JsonMapper.ToJson(item.Value), filePath);
            }
            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
        }
Example #2
0
        private static string GenCnfCode(Type cnfType)
        {
            string className     = GenTBConfigCode.GetCodeClassName(cnfType);
            string classFileName = GenTBConfigCode.GetCodeClassFileName(cnfType);
            string displayName   = cnfType.Name;

            if (AttributeHelper.TryGetTypeAttribute(cnfType, out ConfigAttribute attr))
            {
                displayName = attr.DisplayName;
            }

            string resStr = CnfCode;

            resStr  = Regex.Replace(resStr, "#DISPLAYNAME#", displayName);
            resStr  = Regex.Replace(resStr, "#CLASS#", className);
            resStr  = Regex.Replace(resStr, "#NAME#", classFileName);
            resStr  = Regex.Replace(resStr, "#TYPE#", cnfType.Name);
            resStr  = Regex.Replace(resStr, "#NAME01#", "_" + cnfType.Name);
            resStr  = Regex.Replace(resStr, "#NAME02#", cnfType.Name);
            resStr  = Regex.Replace(resStr, "#NAME03#", ConfigDef.GetCnfNoExName(cnfType.Name));
            resStr += "\n";
            return(resStr);
        }