完成Note预制体的创建体系

This commit is contained in:
2025-10-08 00:35:50 +08:00
parent 3429df6e49
commit ed0dc0b523
9 changed files with 235 additions and 91 deletions

View File

@@ -4,8 +4,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using Convention;
using Unity.VisualScripting;
using UnityEngine;
namespace Demo.Editor
{
@@ -20,42 +18,56 @@ namespace Demo.Editor
private static void WriteCPPClassBase(StreamWriter stream, Type currentType)
{
if (currentType == typeof(ScriptableObject))
return;
string typeName = currentType.Name;
if (typeName.Contains('`'))
{
typeName = typeName[..typeName.LastIndexOf('`')];
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in asm.GetTypes())
{
// Functions
if (typeof(ScriptableObject).IsAssignableFrom(type))
{
string typeName = type.Name;
if (typeName.Contains('`'))
{
typeName = typeName[..typeName.LastIndexOf('`')];
}
stream.WriteLine($"#define {typeName}");
}
}
}
stream.Write(@"/*
<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󽫻<EFBFBD>ԭ
e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
*/");
stream.Write($"#define with(...)\n\n");
return;
}
string baseTypeName = currentType.BaseType.Name;
if (baseTypeName.Contains('`'))
{
baseTypeName = baseTypeName[..baseTypeName.LastIndexOf('`')];
}
stream.Write($"#include \"{baseTypeName}.helper.h\"\n\n#define {typeName}\n\n");
stream.Write(@"/*
<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󽫻<EFBFBD>ԭ
e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
*/");
stream.Write($"#define with(...)\n\n");
stream.Write($"#include \"{baseTypeName}.helper.h\"\n\n");
}
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
{
if (name == nameof(ScriptableObject.LoadSubScript))
{
if (name == nameof(ScriptableObject.LoadSubScript))
{
stream.WriteLine("#define __build_in_pragma #");
stream.WriteLine("#define __build_in_to_text(x) #x");
stream.Write("/*\n" + description + "\n*/\n");
stream.Write($"#define {name}({string.Join(',', paramList)}) __build_in_pragma include {paramList.ToArray()[1]}\n\n");
//stream.Write($"#define {name}({string.Join(',', paramList)})\n\n");
}
else
{
stream.Write("/*\n" + description + "\n*/\n");
stream.Write($"#define {name}({string.Join(',', paramList)}) \n\n");
}
}
else
{
stream.Write("/*\n" + description + "\n*/\n");
stream.Write($"#define {name}({string.Join(',', paramList)}) \n\n");
}
}
public static void CreateHelperFiles(string dir, ProjectDefaultFileStyle style = ProjectDefaultFileStyle.CPP)

View File

@@ -120,12 +120,33 @@ namespace Demo.Game
// Setup Game Rules (Main)
if (Editor.EditorController.instance.MainGameController == this)
{
ScriptableObject.FastScriptableObjectTypen = content.ScriptableObjectTypen;
ScriptableObject.IsAutoPlay = content.IsAutoPlay;
ScriptableObject.OneBarTime = 60.0f / (float)MainConfig.FindItem(nameof(Editor.EditorController.BPM), Editor.EditorController.instance.BPM);
SongOffset = (float)MainConfig.FindItem(nameof(SongOffset), SongOffset);
SetupSongDuration = GameContent.instance.SetupSongDuration;
SetSongCurrentTime = GameContent.instance.SetSongCurrentTime;
// Config ScriptableObject
{
ScriptableObject.FastScriptableObjectTypen = content.ScriptableObjectTypen;
ScriptableObject.IsAutoPlay = content.IsAutoPlay;
ScriptableObject.OneBarTime = 60.0f / (float)MainConfig.FindItem(nameof(Editor.EditorController.BPM), Editor.EditorController.instance.BPM);
}
// Default IInteraction
{
IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest),
IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest);
IInteraction.DefaultInteractableScoreIntervalLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractableScoreIntervalLength),
IInteraction.DefaultInteractableScoreIntervalLength);
IInteraction.DefaultInteractiveLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractiveLength),
IInteraction.DefaultInteractiveLength);
IInteraction.DefaultVisibleLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultVisibleLength),
IInteraction.DefaultVisibleLength);
}
// Config Game
{
SongOffset = (float)MainConfig.FindItem(nameof(SongOffset), SongOffset);
SetupSongDuration = GameContent.instance.SetupSongDuration;
SetSongCurrentTime = GameContent.instance.SetSongCurrentTime;
}
}
// Setup Game Rules
{

View File

@@ -43,6 +43,11 @@ namespace Demo.Game
public void EnableScript(string sourcePath, string scriptPath, GameController parent)
{
AllScriptableObjectCounter = 0;
if (AllScriptableObjectCounterHierarchyItem == null)
{
AllScriptableObjectCounterHierarchyItem = HierarchyWindow.instance.CreateRootItemEntryWithBinders(typeof(ScriptableObject))[0];
}
base.EnableScript(sourcePath, scriptPath, nameof(RootObject), null);
RootGameController = parent;
}

View File

@@ -618,6 +618,8 @@ namespace Demo
// Hierarchy
public PropertiesWindow.ItemEntry MyHierarchyItem;
public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem;
public static int AllScriptableObjectCounter = 0;
// Cache
@@ -1003,6 +1005,11 @@ namespace Demo
{
yield break;
}
// 增数
{
AllScriptableObjectCounter++;
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}";
}
yield return ParseScript2Expr(script);
IsEnableUpdate = true;
}
@@ -1040,6 +1047,9 @@ namespace Demo
this.name = "<Unload>";
// 清理Cache
DDTCache.Clear();
// 减数
AllScriptableObjectCounter--;
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}";
}
}
}