public MechaConfig ExportMechaConfig() { MechaConfig mechaConfig = new MechaConfig(); mechaConfig.MechaConfigName = name; MechaComponentBase[] mcs = transform.GetComponentsInChildren <MechaComponentBase>(); foreach (MechaComponentBase mcb in mcs) { MechaConfig.Config config = new MechaConfig.Config(); config.MechaComponentKey = mcb.name; config.MechaComponentAlias = mcb.EditorAlias; config.MechaComponentQuality = mcb.EditorQuality; config.GridPosR = GridPosR.GetGridPosByLocalTrans(mcb.transform, 1); mechaConfig.MechaComponentList.Add(config); } BehaviourTreeOwner bto = GetComponent <BehaviourTreeOwner>(); if (bto != null) { mechaConfig.MechaAIConfigKey = bto.behaviour.name; } mechaConfig.MechaAIParams = MechaAIParams.Clone(); return(mechaConfig); }
private static void ExportMechaConfig(DataFormat dataFormat) { string folder = MechaConfigFolder_Build; if (Directory.Exists(folder)) { Directory.Delete(folder, true); } Directory.CreateDirectory(folder); DirectoryInfo di = new DirectoryInfo(Application.dataPath + DesignRoot + MechaConfigFolder_Relative); foreach (FileInfo fi in di.GetFiles("*.prefab")) { string relativePath = CommonUtils.ConvertAbsolutePathToProjectPath(fi.FullName); Object configObj = AssetDatabase.LoadAssetAtPath <Object>(relativePath); MechaDesignerHelper helper = ((GameObject)configObj).GetComponent <MechaDesignerHelper>(); if (helper) { MechaConfig config = helper.ExportMechaConfig(); string path = folder + config.MechaConfigName + ".config"; byte[] bytes = SerializationUtility.SerializeValue(config, dataFormat); File.WriteAllBytes(path, bytes); } else { Debug.LogError($"{configObj.name}机甲配置未绑定脚本MechaDesignerHelper,无法序列化"); } } }
private static void LoadMechaConfig(DataFormat dataFormat) { MechaConfigDict.Clear(); DirectoryInfo di = new DirectoryInfo(MechaConfigFolder_Build); if (di.Exists) { foreach (FileInfo fi in di.GetFiles("*.config", SearchOption.AllDirectories)) { byte[] bytes = File.ReadAllBytes(fi.FullName); MechaConfig config = SerializationUtility.DeserializeValue <MechaConfig>(bytes, dataFormat); if (MechaConfigDict.ContainsKey(config.MechaConfigName)) { Debug.LogError($"机甲配置重名:{config.MechaConfigName}"); } else { MechaConfigDict.Add(config.MechaConfigName, config); } } } else { Debug.LogError("机甲配置表不存在"); } }
public MechaInfo(string mechaName, MechaCamp mechaCamp, MechaConfig mechaConfig) { GUID = GetGUID(); MechaName = mechaName; MechaCamp = mechaCamp; MechaConfig = mechaConfig; }