From 3429df6e491f4aad6a58f422a31de5103b7ea168 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Tue, 7 Oct 2025 15:45:12 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=87=86=E5=A4=87=E7=BC=96=E5=86=99Scriptabl?= =?UTF-8?q?eEnum=E7=9A=84Helper2.=E5=87=86=E5=A4=87Judgement=E7=9A=84?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E5=88=9B=E5=BB=BA=E4=BD=93=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditiorContent/ProjectCreateHelper.cs | 73 ++++++++++--------- .../Framework/EditiorContent/TimelineItem.cs | 2 +- Assets/Scripts/Framework/ScriptableObject.cs | 10 +++ 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs b/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs index 17f65bf..3dfc0b2 100644 --- a/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs +++ b/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs @@ -70,45 +70,52 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1); { foreach (var type in asm.GetTypes()) { - if (typeof(ScriptableObject).IsAssignableFrom(type) == false) - continue; - var scriptCalls = (from info in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) - where info is MethodInfo - where info.GetCustomAttribute(false) != null - select info as MethodInfo).ToList(); - var typeName = type.Name; - if (typeName.Contains('`')) - { - typeName = typeName[..typeName.LastIndexOf('`')]; - } - string fileHeader = $"{typeName}.helper" + style switch + // Functions + if (typeof(ScriptableObject).IsAssignableFrom(type)) { - ProjectDefaultFileStyle.PY => ",py", - _ => ".h" - }; - using var fs = File.AppendText((toolDir | fileHeader).GetFullPath()); - switch (style) - { - case ProjectDefaultFileStyle.CPP: - WriteCPPClassBase(fs, type); - break; - case ProjectDefaultFileStyle.PY: - break; - } - foreach (var methodInfo in scriptCalls) - { - var data = methodInfo.GetCustomAttribute(false); + var scriptCalls = (from info in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) + where info is MethodInfo + where info.GetCustomAttribute(false) != null + select info as MethodInfo).ToList(); + var typeName = type.Name; + if (typeName.Contains('`')) + { + typeName = typeName[..typeName.LastIndexOf('`')]; + } + string fileHeader = $"{typeName}.helper" + style switch + { + ProjectDefaultFileStyle.PY => ",py", + _ => ".h" + }; + using var fs = File.AppendText((toolDir | fileHeader).GetFullPath()); switch (style) { + case ProjectDefaultFileStyle.CPP: + WriteCPPClassBase(fs, type); + break; case ProjectDefaultFileStyle.PY: - WritePythonStyleFunction(fs, methodInfo.Name, from param in methodInfo.GetParameters() select param.Name, data.Description); - break; - default: - WriteCPPStyleFunction(fs, methodInfo.Name, from param in methodInfo.GetParameters() select param.Name, data.Description); break; } - } - } + foreach (var methodInfo in scriptCalls) + { + var data = methodInfo.GetCustomAttribute(false); + switch (style) + { + case ProjectDefaultFileStyle.PY: + WritePythonStyleFunction(fs, methodInfo.Name, from param in methodInfo.GetParameters() select param.Name, data.Description); + break; + default: + WriteCPPStyleFunction(fs, methodInfo.Name, from param in methodInfo.GetParameters() select param.Name, data.Description); + break; + } + } + } + // Enums + if (typeof(Enum).IsAssignableFrom(type)&& type.GetCustomAttribute(false) != null) + { + // TODO + } + } } } } diff --git a/Assets/Scripts/Framework/EditiorContent/TimelineItem.cs b/Assets/Scripts/Framework/EditiorContent/TimelineItem.cs index 3c54530..816f4aa 100644 --- a/Assets/Scripts/Framework/EditiorContent/TimelineItem.cs +++ b/Assets/Scripts/Framework/EditiorContent/TimelineItem.cs @@ -88,7 +88,7 @@ namespace Demo.Editor.UI if (Mathf.Approximately(durationX, durationY)) { from = (durationX - clip.x) / left2rightDuration; - to = Mathf.Max(from + 0.1f, EditorController.instance.SongOffset); + to = Mathf.Max(from + 0.1f, (EditorController.instance.SongOffset - clip.x) / left2rightDuration); } else { diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index 4f01187..51ec24c 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -30,6 +30,16 @@ namespace Demo } } + [System.AttributeUsage(AttributeTargets.Enum, Inherited = true, AllowMultiple = false)] + public sealed class ScriptableEnumAttribute : Attribute + { + public string Description; + public ScriptableEnumAttribute(string description) + { + this.Description = description; + } + } + public static class ScriptCallUtility { // 解析函数调用的方法,支持 with 子句