mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
临时提交
This commit is contained in:
3
JNFrame2/Assets/HotScripts/JNGame/Editor/CodeGen.meta
Normal file
3
JNFrame2/Assets/HotScripts/JNGame/Editor/CodeGen.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2131d730bd5441b894b4aa82cf8ec03c
|
||||
timeCreated: 1729496838
|
@@ -0,0 +1,134 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace JNGame.Tools.CodeGen
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成信息
|
||||
/// </summary>
|
||||
public class CodeGenInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码文件输出路径
|
||||
/// </summary>
|
||||
public string outputPath;
|
||||
/// <summary>
|
||||
/// 代码生成using的命名空间
|
||||
/// </summary>
|
||||
public string codeGenNameSpace;
|
||||
/// <summary>
|
||||
/// 需要代码生成的所有Type
|
||||
/// </summary>
|
||||
public List<System.Type> allTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CodeGenFieldInfo
|
||||
{
|
||||
public System.Type type;
|
||||
public string name;
|
||||
|
||||
public string TypeName => type.Name;
|
||||
public string FullTypeName => type.FullName;
|
||||
public bool IsEnum => type.IsEnum;
|
||||
public bool IsStruct => !type.IsClass && !type.IsInterface;
|
||||
public bool IsClass => type.IsClass;
|
||||
public bool IsString => type == typeof(string);
|
||||
public bool IsArray => type.IsArray;
|
||||
public bool IsList => type.IsSubclassOf(typeof(IList));
|
||||
public bool IsDict => type.IsSubclassOf(typeof(IDictionary));
|
||||
}
|
||||
|
||||
public class CodeGenTemplateInfo
|
||||
{
|
||||
public string Default = "";
|
||||
public string Enum = "";
|
||||
public string Struct = "";
|
||||
public string Array = "";
|
||||
public string List = "";
|
||||
public string Dict = "";
|
||||
|
||||
public string GetTemplateStr(CodeGenFieldInfo info)
|
||||
{
|
||||
if (info.IsEnum && !string.IsNullOrEmpty(Enum)) return Enum;
|
||||
if (info.IsList && !string.IsNullOrEmpty(List)) return List;
|
||||
if (info.IsDict && !string.IsNullOrEmpty(Dict)) return Dict;
|
||||
if (info.IsStruct && !string.IsNullOrEmpty(Struct)) return Struct;
|
||||
if (info.IsArray && !string.IsNullOrEmpty(Array)) return Array;
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
|
||||
public class FileUtil
|
||||
{
|
||||
public static void SaveFile(string path, byte[] finalStr, bool isNeedLog = true)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var rawContent = File.ReadAllBytes(path);
|
||||
if (finalStr.Length == rawContent.Length)
|
||||
{
|
||||
bool isSame = true;
|
||||
for (int i = 0; i < finalStr.Length; i++)
|
||||
{
|
||||
if (finalStr[i] != rawContent[i])
|
||||
{
|
||||
isSame = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSame)
|
||||
{
|
||||
// 相同的内容跳过,避免重新的导入
|
||||
#if UNITY_EDITOR
|
||||
if (isNeedLog) UnityEngine.Debug.Log("Output Skip " + path);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File.WriteAllBytes(path, finalStr);
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.AssetDatabase.ImportAsset(path);
|
||||
if (isNeedLog) UnityEngine.Debug.Log("Output " + path);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void SaveFile(string path, string finalStr, bool isNeedLog = true)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var rawContent = File.ReadAllText(path);
|
||||
if (finalStr == rawContent)
|
||||
{
|
||||
// 相同的内容跳过,避免重新的导入
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllText(path, finalStr);
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.AssetDatabase.ImportAsset(path);
|
||||
if (isNeedLog) UnityEngine.Debug.Log("Output " + path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6427711364f941d58000a7c3df90315e
|
||||
timeCreated: 1729496613
|
@@ -0,0 +1,70 @@
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System.Collections.Generic;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Serialization;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
public static class GameplayAbilityAssetConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// 序列化TimelineAbilityAsset
|
||||
/// </summary>
|
||||
/// <param name="timelineAbilityAsset"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ToBytes(this TimelineAbilityAsset timelineAbilityAsset)
|
||||
{
|
||||
Serializer serializer = new Serializer();
|
||||
// 序列化TimlineAbilityAsset的Ability属性配置
|
||||
serializer.Write(timelineAbilityAsset.Name);
|
||||
serializer.Write(timelineAbilityAsset.UniqueName);
|
||||
serializer.Write(timelineAbilityAsset.Cost == null ? "" : timelineAbilityAsset.Cost.Name);
|
||||
serializer.Write(timelineAbilityAsset.CooldownTime);
|
||||
// serializer.WriteArray(timelineAbilityAsset.AssetTags);
|
||||
// serializer.WriteArray(timelineAbilityAsset.CancelAbilityTags);
|
||||
// serializer.WriteArray(timelineAbilityAsset.BlockAbilityTags);
|
||||
// serializer.WriteArray(timelineAbilityAsset.ActivationOwnedTags);
|
||||
// serializer.WriteArray(timelineAbilityAsset.ActivationRequiredTags);
|
||||
// serializer.WriteArray(timelineAbilityAsset.ActivationBlockedTags);
|
||||
|
||||
// Ability的Timeline执行规则部分转化为TimelineInfo
|
||||
// TimelineInfo timelineInfo = Convert2TimelineInfo(timelineAbilityAsset);
|
||||
// timelineInfo.SerializeForEditor(serializer);
|
||||
|
||||
return serializer.CopyData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class AbilityAssetTool
|
||||
{
|
||||
// /// <summary>
|
||||
// /// PureTimelineAbilityAsset数据序列化为字节数据的工具函数
|
||||
// /// </summary>
|
||||
// /// <param name="info"></param>
|
||||
// /// <returns></returns>
|
||||
// public static byte[] Serialize(PureTimelineAbilityAsset abilityAsset)
|
||||
// {
|
||||
// var writer = new Serializer();
|
||||
// abilityAsset.SerializeForEditor(writer);
|
||||
// return writer.CopyData();
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 字节数据反序列化为PureTimelineAbilityAsset的工具函数
|
||||
// /// </summary>
|
||||
// /// <param name="bytes"></param>
|
||||
// /// <returns></returns>
|
||||
// public static PureTimelineAbilityAsset Deserialize(byte[] bytes)
|
||||
// {
|
||||
// var reader = new Deserializer(bytes);
|
||||
// var abilityAsset = new PureTimelineAbilityAsset();
|
||||
// abilityAsset.DeserializeForEditor(reader);
|
||||
// return abilityAsset;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8ce146f8ec841b49c7015f978fe03d9
|
||||
timeCreated: 1729501121
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using GAS.General;
|
||||
using Sirenix.OdinInspector;
|
||||
@@ -30,6 +31,25 @@ namespace GAS.Editor
|
||||
[OnValueChanged("SaveAsset")]
|
||||
public string GASConfigAssetPath = "Assets/GAS/Config";
|
||||
|
||||
[BoxGroup("A")]
|
||||
[LabelText("二进制配置文件生成路径")]
|
||||
[LabelWidth(LABEL_WIDTH)]
|
||||
[FolderPath]
|
||||
[OnValueChanged("SaveAsset")]
|
||||
public string GASBinaryAssetPath = "Assets/GAS/Binary";
|
||||
|
||||
[BoxGroup("A")]
|
||||
[LabelText("业务脚本生成路径")]
|
||||
[LabelWidth(LABEL_WIDTH)]
|
||||
[FolderPath]
|
||||
[OnValueChanged("SaveAsset")]
|
||||
public string LogicCodeGeneratePath = "Assets/Scripts/Gen";
|
||||
|
||||
[BoxGroup("A")]
|
||||
[LabelText("业务脚本Assembly")]
|
||||
[LabelWidth(LABEL_WIDTH)]
|
||||
public List<string> LogicCodeGenerateAssemblies = new List<string>();
|
||||
|
||||
public static GASSettingAsset Setting
|
||||
{
|
||||
get
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c8eb15d90924617af4759059f71843b
|
||||
timeCreated: 1729496573
|
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Tools.CodeGen;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// AbilityTask枚举和构造工厂方法注册代码生成
|
||||
/// </summary>
|
||||
public class CodeGenAbilityTaskInjecter
|
||||
{
|
||||
private static readonly string s_CodeTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏业务逻辑扩展的AbilityTask枚举
|
||||
/// </summary>
|
||||
public enum EnumGameAbilityTaskType
|
||||
{
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
#region AbilityTask构造工厂方法注册
|
||||
|
||||
public partial class GASInjector
|
||||
{
|
||||
private partial void InternalAbilityTaskInject()
|
||||
{
|
||||
##CODEREPLACE_1
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AbilityTask枚举ID自动生成
|
||||
|
||||
##CODEREPLACE_2
|
||||
|
||||
#endregion
|
||||
|
||||
}";
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t";
|
||||
var contextTemplates = new List<string>()
|
||||
{
|
||||
prefix + prefix + "##TYPE_NAME = ##INDEX,",
|
||||
prefix + prefix + prefix + "AbilityTaskFactory.Register((ushort)EnumGameAbilityTaskType.##TYPE_NAME, () => new ##FULL_TYPE_NAME());",
|
||||
prefix + "public partial class ##TYPE_NAME { public override ushort TypeId => (ushort)EnumGameAbilityTaskType.##TYPE_NAME; }"
|
||||
};
|
||||
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
var finalStr = s_CodeTemplate.Replace("##NAMESPACE", info.codeGenNameSpace);
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
finalStr = finalStr.Replace("##CODEREPLACE_" + i, GenCodeByTemplate(types, contextTemplates[i]));
|
||||
}
|
||||
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(List<Type> types, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int counterInstantTask = 0;
|
||||
int counterOngoingTask = 0;
|
||||
int counterPassiveTask = 0;
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
var type = types[i];
|
||||
string index;
|
||||
if (type.IsSubclassOf(typeof(InstantAbilityTask)))
|
||||
{
|
||||
index = ((int)EnumAbilityTaskType.InstantTaskStart + (++counterInstantTask)).ToString();
|
||||
}
|
||||
else if (type.IsSubclassOf(typeof(OngoingAbilityTask)))
|
||||
{
|
||||
index = ((int)EnumAbilityTaskType.OngoingTaskStart + (++counterOngoingTask)).ToString();
|
||||
}
|
||||
else if(type.IsSubclassOf(typeof(PassiveAbilityTask)))
|
||||
{
|
||||
index = ((int)EnumAbilityTaskType.PassiveTaskStart + (++counterPassiveTask)).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"AbilityTask的类型不是 InstantAbilityTask /OngoingAbilityTask / PassiveAbilityTask 任意一种,{type.FullName}");
|
||||
continue;
|
||||
}
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##INDEX", index).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdc093094756c434781a2996f811416d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,127 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 行为树节点序列化相关代码生成
|
||||
/// </summary>
|
||||
public class CodeGenAbilityTaskSerialization
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码文件头部模板代码
|
||||
/// </summary>
|
||||
private static readonly string s_CodeHeaderTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
using JNGame.Serialization;
|
||||
";
|
||||
|
||||
/// <summary>
|
||||
/// 类模板代码
|
||||
/// </summary>
|
||||
private static readonly string s_ClsTemplate = @"
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
public partial class ##TYPE_NAME
|
||||
{
|
||||
public override void Serialize(Serializer writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
public override void Deserialize(Deserializer reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
##CODEREPLACE_1
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
private static readonly BindingFlags s_BindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t\t\t";
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var type in types)
|
||||
{
|
||||
var clsStr = GenCodeByTemplate(type, s_ClsTemplate);
|
||||
var contextTemplates = new List<CodeGenTemplateInfo>()
|
||||
{
|
||||
new CodeGenTemplateInfo()
|
||||
{
|
||||
Default = prefix + "writer.Write(##NAME);",
|
||||
Enum = prefix + "writer.Write((int)##NAME);", // TODO deal with array list &dict
|
||||
Array = prefix + "writer.WriteArray(##NAME);",
|
||||
},
|
||||
new CodeGenTemplateInfo()
|
||||
{
|
||||
Default = prefix + "##NAME = reader.Read##TYPE_NAME();",
|
||||
Enum = prefix + "##NAME = (##TYPE_NAME)reader.ReadInt32();",
|
||||
Array = prefix + "##NAME = reader.ReadArray(new ##ELEMENT_TYPE_NAME());",
|
||||
},
|
||||
};
|
||||
var fields = type.GetFields(s_BindingFlags)
|
||||
.Select(a => new CodeGenFieldInfo() { name = a.Name, type = a.FieldType }).ToList();
|
||||
// var properties = type.GetProperties(s_BindingFlags).Where(a => a.CanRead && a.CanWrite)
|
||||
// .Select(a => new CodeGenFieldInfo() { name = a.Name, type = a.PropertyType }).ToList();
|
||||
// fields.AddRange(properties);
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
clsStr = clsStr.Replace("##CODEREPLACE_" + i, GetFieldsCode(fields, contextTemplates[i]));
|
||||
}
|
||||
|
||||
if (fields.Count > 0)
|
||||
{
|
||||
sb.AppendLine(clsStr);
|
||||
}
|
||||
}
|
||||
|
||||
var finalStr = s_CodeHeaderTemplate;
|
||||
finalStr += sb.ToString();
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GetFieldsCode(List<CodeGenFieldInfo> fields, CodeGenTemplateInfo template)
|
||||
{
|
||||
StringBuilder sbField = new StringBuilder();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var templateStr = template.GetTemplateStr(field);
|
||||
string elementTypeName = "";
|
||||
if(field.IsArray || field.IsList)
|
||||
{
|
||||
elementTypeName = field.type.GetElementType().Name;
|
||||
}
|
||||
var str = templateStr.Replace("##NAME", field.name).Replace("##TYPE_NAME", field.TypeName).Replace("##FULL_TYPE_NAME", field.FullTypeName)
|
||||
.Replace("##ELEMENT_TYPE_NAME", elementTypeName);
|
||||
sbField.AppendLine(str);
|
||||
}
|
||||
|
||||
return sbField.ToString();
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(Type type, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var nameSpace = type.Namespace.ToString();
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##NAMESPACE", nameSpace).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d06f987f50f2b6947beba00d4c7be0b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
public class CodeGenGELib
|
||||
{
|
||||
private static readonly string s_CodeTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
#region GE索引自动导出
|
||||
|
||||
public static class GELib
|
||||
{
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}";
|
||||
|
||||
public static void GenCode(List<string> allGEAssetNames, string codeGenNameSpace, string outputPath)
|
||||
{
|
||||
string prefix = "\t\t";
|
||||
var contextTemplates = new List<string>()
|
||||
{
|
||||
prefix + "public static readonly string ##FILE_NAME = \"##UNIQUE_KEY\";"
|
||||
};
|
||||
|
||||
var finalStr = s_CodeTemplate.Replace("##NAMESPACE", codeGenNameSpace);
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
finalStr = finalStr.Replace("##CODEREPLACE_" + i, GenCodeByTemplate(allGEAssetNames, contextTemplates[i]));
|
||||
}
|
||||
|
||||
var path = outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(List<string> allGEAssetNames, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < allGEAssetNames.Count; ++i)
|
||||
{
|
||||
var str = template.Replace("##FILE_NAME", allGEAssetNames[i]).Replace("##UNIQUE_KEY", allGEAssetNames[i]);
|
||||
sb.AppendLine(str);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43f0c08a89a7fef4da5be7b154a90b57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// MMC枚举和构造工厂方法注册代码生成
|
||||
/// </summary>
|
||||
public class CodeGenPureMMCInjecter
|
||||
{
|
||||
private static readonly string s_CodeTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏业务逻辑扩展的MMC枚举
|
||||
/// </summary>
|
||||
public enum EnumGameMMCType
|
||||
{
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
#region MMC构造工厂方法注册
|
||||
|
||||
public partial class GASInjector
|
||||
{
|
||||
private partial void InternalMMCInject()
|
||||
{
|
||||
##CODEREPLACE_1
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MMC枚举ID自动生成
|
||||
|
||||
##CODEREPLACE_2
|
||||
|
||||
#endregion
|
||||
|
||||
}";
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t";
|
||||
var contextTemplates = new List<string>()
|
||||
{
|
||||
prefix + prefix + "##TYPE_NAME = ##INDEX,",
|
||||
prefix + prefix + prefix + "MMCFactory.Register((ushort)EnumGameMMCType.##TYPE_NAME, () => new ##FULL_TYPE_NAME());",
|
||||
prefix + "public partial class ##TYPE_NAME { public override ushort TypeId => (ushort)EnumGameMMCType.##TYPE_NAME; }"
|
||||
};
|
||||
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
var finalStr = s_CodeTemplate.Replace("##NAMESPACE", info.codeGenNameSpace);
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
finalStr = finalStr.Replace("##CODEREPLACE_" + i, GenCodeByTemplate(types, contextTemplates[i]));
|
||||
}
|
||||
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(List<Type> types, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
var type = types[i];
|
||||
string index = ((int)EnumMMCType.EnumBuiltinCount + i + 1).ToString();
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##INDEX", index).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f93cd40e5f55ae4bad291b74a82898b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,122 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 行为树节点序列化相关代码生成
|
||||
/// </summary>
|
||||
public class CodeGenPureMMCSerialization
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码文件头部模板代码
|
||||
/// </summary>
|
||||
private static readonly string s_CodeHeaderTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
using JNGame.Serialization;
|
||||
";
|
||||
|
||||
/// <summary>
|
||||
/// 类模板代码
|
||||
/// </summary>
|
||||
private static readonly string s_ClsTemplate = @"
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
public partial class ##TYPE_NAME
|
||||
{
|
||||
public override void Serialize(Serializer writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
public override void Deserialize(Deserializer reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
##CODEREPLACE_1
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
private static readonly BindingFlags s_BindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t\t\t";
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var type in types)
|
||||
{
|
||||
var clsStr = GenCodeByTemplate(type, s_ClsTemplate);
|
||||
var contextTemplates = new List<CodeGenTemplateInfo>()
|
||||
{
|
||||
new CodeGenTemplateInfo()
|
||||
{
|
||||
Default = prefix + "writer.Write(##NAME);",
|
||||
Enum = prefix + "writer.Write((byte)##NAME);", // TODO deal with array list &dict
|
||||
},
|
||||
new CodeGenTemplateInfo()
|
||||
{
|
||||
Default = prefix + "##NAME = reader.Read##TYPE_NAME();",
|
||||
Enum = prefix + "##NAME = (##TYPE_NAME)reader.ReadByte();",
|
||||
},
|
||||
};
|
||||
var fields = type.GetFields(s_BindingFlags)
|
||||
.Select(a => new CodeGenFieldInfo() { name = a.Name, type = a.FieldType }).ToList();
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
clsStr = clsStr.Replace("##CODEREPLACE_" + i, GetFieldsCode(fields, contextTemplates[i]));
|
||||
}
|
||||
|
||||
if (fields.Count > 0)
|
||||
{
|
||||
sb.AppendLine(clsStr);
|
||||
}
|
||||
}
|
||||
|
||||
var finalStr = s_CodeHeaderTemplate;
|
||||
finalStr += sb.ToString();
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GetFieldsCode(List<CodeGenFieldInfo> fields, CodeGenTemplateInfo template)
|
||||
{
|
||||
StringBuilder sbField = new StringBuilder();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var templateStr = template.GetTemplateStr(field);
|
||||
string elementTypeName = "";
|
||||
if(field.IsArray || field.IsList)
|
||||
{
|
||||
elementTypeName = field.type.GetElementType().Name;
|
||||
}
|
||||
var str = templateStr.Replace("##NAME", field.name).Replace("##TYPE_NAME", field.TypeName).Replace("##FULL_TYPE_NAME", field.FullTypeName)
|
||||
.Replace("##ELEMENT_TYPE_NAME", elementTypeName);
|
||||
sbField.AppendLine(str);
|
||||
}
|
||||
|
||||
return sbField.ToString();
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(Type type, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var nameSpace = type.Namespace.ToString();
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##NAMESPACE", nameSpace).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44b19adf34116394c99dd66de03bebde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// MMC枚举和构造工厂方法注册代码生成
|
||||
/// </summary>
|
||||
public class CodeGenScriptableMMCInjecter
|
||||
{
|
||||
private static readonly string s_CodeTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
#region MMC枚举ID自动生成
|
||||
|
||||
##CODEREPLACE_0
|
||||
|
||||
#endregion
|
||||
|
||||
}";
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t";
|
||||
var contextTemplates = new List<string>()
|
||||
{
|
||||
prefix + "public partial class ##TYPE_NAME { public override ushort TypeId => (ushort)EnumGameMMCType.Pure##TYPE_NAME; }"
|
||||
};
|
||||
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
var finalStr = s_CodeTemplate.Replace("##NAMESPACE", info.codeGenNameSpace);
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
finalStr = finalStr.Replace("##CODEREPLACE_" + i, GenCodeByTemplate(types, contextTemplates[i]));
|
||||
}
|
||||
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(List<Type> types, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
var type = types[i];
|
||||
string index = ((int)EnumMMCType.EnumBuiltinCount + i + 1).ToString();
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##INDEX", index).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be3b8b5fbf6288d489d2505ffb6c937b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,122 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 行为树节点序列化相关代码生成
|
||||
/// </summary>
|
||||
public class CodeGenScriptableMMCSerialization
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码文件头部模板代码
|
||||
/// </summary>
|
||||
private static readonly string s_CodeHeaderTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
using JNGame.Serialization;
|
||||
";
|
||||
|
||||
/// <summary>
|
||||
/// 类模板代码
|
||||
/// </summary>
|
||||
private static readonly string s_ClsTemplate = @"
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
public partial class ##TYPE_NAME
|
||||
{
|
||||
public override void Serialize(Serializer writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
public override void Deserialize(Deserializer reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
##CODEREPLACE_1
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
private static readonly BindingFlags s_BindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t\t\t";
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var type in types)
|
||||
{
|
||||
var clsStr = GenCodeByTemplate(type, s_ClsTemplate);
|
||||
var contextTemplates = new List<CodeGenTemplateInfo>()
|
||||
{
|
||||
new CodeGenTemplateInfo()
|
||||
{
|
||||
Default = prefix + "writer.Write(##NAME);",
|
||||
Enum = prefix + "writer.Write((byte)##NAME);", // TODO deal with array list &dict
|
||||
},
|
||||
new CodeGenTemplateInfo()
|
||||
{
|
||||
Default = prefix + "##NAME = reader.Read##TYPE_NAME();",
|
||||
Enum = prefix + "##NAME = (##TYPE_NAME)reader.ReadByte();",
|
||||
},
|
||||
};
|
||||
var fields = type.GetFields(s_BindingFlags)
|
||||
.Select(a => new CodeGenFieldInfo() { name = a.Name, type = a.FieldType }).ToList();
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
clsStr = clsStr.Replace("##CODEREPLACE_" + i, GetFieldsCode(fields, contextTemplates[i]));
|
||||
}
|
||||
|
||||
if (fields.Count > 0)
|
||||
{
|
||||
sb.AppendLine(clsStr);
|
||||
}
|
||||
}
|
||||
|
||||
var finalStr = s_CodeHeaderTemplate;
|
||||
finalStr += sb.ToString();
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GetFieldsCode(List<CodeGenFieldInfo> fields, CodeGenTemplateInfo template)
|
||||
{
|
||||
StringBuilder sbField = new StringBuilder();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var templateStr = template.GetTemplateStr(field);
|
||||
string elementTypeName = "";
|
||||
if(field.IsArray || field.IsList)
|
||||
{
|
||||
elementTypeName = field.type.GetElementType().Name;
|
||||
}
|
||||
var str = templateStr.Replace("##NAME", field.name).Replace("##TYPE_NAME", field.TypeName).Replace("##FULL_TYPE_NAME", field.FullTypeName)
|
||||
.Replace("##ELEMENT_TYPE_NAME", elementTypeName);
|
||||
sbField.AppendLine(str);
|
||||
}
|
||||
|
||||
return sbField.ToString();
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(Type type, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var nameSpace = type.Namespace.ToString();
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##NAMESPACE", nameSpace).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7b15c5efee61074f997ba552d608101
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,90 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Tools.CodeGen;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 目标捕获器枚举和构造工厂方法注册代码生成
|
||||
/// </summary>
|
||||
public class CodeGenTargetCatcherInjecter
|
||||
{
|
||||
private static readonly string s_CodeTemplate = @"
|
||||
// auto generate by tools, DO NOT Modify it!!!
|
||||
|
||||
using GAS.Runtime;
|
||||
|
||||
namespace ##NAMESPACE
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏业务逻辑扩展的TargetCatcher枚举
|
||||
/// </summary>
|
||||
public enum EnumGameTargetCatcherType
|
||||
{
|
||||
##CODEREPLACE_0
|
||||
}
|
||||
|
||||
#region TargetCatcher构造工厂方法注册
|
||||
|
||||
public partial class GASInjector
|
||||
{
|
||||
private partial void InternalTargetCatcherInject()
|
||||
{
|
||||
##CODEREPLACE_1
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TargetCatcher枚举ID自动生成
|
||||
|
||||
##CODEREPLACE_2
|
||||
|
||||
#endregion
|
||||
|
||||
}";
|
||||
|
||||
public static void GenCode(CodeGenInfo info)
|
||||
{
|
||||
string prefix = "\t";
|
||||
var contextTemplates = new List<string>()
|
||||
{
|
||||
prefix + prefix + "##TYPE_NAME = ##INDEX,",
|
||||
prefix + prefix + prefix + "TargetCatcherFactory.Register((ushort)EnumGameTargetCatcherType.##TYPE_NAME, () => new ##FULL_TYPE_NAME());",
|
||||
prefix + "public partial class ##TYPE_NAME { public override ushort TypeId => (ushort)EnumGameTargetCatcherType.##TYPE_NAME; }"
|
||||
};
|
||||
|
||||
var types = info.allTypes.ToArray().ToList();
|
||||
types.Sort((a, b) => a.Name.CompareTo(b.Name));
|
||||
var finalStr = s_CodeTemplate.Replace("##NAMESPACE", info.codeGenNameSpace);
|
||||
for (int i = 0; i < contextTemplates.Count; i++)
|
||||
{
|
||||
finalStr = finalStr.Replace("##CODEREPLACE_" + i, GenCodeByTemplate(types, contextTemplates[i]));
|
||||
}
|
||||
|
||||
var path = info.outputPath;
|
||||
FileUtil.SaveFile(path, finalStr);
|
||||
}
|
||||
|
||||
private static string GenCodeByTemplate(List<Type> types, string template)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
var type = types[i];
|
||||
string index = ((int)EnumTargetCatcherType.EnumBuiltinCount + i + 1).ToString();
|
||||
var typeName = type.Name.ToString();
|
||||
var fullTypeName = type.FullName.ToString();
|
||||
var str = template.Replace("##INDEX", index).Replace("##TYPE_NAME", typeName).Replace("##FULL_TYPE_NAME", fullTypeName);
|
||||
sb.AppendLine(str);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9417a4dacd34d1f438b3a1583dea58de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f879d96e563108c45ab0cfa0ffc025f8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,338 @@
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GAS.Runtime;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using JNGame.Tools.CodeGen;
|
||||
using JNGame.Serialization;
|
||||
using FileUtil = JNGame.Tools.CodeGen.FileUtil;
|
||||
|
||||
namespace GAS.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 纯净模式GAS的编辑器工具
|
||||
/// </summary>
|
||||
public static class PureGASEditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// GAS纯净模式代码生成入口
|
||||
/// </summary>
|
||||
[MenuItem("EX-GAS/PureMode/GenCode/All")]
|
||||
public static void GenCode()
|
||||
{
|
||||
GenCode_AbilityTaskBase();
|
||||
GenCode_TargetCatcherBase();
|
||||
GenCode_MMC();
|
||||
GenCode_GELib();
|
||||
}
|
||||
|
||||
[MenuItem("EX-GAS/PureMode/GenCode/AbilityTask")]
|
||||
public static void GenCode_AbilityTaskBase()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
GASSettingAsset gasSetting = GASSettingAsset.Setting;
|
||||
List<Type> subTypeFromAbilityTaskBase = new List<Type>();
|
||||
for (var i = 0; i < assemblies.Length; ++i)
|
||||
{
|
||||
var assembly = assemblies[i];
|
||||
if (assembly == null) { continue; }
|
||||
var assName = assembly.GetName().Name;
|
||||
if (!gasSetting.LogicCodeGenerateAssemblies.Contains(assName)) { continue; }
|
||||
// 筛选非抽象的AbilityTaskBase派生类
|
||||
var lst = assembly.GetTypes().Where(
|
||||
clsType => !clsType.IsAbstract && clsType.IsSubclassOf(typeof(AbilityTaskBase))
|
||||
);
|
||||
subTypeFromAbilityTaskBase.AddRange(lst);
|
||||
}
|
||||
|
||||
var dir = gasSetting.LogicCodeGeneratePath;
|
||||
// 自动生成AbilityTask枚举和工厂注入方法
|
||||
CodeGenAbilityTaskInjecter.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_AbilityTaskExt.cs"),
|
||||
allTypes = subTypeFromAbilityTaskBase
|
||||
});
|
||||
// 自动生成AbilityTask序列化相关代码
|
||||
CodeGenAbilityTaskSerialization.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_AbilityTaskExtSerialization.cs"),
|
||||
allTypes = subTypeFromAbilityTaskBase
|
||||
});
|
||||
}
|
||||
|
||||
[MenuItem("EX-GAS/PureMode/GenCode/TargetCatcher")]
|
||||
public static void GenCode_TargetCatcherBase()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
GASSettingAsset gasSetting = GASSettingAsset.Setting;
|
||||
List<Type> subTypeFromTargetCatcherBase = new List<Type>();
|
||||
for (var i = 0; i < assemblies.Length; ++i)
|
||||
{
|
||||
var assembly = assemblies[i];
|
||||
if (assembly == null) { continue; }
|
||||
var assName = assembly.GetName().Name;
|
||||
if (!gasSetting.LogicCodeGenerateAssemblies.Contains(assName)) { continue; }
|
||||
// 筛选非抽象的TargetCatcherBase派生类
|
||||
var lst = assembly.GetTypes().Where(
|
||||
clsType => !clsType.IsAbstract && clsType.IsSubclassOf(typeof(TargetCatcherBase))
|
||||
);
|
||||
subTypeFromTargetCatcherBase.AddRange(lst);
|
||||
}
|
||||
// 自动生成TargetCatcher枚举和工厂注入方法
|
||||
var dir = gasSetting.LogicCodeGeneratePath;
|
||||
CodeGenTargetCatcherInjecter.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_TaregetCatcherExt.cs"),
|
||||
allTypes = subTypeFromTargetCatcherBase
|
||||
});
|
||||
}
|
||||
|
||||
[MenuItem("EX-GAS/PureMode/GenCode/GELib")]
|
||||
public static void GenCode_GELib()
|
||||
{
|
||||
var dir = GASSettingAsset.Setting.LogicCodeGeneratePath;
|
||||
var guids = AssetDatabase.FindAssets($"t:{nameof(GameplayEffectAsset)}");
|
||||
List<string> allGENames = new List<string>(guids.Length);
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
// 加载Scriptable配置,并且序列化为bytes
|
||||
var geAsset = AssetDatabase.LoadAssetAtPath<GameplayEffectAsset>(path);
|
||||
allGENames.Add(geAsset.name);
|
||||
}
|
||||
CodeGenGELib.GenCode(allGENames, "JNGame.GAS", Path.Combine(dir, "CodeGen_GELib.cs"));
|
||||
}
|
||||
|
||||
[MenuItem("EX-GAS/PureMode/GenCode/MMC")]
|
||||
public static void GenCode_MMC()
|
||||
{
|
||||
GenCode_PureMMC();
|
||||
GenCode_ScriptableMMC();
|
||||
}
|
||||
|
||||
public static void GenCode_PureMMC()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
GASSettingAsset gasSetting = GASSettingAsset.Setting;
|
||||
List<Type> subTypeFromPureMMC = new List<Type>();
|
||||
List<Type> subTypeFromScriptableMMC = new List<Type>();
|
||||
List<string> outFilter = new List<string>() {
|
||||
"AttrBasedWithStackModCalculation",
|
||||
"AttributeBasedModCalculation",
|
||||
"ScalableFloatModCalculation",
|
||||
"StackModCalculation",
|
||||
};
|
||||
for (var i = 0; i < assemblies.Length; ++i)
|
||||
{
|
||||
var assembly = assemblies[i];
|
||||
if (assembly == null) { continue; }
|
||||
var assName = assembly.GetName().Name;
|
||||
if (!gasSetting.LogicCodeGenerateAssemblies.Contains(assName)) { continue; }
|
||||
// 筛选非抽象的PureModifierMagnitudeCalculation派生类
|
||||
var lst = assembly.GetTypes().Where(
|
||||
clsType => !clsType.IsAbstract && clsType.IsSubclassOf(typeof(PureModifierMagnitudeCalculation)) && outFilter.IndexOf(clsType.Name) < 0
|
||||
);
|
||||
subTypeFromPureMMC.AddRange(lst);
|
||||
}
|
||||
var dir = gasSetting.LogicCodeGeneratePath;
|
||||
CodeGenPureMMCInjecter.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_PureMMCExt.cs"),
|
||||
allTypes = subTypeFromPureMMC
|
||||
});
|
||||
CodeGenPureMMCSerialization.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_PureMMCExtSerialization.cs"),
|
||||
allTypes = subTypeFromPureMMC
|
||||
});
|
||||
}
|
||||
|
||||
public static void GenCode_ScriptableMMC()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
GASSettingAsset gasSetting = GASSettingAsset.Setting;
|
||||
List<Type> subTypeFromScriptableMMC = new List<Type>();
|
||||
|
||||
List<string> outFilter = new List<string>() {
|
||||
"AttrBasedWithStackModCalculation",
|
||||
"AttributeBasedModCalculation",
|
||||
"ScalableFloatModCalculation",
|
||||
"StackModCalculation",
|
||||
};
|
||||
for (var i = 0; i < assemblies.Length; ++i)
|
||||
{
|
||||
var assembly = assemblies[i];
|
||||
if (assembly == null) { continue; }
|
||||
var assName = assembly.GetName().Name;
|
||||
if (!"GAS.UnityExt.Runtime".Equals(assName)) { continue; }
|
||||
// 筛选非抽象的ModifierMagnitudeCalculation派生类
|
||||
var lst = assembly.GetTypes().Where(
|
||||
clsType => !clsType.IsAbstract && clsType.IsSubclassOf(typeof(ModifierMagnitudeCalculation)) && outFilter.IndexOf(clsType.Name) < 0
|
||||
);
|
||||
subTypeFromScriptableMMC.AddRange(lst);
|
||||
}
|
||||
var dir = "Assets/GameScript/HotFix/GAS.UnityExt/Runtime/CodeGen";// gasSetting.LogicCodeGeneratePath;
|
||||
CodeGenScriptableMMCInjecter.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_ScriptableMMCExt.cs"),
|
||||
allTypes = subTypeFromScriptableMMC
|
||||
});
|
||||
CodeGenScriptableMMCSerialization.GenCode(new CodeGenInfo()
|
||||
{
|
||||
codeGenNameSpace = "JNGame.GAS",
|
||||
outputPath = Path.Combine(dir, "CodeGen_ScriptableMMCExtSerialization.cs"),
|
||||
allTypes = subTypeFromScriptableMMC
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GAS纯净模式二进制配置生成入口
|
||||
/// </summary>
|
||||
[MenuItem("EX-GAS/PureMode/GenData/All")]
|
||||
public static void GenData()
|
||||
{
|
||||
GenGAData();
|
||||
GenGEData();
|
||||
GenASCPresetData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GAS纯净模式 - 二进制Ability配置生成入口
|
||||
/// </summary>
|
||||
/// <param name="genPath"></param>
|
||||
[MenuItem("EX-GAS/PureMode/GenData/AbilityAsset")]
|
||||
public static void GenGAData()
|
||||
{
|
||||
|
||||
string saveDir = GASSettingAsset.Setting.GASBinaryAssetPath;
|
||||
var guids = AssetDatabase.FindAssets($"t:{nameof(TimelineAbilityAsset)}");
|
||||
int exportCount = 0;
|
||||
int failedCount = 0;
|
||||
Dictionary<string, byte[]> allGAAssets = new Dictionary<string, byte[]>();
|
||||
Serializer serializer = new Serializer();
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
exportCount++;
|
||||
// 加载Scriptable配置,并且序列化为bytes
|
||||
var timelineAsset = AssetDatabase.LoadAssetAtPath<TimelineAbilityAsset>(path);
|
||||
// var bytes = timelineAsset.ToBytes();
|
||||
// // 反序列为纯净模式配置,并再次序列化为二进制数据,检查两次序列化数据是否一致
|
||||
// var newInfo = AbilityAssetTool.Deserialize(bytes);
|
||||
// var newBytes = AbilityAssetTool.Serialize(newInfo);
|
||||
// bool isSame = newBytes.EqualsEx(bytes);
|
||||
// if (!isSame)
|
||||
// {
|
||||
// Debug.LogError($"TimelineAsset Serialize Failed {path}");
|
||||
// ++failedCount;
|
||||
// continue;
|
||||
// }
|
||||
// allGAAssets.Add(timelineAsset.name, bytes);
|
||||
}
|
||||
// 整合成一个二进制文件
|
||||
serializer.Write((ushort)allGAAssets.Count);
|
||||
foreach (var iter in allGAAssets)
|
||||
{
|
||||
serializer.Append(iter.Value);
|
||||
}
|
||||
FileUtil.SaveFile(Path.Combine(saveDir, "GA_Database.bytes"), serializer.CopyData());
|
||||
Debug.Log($"Export Done count= {exportCount}, Failed count = {failedCount}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GAS纯净模式 - 二进制GE配置生成入口
|
||||
/// </summary>
|
||||
/// <param name="genPath"></param>
|
||||
[MenuItem("EX-GAS/PureMode/GenData/GEAsset")]
|
||||
public static void GenGEData()
|
||||
{
|
||||
string saveDir = GASSettingAsset.Setting.GASBinaryAssetPath;
|
||||
var guids = AssetDatabase.FindAssets($"t:{nameof(GameplayEffectAsset)}");
|
||||
int exportCount = 0;
|
||||
int failedCount = 0;
|
||||
Dictionary<string, byte[]> allGEAssets = new Dictionary<string, byte[]>();
|
||||
Serializer serializer = new Serializer();
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
exportCount++;
|
||||
// 加载Scriptable配置,并且序列化为bytes
|
||||
var geAsset = AssetDatabase.LoadAssetAtPath<GameplayEffectAsset>(path);
|
||||
// var bytes = geAsset.ToBytes();
|
||||
// // 反序列为纯净模式配置,并再次序列化为二进制数据,检查两次序列化数据是否一致
|
||||
// var newInfo = GameEffectAssetSerializationTool.Deserialize(bytes);
|
||||
// var newBytes = GameEffectAssetSerializationTool.Serialize(newInfo);
|
||||
// bool isSame = newBytes.EqualsEx(bytes);
|
||||
// if (!isSame)
|
||||
// {
|
||||
// Debug.LogError($"TimelineAsset Serialize Failed {path}");
|
||||
// ++failedCount;
|
||||
// continue;
|
||||
// }
|
||||
// allGEAssets.Add(geAsset.name, bytes);
|
||||
}
|
||||
// 整合成一个二进制文件
|
||||
serializer.Write((ushort)allGEAssets.Count);
|
||||
foreach (var iter in allGEAssets)
|
||||
{
|
||||
serializer.Append(iter.Value);
|
||||
}
|
||||
FileUtil.SaveFile(Path.Combine(saveDir, "GE_Database.bytes"), serializer.CopyData());
|
||||
Debug.Log($"Export Done count= {exportCount}, Failed count = {failedCount}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GAS纯净模式 - 二进制GASPreset配置生成入口
|
||||
/// </summary>
|
||||
[MenuItem("EX-GAS/PureMode/GenData/ASCPreset")]
|
||||
public static void GenASCPresetData()
|
||||
{
|
||||
string saveDir = GASSettingAsset.Setting.GASBinaryAssetPath;
|
||||
var guids = AssetDatabase.FindAssets($"t:{nameof(AbilitySystemComponentPreset)}");
|
||||
int exportCount = 0;
|
||||
int failedCount = 0;
|
||||
Dictionary<string, byte[]> allASCPresets = new Dictionary<string, byte[]>();
|
||||
Serializer serializer = new Serializer();
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
exportCount++;
|
||||
// 加载Scriptable配置,并且序列化为bytes
|
||||
var ascPresetAsset = AssetDatabase.LoadAssetAtPath<AbilitySystemComponentPreset>(path);
|
||||
// var bytes = ascPresetAsset.ToBytes();
|
||||
// // 反序列为纯净模式配置,并再次序列化为二进制数据,检查两次序列化数据是否一致
|
||||
// var newInfo = AbilitySystemComponentPresetConverter.Deserialize(bytes);
|
||||
// var newBytes = AbilitySystemComponentPresetConverter.Serialize(newInfo);
|
||||
// bool isSame = newBytes.EqualsEx(bytes);
|
||||
// if (!isSame)
|
||||
// {
|
||||
// Debug.LogError($"TimelineAsset Serialize Failed {path}");
|
||||
// ++failedCount;
|
||||
// continue;
|
||||
// }
|
||||
// allASCPresets.Add(ascPresetAsset.name, bytes);
|
||||
}
|
||||
// 整合成一个二进制文件
|
||||
serializer.Write((ushort)allASCPresets.Count);
|
||||
foreach (var iter in allASCPresets)
|
||||
{
|
||||
serializer.Append(iter.Value);
|
||||
}
|
||||
FileUtil.SaveFile(Path.Combine(saveDir, "ASC_Database.bytes"), serializer.CopyData());
|
||||
Debug.Log($"Export Done count= {exportCount}, Failed count = {failedCount}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a832c435436925438d1e3859b98902c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user