1.修复一些错误2.准备专门提供基于距离的spline3.tracydll存在崩溃问题

This commit is contained in:
2025-11-28 17:35:24 +08:00
parent 2a6bc6edf8
commit ee7bd2d800
22 changed files with 1376 additions and 507 deletions

View File

@@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using Convention;
using UnityEngine;
using System;
namespace Demo.Game
{
@@ -29,9 +30,23 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method]
public float At(int index)
{
if (index < 0)
index = Datas.Count + index;
if (index < 0 || index >= Datas.Count)
throw new IndexOutOfRangeException($"{index} is out of [0, {Datas.Count})");
return Datas[index];
}
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
/// </summary>
/// <returns></returns>
[Convention.RScript.Variable.Attr.Method]
public int GetCount()
{
return Datas.Count;
}
public IEnumerator<float> GetEnumerator()
{
return ((IEnumerable<float>)Datas).GetEnumerator();

View File

@@ -2,6 +2,7 @@ using Convention;
using Convention.WindowsUI;
using Convention.WindowsUI.Variant;
using Demo.Game;
using Dreamteck.Splines;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -12,6 +13,7 @@ using UnityEngine.SceneManagement;
namespace Demo.Editor
{
[DefaultExecutionOrder(-9999)]
public class EditorController : MonoSingleton<EditorController>
{
/// <summary>
@@ -43,6 +45,7 @@ namespace Demo.Editor
/// TODO: 替换为Dict<Tex>纹理组,这将用来支持更高的精度
/// </summary>
private Texture2D SpectrumRenderTexture;
private bool IsEnableUpdateSpectrumRenderTexture = false;
private Color backgroundColor = new(0, 0, 0, 0);
private Color waveformColor = new(1, 1, 1, 1);
@@ -150,8 +153,10 @@ namespace Demo.Editor
SpectrumRawImage.texture = SpectrumRenderTexture;
}
}
using (Profiler.BeginZone(nameof(UpdateSpectrumRenderTexture)))
UpdateSpectrumRenderTexture();
if (IsEnableUpdateSpectrumRenderTexture)
using (Profiler.BeginZone(nameof(UpdateSpectrumRenderTexture)))
UpdateSpectrumRenderTexture();
}
private void InjectSongLoadOverCallback(BasicAudioSystem audio)
@@ -370,37 +375,41 @@ namespace Demo.Editor
}));
}
private void RegisterVariableGenerater()
{
// Generate Framework
var generaters = DefaultInstantiate.GetScriptableObjectInstantiate();
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in asm.GetTypes())
{
string filename = Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater.GetTypename(type);
if (Convention.RScript.Variable.RScriptInjectVariableGenerater.AllRScriptInjectVariables.ContainsKey(filename))
continue;
if (generaters.TryGetValue(filename, out var generater))
{
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(type, () => generater(), null, filename).Register();
}
else if (typeof(ScriptableObject).IsAssignableFrom(type))
{
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(type, null, null, filename).Register();
}
}
}
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(typeof(MathExtension.EaseCurveType), null, null,
Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater.GetTypename(typeof(MathExtension.EaseCurveType))).Register();
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(typeof(SplineComputer.SampleMode), null, null,
Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater.GetTypename(typeof(SplineComputer.SampleMode))).Register();
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(typeof(Spline.Type), null, null,
Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater.GetTypename(typeof(Spline.Type))).Register();
}
private void Start()
{
Profiler.AppInfo(Application.productName);
GlobalConfig.ConstConfigFile = "config.easysave";
// Generate Framework
{
var generaters = DefaultInstantiate.GetScriptableObjectInstantiate();
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in asm.GetTypes())
{
string filename = Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater.GetTypename(type);
if (Convention.RScript.Variable.RScriptInjectVariableGenerater.AllRScriptInjectVariables.ContainsKey(filename))
continue;
if (generaters.TryGetValue(filename, out var generater))
{
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(type, () => generater(), null, filename).Register();
Debug.Log($"{filename} register");
}
else if (typeof(ScriptableObject).IsAssignableFrom(type))
{
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(type, null, null, filename).Register();
Debug.Log($"{filename} register");
}
}
}
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(
typeof(MathExtension.EaseCurveType), null, null, nameof(MathExtension.EaseCurveType) + "Getter").Register();
Debug.Log($"{typeof(MathExtension.EaseCurveType)} register");
}
RegisterVariableGenerater();
// Helper Files
ToolFile helperHeaderDir = new ToolFile(PersistentHelperPath);
@@ -450,6 +459,10 @@ namespace Demo.Editor
{
IsLowPerformance = true;
}
else if (arg == "-UpdateSpectrumRenderTexture")
{
IsEnableUpdateSpectrumRenderTexture = true;
}
}
}

View File

@@ -2,12 +2,14 @@ using Convention;
using Convention.RScript;
using Convention.WindowsUI.Variant;
using Demo.Game;
using Dreamteck.Splines;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Unity.VisualScripting;
using UnityEngine;
namespace Demo
@@ -57,6 +59,23 @@ namespace Demo
public MathExtension.EaseCurveType InOutBack => MathExtension.EaseCurveType.InOutBack;
public MathExtension.EaseCurveType Custom => MathExtension.EaseCurveType.Custom;
}
public class SplineComputerSampleModeInstance
{
public static SplineComputerSampleModeInstance instance = new();
public SplineComputer.SampleMode Default => SplineComputer.SampleMode.Default;
public SplineComputer.SampleMode Uniform => SplineComputer.SampleMode.Uniform;
public SplineComputer.SampleMode Optimized => SplineComputer.SampleMode.Optimized;
}
public class SplineTypeInstance
{
public static SplineTypeInstance instance = new();
public Spline.Type Linear => Spline.Type.Linear;
public Spline.Type BSpline => Spline.Type.BSpline;
public Spline.Type CatmullRom => Spline.Type.CatmullRom;
public Spline.Type Bezier => Spline.Type.Bezier;
}
}
public partial class ScriptableObject : IScriptableObject
@@ -324,6 +343,8 @@ namespace Demo
public static Dictionary<string, Type> FastScriptableObjectTypen = new();
public static int AllScriptableObjectCounter = 0;
public bool IsParseScript2Expr { get; private set; } = false;
#region LoadSubScript
/// <summary>
@@ -418,34 +439,64 @@ namespace Demo
#endregion
public static class RandomTool
{
public static float Random(float min,float max)
{
return UnityEngine.Random.Range(min,max);
}
public static float Random(double min,double max)
{
return UnityEngine.Random.Range((float)min, (float)max);
}
}
public class ConsoleTool
{
GameObject gameObject;
public ConsoleTool(GameObject gameObject)
{
this.gameObject = gameObject;
}
public void Log(object obj)
{
Debug.Log(obj);
}
}
public IEnumerator ParseScript2Expr(string script)
{
IsParseScript2Expr = true;
RScriptEngine engine = new();
RScriptImportClass importClass = new()
{
typeof(Mathf),
typeof(UnityEngine.Random),
typeof(RandomTool),
};
RScriptVariables variables = new()
{
{ "this", new() { data = this, type = this.GetType() } },
{ "self", new() { data = this, type = this.GetType() } },
{ nameof(MathExtension.EaseCurveType),new(){ data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } }
{ "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } },
{ nameof(MathExtension.EaseCurveType), new() { data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } },
{ $"Spline{nameof(SplineComputer.SampleMode)}",
new() { data = PrivateType.SplineComputerSampleModeInstance.instance, type = typeof(PrivateType.SplineComputerSampleModeInstance)} },
{ $"Spline{nameof(Spline.Type)}",
new() { data = PrivateType.SplineTypeInstance.instance, type = typeof(PrivateType.SplineTypeInstance)} },
};
// 预设变量会导致问题(当前变量类型在不同命名空间中无法更改)
// foreach (var type in DefaultInstantiate.GetScriptableObjectInstantiate().Keys)
// {
// variables.Add(type, new(type.GetType(), type));
// }
return engine.RunAsync(script, importClass, variables);
foreach (var ir in engine.RunAsync(script, importClass, variables).Yield())
{
// using var _curr_sen = Profiler.BeginZone(engine.context.CurrentSentence.content);
yield return ir;
}
IsParseScript2Expr = false;
}
[Content]
public bool IsScriptApply
{
get; private set;
} = false;
public bool IsScriptApply { get; private set; } = false;
public enum TickType
{
@@ -463,7 +514,7 @@ namespace Demo
if (gameObject.activeInHierarchy == false)
return;
using (Profiler.BeginZone($"{GetType().Name}.Update"))
using (Profiler.BeginZone($"{GetType().Name}.ScriptUpdate"))
{
if (tickType == TickType.Reset)
{
@@ -514,6 +565,11 @@ namespace Demo
{
yield break;
}
// 等待自身脚本解析完毕
while(this.IsParseScript2Expr)
{
yield return null;
}
yield return DoSomethingDuringApplyScript();
// 增数
{