临时提交

This commit is contained in:
PC-20230316NUNE\Administrator
2024-10-21 20:02:19 +08:00
parent 930911e7df
commit e9c01842f0
206 changed files with 14468 additions and 21348 deletions

View File

@@ -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
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6427711364f941d58000a7c3df90315e
timeCreated: 1729496613