private static void LoadMechaComponentGroupConfig(DataFormat dataFormat) { MechaComponentGroupConfigDict.Clear(); DirectoryInfo di = new DirectoryInfo(MechaComponentGroupConfigFolder_Build); if (di.Exists) { foreach (FileInfo fi in di.GetFiles("*.config", SearchOption.AllDirectories)) { byte[] bytes = File.ReadAllBytes(fi.FullName); MechaComponentGroupConfig config = SerializationUtility.DeserializeValue <MechaComponentGroupConfig>(bytes, dataFormat); if (MechaComponentGroupConfigDict.ContainsKey(config.MechaComponentGroupConfigName)) { Debug.LogError($"机甲组件组配置重名:{config.MechaComponentGroupConfigName}"); } else { MechaComponentGroupConfigDict.Add(config.MechaComponentGroupConfigName, config); } } } else { Debug.LogError("机甲组件组配置表不存在"); } }
private static void ExportMechaComponentGroupConfig(DataFormat dataFormat) { string folder = MechaComponentGroupConfigFolder_Build; if (Directory.Exists(folder)) { Directory.Delete(folder, true); } Directory.CreateDirectory(folder); DirectoryInfo di = new DirectoryInfo(Application.dataPath + DesignRoot + MechaComponentGroupConfigFolder_Relative); foreach (FileInfo fi in di.GetFiles("*.asset")) { string relativePath = CommonUtils.ConvertAbsolutePathToProjectPath(fi.FullName); Object configObj = AssetDatabase.LoadAssetAtPath <Object>(relativePath); MechaComponentGroupConfigSSO configSSO = (MechaComponentGroupConfigSSO)configObj; configSSO.RefreshConfigListBeforeExport(); MechaComponentGroupConfig config = configSSO.MechaComponentGroupConfig; if (string.IsNullOrEmpty(configSSO.MechaComponentGroupConfig.MechaComponentGroupConfigName)) { Debug.LogError("机甲组件组配置无名称,无法序列化"); } else { string path = folder + configSSO.name + ".config"; byte[] bytes = SerializationUtility.SerializeValue(config, dataFormat); File.WriteAllBytes(path, bytes); } } }