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,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();
// 增数
{