1.解决了Track面向的问题2.新增Surface类型的Spline渲染器3.新增with后缀表达式
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -32,7 +32,13 @@ namespace Demo.Editor
|
|||||||
baseTypeName = baseTypeName[..baseTypeName.LastIndexOf('`')];
|
baseTypeName = baseTypeName[..baseTypeName.LastIndexOf('`')];
|
||||||
}
|
}
|
||||||
stream.Write($"#include \"{baseTypeName}.helper.h\"\n\n#define {typeName}\n\n");
|
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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Convention;
|
using Convention;
|
||||||
using Convention.Internal;
|
|
||||||
using Convention.WindowsUI;
|
using Convention.WindowsUI;
|
||||||
using Convention.WindowsUI.Variant;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
@@ -63,7 +59,7 @@ namespace Demo.Editor.UI
|
|||||||
|
|
||||||
public void ResizeOnTimeline()
|
public void ResizeOnTimeline()
|
||||||
{
|
{
|
||||||
if(IsSetup==false)
|
if (IsSetup == false)
|
||||||
{
|
{
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
return;
|
return;
|
||||||
@@ -76,7 +72,7 @@ namespace Demo.Editor.UI
|
|||||||
Vector3 minPosition = DragAreaInternal.rect.min - DragObjectInternal.rect.min;
|
Vector3 minPosition = DragAreaInternal.rect.min - DragObjectInternal.rect.min;
|
||||||
Vector3 maxPosition = DragAreaInternal.rect.max - DragObjectInternal.rect.max;
|
Vector3 maxPosition = DragAreaInternal.rect.max - DragObjectInternal.rect.max;
|
||||||
|
|
||||||
if(DragObjectInternal.localPosition.y< minPosition.y|| DragObjectInternal.localPosition.y > maxPosition.y)
|
if (DragObjectInternal.localPosition.y < minPosition.y || DragObjectInternal.localPosition.y > maxPosition.y)
|
||||||
{
|
{
|
||||||
RawButton.gameObject.SetActive(false);
|
RawButton.gameObject.SetActive(false);
|
||||||
return;
|
return;
|
||||||
@@ -92,7 +88,7 @@ namespace Demo.Editor.UI
|
|||||||
if (Mathf.Approximately(durationX, durationY))
|
if (Mathf.Approximately(durationX, durationY))
|
||||||
{
|
{
|
||||||
from = (durationX - clip.x) / left2rightDuration;
|
from = (durationX - clip.x) / left2rightDuration;
|
||||||
to = from + 0.1f;
|
to = Mathf.Max(from + 0.1f, EditorController.instance.SongOffset);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,22 +32,93 @@ namespace Demo
|
|||||||
|
|
||||||
public static class ScriptCallUtility
|
public static class ScriptCallUtility
|
||||||
{
|
{
|
||||||
// 解析函数调用的方法
|
// 解析函数调用的方法,支持 with 子句
|
||||||
public static (string functionName, string[] arguments) ParseFunctionCall(string input)
|
public static (string functionName, string[] arguments, Dictionary<string, string> withVariables) ParseFunctionCall(string input)
|
||||||
{
|
{
|
||||||
// 匹配函数名和参数部分
|
// 匹配函数名和参数部分,以及可选的 with 子句
|
||||||
Match match = Regex.Match(input, @"^(\w+)\s*\(\s*(.*?)\s*\)\s*;?$");
|
Match match = Regex.Match(input, @"^(\w+)\s*\(\s*(.*?)\s*\)\s*(?:\s+with\s*\(\s*(.*?)\s*\))?\s*;?$");
|
||||||
|
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
return (null, new string[0]);
|
return (null, new string[0], new Dictionary<string, string>());
|
||||||
|
|
||||||
string functionName = match.Groups[1].Value;
|
string functionName = match.Groups[1].Value;
|
||||||
string argumentsString = match.Groups[2].Value;
|
string argumentsString = match.Groups[2].Value;
|
||||||
|
string withString = match.Groups[3].Value;
|
||||||
|
|
||||||
// 解析参数数组
|
// 解析参数数组
|
||||||
string[] arguments = ParseArguments(argumentsString);
|
string[] arguments = ParseArguments(argumentsString);
|
||||||
|
|
||||||
return (functionName, arguments);
|
// 解析 with 子句的变量
|
||||||
|
Dictionary<string, string> withVariables = new Dictionary<string, string>();
|
||||||
|
if (!string.IsNullOrWhiteSpace(withString))
|
||||||
|
{
|
||||||
|
withVariables = ParseWithClause(withString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (functionName, arguments, withVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 with 子句的方法
|
||||||
|
private static Dictionary<string, string> ParseWithClause(string withString)
|
||||||
|
{
|
||||||
|
var variables = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(withString))
|
||||||
|
return variables;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (i < withString.Length)
|
||||||
|
{
|
||||||
|
// 跳过空白字符
|
||||||
|
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (i >= withString.Length)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// 解析变量名
|
||||||
|
int nameStart = i;
|
||||||
|
while (i < withString.Length && (char.IsLetterOrDigit(withString[i]) || withString[i] == '_'))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (i == nameStart)
|
||||||
|
break; // 没有找到有效的变量名
|
||||||
|
|
||||||
|
string varName = withString.Substring(nameStart, i - nameStart);
|
||||||
|
|
||||||
|
// 跳过空白字符
|
||||||
|
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
// 检查等号
|
||||||
|
if (i >= withString.Length || withString[i] != '=')
|
||||||
|
break; // 没有找到等号
|
||||||
|
i++; // 跳过等号
|
||||||
|
|
||||||
|
// 跳过空白字符
|
||||||
|
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
// 解析变量值
|
||||||
|
string varValue = ExtractArgument(withString, ref i);
|
||||||
|
variables[varName] = varValue.Trim();
|
||||||
|
|
||||||
|
// 跳过空白字符
|
||||||
|
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
// 检查逗号
|
||||||
|
if (i < withString.Length && withString[i] == ',')
|
||||||
|
{
|
||||||
|
i++; // 跳过逗号
|
||||||
|
}
|
||||||
|
else if (i < withString.Length)
|
||||||
|
{
|
||||||
|
break; // 期望逗号但找到了其他字符
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析参数的方法
|
// 解析参数的方法
|
||||||
@@ -382,7 +453,14 @@ namespace Demo
|
|||||||
}
|
}
|
||||||
throw new ArgumentException("value is end by '}' but not match on any invlid parse");
|
throw new ArgumentException("value is end by '}' but not match on any invlid parse");
|
||||||
}
|
}
|
||||||
return float.Parse(value);
|
try
|
||||||
|
{
|
||||||
|
return float.Parse(value);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new FormatException($"{value} is not support any Parser");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,7 +804,7 @@ namespace Demo
|
|||||||
}
|
}
|
||||||
var exprs = preprocessing.Split(';');
|
var exprs = preprocessing.Split(';');
|
||||||
|
|
||||||
ParseStats ParseCommandAndParamaterWords(int commandIterator, ref string command, ref string[] words)
|
ParseStats ParseCommandAndParamaterWords(int commandIterator, ref string command, ref string[] words, ref Dictionary<string,string> withVariables)
|
||||||
{
|
{
|
||||||
var expr = exprs[commandIterator].Trim();
|
var expr = exprs[commandIterator].Trim();
|
||||||
//空语句
|
//空语句
|
||||||
@@ -745,7 +823,7 @@ namespace Demo
|
|||||||
MethodInvokerCache.Add(this.GetType(), new());
|
MethodInvokerCache.Add(this.GetType(), new());
|
||||||
}
|
}
|
||||||
//函数解析
|
//函数解析
|
||||||
(command, words) = ScriptCallUtility.ParseFunctionCall(expr);
|
(command, words, withVariables) = ScriptCallUtility.ParseFunctionCall(expr);
|
||||||
if (string.IsNullOrEmpty(command))
|
if (string.IsNullOrEmpty(command))
|
||||||
return ParseStats.Continue;
|
return ParseStats.Continue;
|
||||||
for (int i = 0, e = words.Length; i < e; i++)
|
for (int i = 0, e = words.Length; i < e; i++)
|
||||||
@@ -763,7 +841,8 @@ namespace Demo
|
|||||||
{
|
{
|
||||||
string command = null;
|
string command = null;
|
||||||
string[] words = null;
|
string[] words = null;
|
||||||
var stats = ParseCommandAndParamaterWords(commandIterator, ref command, ref words);
|
Dictionary<string, string> withVariables = new();
|
||||||
|
var stats = ParseCommandAndParamaterWords(commandIterator, ref command, ref words,ref withVariables);
|
||||||
if (stats == ParseStats.Continue)
|
if (stats == ParseStats.Continue)
|
||||||
continue;
|
continue;
|
||||||
else if (stats == ParseStats.Break)
|
else if (stats == ParseStats.Break)
|
||||||
@@ -781,13 +860,16 @@ namespace Demo
|
|||||||
// Main Loop
|
// Main Loop
|
||||||
for (int commandIterator = 0; commandIterator < exprs.Length; commandIterator++)
|
for (int commandIterator = 0; commandIterator < exprs.Length; commandIterator++)
|
||||||
{
|
{
|
||||||
|
// Run Stats
|
||||||
string command = null;
|
string command = null;
|
||||||
string[] words = null;
|
string[] words = null;
|
||||||
var stats = ParseCommandAndParamaterWords(commandIterator, ref command, ref words);
|
Dictionary<string, string> withVariables = new();
|
||||||
|
var stats = ParseCommandAndParamaterWords(commandIterator, ref command, ref words, ref withVariables);
|
||||||
if (stats == ParseStats.Continue)
|
if (stats == ParseStats.Continue)
|
||||||
continue;
|
continue;
|
||||||
else if (stats == ParseStats.Break)
|
else if (stats == ParseStats.Break)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Logic
|
// Logic
|
||||||
if (command == "label")
|
if (command == "label")
|
||||||
{
|
{
|
||||||
@@ -808,6 +890,8 @@ namespace Demo
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Functions
|
||||||
var paramsList = (from word in words where string.IsNullOrEmpty(word.Trim()) == false select (object)word.Trim()).ToArray();
|
var paramsList = (from word in words where string.IsNullOrEmpty(word.Trim()) == false select (object)word.Trim()).ToArray();
|
||||||
if (MethodInvokerCache[this.GetType()].TryGetValue(command, out MemberInfo commandInfo) == false)
|
if (MethodInvokerCache[this.GetType()].TryGetValue(command, out MemberInfo commandInfo) == false)
|
||||||
{
|
{
|
||||||
@@ -823,6 +907,23 @@ namespace Demo
|
|||||||
}
|
}
|
||||||
Debug.Log($"in line \"{expr}\" of \"{ScriptPath}\", {command} is try to invoke", this);
|
Debug.Log($"in line \"{expr}\" of \"{ScriptPath}\", {command} is try to invoke", this);
|
||||||
IEnumerator resultEnumerator = null;
|
IEnumerator resultEnumerator = null;
|
||||||
|
|
||||||
|
// 处理 with 子句:保存当前变量状态并设置新变量
|
||||||
|
Dictionary<string, float> originalVariables = new Dictionary<string, float>();
|
||||||
|
if (withVariables.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var kvp in withVariables)
|
||||||
|
{
|
||||||
|
// 保存原始值(如果存在)
|
||||||
|
if (ScriptContextSpace.TryGetValue(kvp.Key, out var originalValue))
|
||||||
|
{
|
||||||
|
originalVariables[kvp.Key] = originalValue;
|
||||||
|
}
|
||||||
|
// 设置新值
|
||||||
|
ScriptContextSpace[kvp.Key] = Parse(kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 调用成功
|
// 调用成功
|
||||||
@@ -852,7 +953,26 @@ namespace Demo
|
|||||||
Debug.LogException(ex, this);
|
Debug.LogException(ex, this);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return resultEnumerator;
|
yield return resultEnumerator;
|
||||||
|
|
||||||
|
// 恢复 with 子句中的变量状态
|
||||||
|
if (withVariables.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var kvp in withVariables)
|
||||||
|
{
|
||||||
|
if (originalVariables.ContainsKey(kvp.Key))
|
||||||
|
{
|
||||||
|
// 恢复原始值
|
||||||
|
ScriptContextSpace[kvp.Key] = originalVariables[kvp.Key];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 删除不存在的变量
|
||||||
|
ScriptContextSpace.Remove(kvp.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace Demo.Game
|
|||||||
{ $"{nameof(SplineHeadObject)}",SplineHeadObject.Make},
|
{ $"{nameof(SplineHeadObject)}",SplineHeadObject.Make},
|
||||||
{ $"{nameof(SplineTrackRenderer)}",SplineTrackRenderer.Make},
|
{ $"{nameof(SplineTrackRenderer)}",SplineTrackRenderer.Make},
|
||||||
{ $"{nameof(SplineTubeRenderer)}",SplineTubeRenderer.Make},
|
{ $"{nameof(SplineTubeRenderer)}",SplineTubeRenderer.Make},
|
||||||
|
{ $"{nameof(SplineSurfaceRenderer)}",SplineTubeRenderer.Make},
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Dictionary<string, Func<ScriptableObject>> JudgementInstantiate = new()
|
public static Dictionary<string, Func<ScriptableObject>> JudgementInstantiate = new()
|
||||||
|
|||||||
22
Assets/Scripts/MoreSpline/SplineSurfaceRenderer.cs
Normal file
22
Assets/Scripts/MoreSpline/SplineSurfaceRenderer.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using Convention;
|
||||||
|
using Dreamteck.Splines;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Demo.Game
|
||||||
|
{
|
||||||
|
public class SplineSurfaceRenderer : BasicSplineRenderer<SurfaceGenerator>
|
||||||
|
{
|
||||||
|
public static SplineTrackRenderer Make()
|
||||||
|
{
|
||||||
|
return new GameObject().AddComponent<SplineTrackRenderer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerator LoadScript(string script)
|
||||||
|
{
|
||||||
|
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
||||||
|
yield return base.LoadScript(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/MoreSpline/SplineSurfaceRenderer.cs.meta
Normal file
11
Assets/Scripts/MoreSpline/SplineSurfaceRenderer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: acff355a0ae693443abc68f727f6d0ab
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -6,44 +6,17 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Demo.Game
|
namespace Demo.Game
|
||||||
{
|
{
|
||||||
public class SplineTrackRenderer : BasicSplineRenderer<SplineRenderer>
|
public class SplineTrackRenderer : BasicSplineRenderer<PathGenerator>
|
||||||
{
|
{
|
||||||
public static SplineTrackRenderer Make()
|
public static SplineTrackRenderer Make()
|
||||||
{
|
{
|
||||||
return new GameObject().AddComponent<SplineTrackRenderer>();
|
return new GameObject().AddComponent<SplineTrackRenderer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public const bool DefaultIsAutoOrient = false;
|
|
||||||
[Content] public bool IsAutoOrient = DefaultIsAutoOrient;
|
|
||||||
|
|
||||||
public override IEnumerator LoadScript(string script)
|
public override IEnumerator LoadScript(string script)
|
||||||
{
|
{
|
||||||
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
||||||
yield return base.LoadScript(script);
|
yield return base.LoadScript(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetupMeshGenerator(SplineRenderer meshGenerater)
|
|
||||||
{
|
|
||||||
base.SetupMeshGenerator(meshGenerater);
|
|
||||||
meshGenerater.autoOrient = IsAutoOrient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IEnumerator UnloadScript()
|
|
||||||
{
|
|
||||||
yield return base.UnloadScript();
|
|
||||||
// Reset
|
|
||||||
{
|
|
||||||
IsAutoOrient = DefaultIsAutoOrient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 开启自动面向摄像机的功能
|
|
||||||
/// </summary>
|
|
||||||
[ScriptableCall(@"开启自动面向摄像机的功能")]
|
|
||||||
public void EnableAutoOrient()
|
|
||||||
{
|
|
||||||
IsAutoOrient = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b233390febd1b6548b41142aba2c5d72
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 8cbf3bec3a6187e4bbcb9f484659d579
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Reference in New Issue
Block a user