1.完成控制流label/goto的使用2.升级Parse解析器3.Judgement的还原依然存在问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -8,6 +9,7 @@ using System.Text.RegularExpressions;
|
||||
using Convention;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Demo.Game;
|
||||
using Flee.PublicTypes;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Profiling;
|
||||
using UnityEngine;
|
||||
@@ -374,10 +376,11 @@ namespace Demo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上下文系统
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
// 上下文系统
|
||||
|
||||
[Content] public Dictionary<string, float> ScriptContextSpace = new();
|
||||
|
||||
public bool GetCompleteScriptContext(string key, out float value)
|
||||
@@ -391,6 +394,19 @@ namespace Demo
|
||||
return true;
|
||||
}
|
||||
|
||||
public void GetCompleteScriptContext(ref Dictionary<string, float> context)
|
||||
{
|
||||
var current = this;
|
||||
while (current != null)
|
||||
{
|
||||
foreach (var key in current.ScriptContextSpace.Keys)
|
||||
{
|
||||
context[key] = current.ScriptContextSpace[key];
|
||||
}
|
||||
current = current.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置局部上下文变量,将会传递给子物体使用
|
||||
/// </summary>
|
||||
@@ -405,16 +421,28 @@ namespace Demo
|
||||
")]
|
||||
public void SetContext(string name, string value)
|
||||
{
|
||||
ScriptContextSpace[name] = float.Parse(value);
|
||||
ScriptContextSpace[name] = Parse(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数值解析工具
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
// 数值解析工具
|
||||
|
||||
private readonly Dictionary<string, DDT> DDTCache = new();
|
||||
private ExpressionContext ExpressionParserCreater()
|
||||
{
|
||||
ExpressionContext context = new();
|
||||
context.Imports.AddType(typeof(Mathf));
|
||||
Dictionary<string, float> vars = new();
|
||||
GetCompleteScriptContext(ref vars);
|
||||
foreach (var item in vars)
|
||||
{
|
||||
context.Variables[item.Key] = item.Value;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
public static float OneBarTime = 1;
|
||||
|
||||
/// <summary>
|
||||
@@ -428,6 +456,10 @@ namespace Demo
|
||||
public float Parse(string value)
|
||||
{
|
||||
value = value.Trim();
|
||||
if(value.StartsWith("\"")&&value.EndsWith("\""))
|
||||
{
|
||||
value = value[1..^1];
|
||||
}
|
||||
if (TimePoints.TryGetValue(value, out var result))
|
||||
return result;
|
||||
if (GetCompleteScriptContext(value, out result))
|
||||
@@ -435,15 +467,19 @@ namespace Demo
|
||||
if(value.EndsWith(']'))
|
||||
{
|
||||
{
|
||||
Regex regex = new(@"^(.+)\[(\d+)\]$");
|
||||
Regex regex = new(@"^(.+)\[(.+)\]$");
|
||||
var match = regex.Match(value);
|
||||
if (match.Success)
|
||||
{
|
||||
if (FindWithPath(match.Groups[1].Value) is DDT ddt)
|
||||
{
|
||||
DDTCache[match.Groups[1].Value] = ddt;
|
||||
}
|
||||
return DDTCache[match.Groups[1].Value].Datas[int.Parse(match.Groups[2].Value)];
|
||||
return (FindWithPath(match.Groups[1].Value) as DDT).Datas[(int)this.Parse(match.Groups[2].Value)];
|
||||
}
|
||||
}
|
||||
{
|
||||
Regex regex = new(@"^(.+)\[\]$");
|
||||
var match = regex.Match(value);
|
||||
if (match.Success)
|
||||
{
|
||||
return (FindWithPath(match.Groups[1].Value) as DDT).Datas.Count;
|
||||
}
|
||||
}
|
||||
throw new ArgumentException("value is end by ']' but not match on any invlid parse");
|
||||
@@ -465,23 +501,34 @@ namespace Demo
|
||||
}
|
||||
try
|
||||
{
|
||||
return float.Parse(value);
|
||||
if (float.TryParse(value, out var _result))
|
||||
return _result;
|
||||
else
|
||||
return ExpressionParserCreater().CompileGeneric<float>(value).Evaluate();
|
||||
}
|
||||
catch
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new FormatException($"{value} is not support any Parser");
|
||||
throw new FormatException($"{value} is not support any Parser", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected T ConvertValue<T>(string str)
|
||||
{
|
||||
return ConventionUtility.convert_xvalue<T>(str);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 先天支持的工具函数
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
// 先天支持的工具函数
|
||||
|
||||
[Content, SerializeField] private Vector3
|
||||
EnterGameLocalPosition = Vector3.zero,
|
||||
EnterGameEulerAngles = Vector3.zero,
|
||||
EnterGameLocalScaling = Vector3.one;
|
||||
[Content, SerializeField] private bool IsSetObjectDisable = false;
|
||||
|
||||
/// <summary>
|
||||
/// 设置坐标
|
||||
@@ -538,13 +585,6 @@ namespace Demo
|
||||
EnterGameLocalScaling = new(Parse(x), Parse(y), Parse(z));
|
||||
}
|
||||
|
||||
public virtual void ResetEnterGameStatus()
|
||||
{
|
||||
transform.localPosition = EnterGameLocalPosition;
|
||||
transform.localEulerAngles = EnterGameEulerAngles;
|
||||
transform.localScale = EnterGameLocalScaling;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭该物体,
|
||||
/// 在面对如多Game场景时关闭某些GameWorld中默认存在的全局灯光等场景时非常有用
|
||||
@@ -557,10 +597,24 @@ namespace Demo
|
||||
")]
|
||||
public void SetObjectDisable()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
IsSetObjectDisable = true;
|
||||
}
|
||||
|
||||
private void ResetScriptableObjectEnterGameStatus()
|
||||
{
|
||||
transform.localPosition = EnterGameLocalPosition;
|
||||
transform.localEulerAngles = EnterGameEulerAngles;
|
||||
transform.localScale = EnterGameLocalScaling;
|
||||
if (IsSetObjectDisable)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UpdatePerFrame相关
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
[Content] public int UpdatePerFrame = 1;
|
||||
@@ -584,47 +638,13 @@ namespace Demo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>使用<see cref="ScriptableCallAttribute"/>标记可编辑脚本所能够调用的函数,并附加注释</para>
|
||||
/// <para>使用<see cref="DefaultScriptAttribute"/>标记派生类,并附加默认模板</para>
|
||||
/// EnableScript相关
|
||||
/// </summary>
|
||||
public partial class ScriptableObject : SerializedMonoBehaviour, IHierarchyItemClickEventListener
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
|
||||
public static Dictionary<string, Type> FastScriptableObjectTypen = new();
|
||||
public static bool IsAutoPlay = false;
|
||||
|
||||
public string SourcePath = "";
|
||||
public string ScriptName = "";
|
||||
public string ScriptPath;
|
||||
public string ScriptTypename;
|
||||
private bool isEnableScript = false;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public ProfilerMarker s_PreparePerfMarker;
|
||||
#endif
|
||||
public ScriptableObject Parent;
|
||||
|
||||
public RootObject GetRoot()
|
||||
{
|
||||
if (Parent == null)
|
||||
return this as RootObject;
|
||||
if (Parent is RootObject result)
|
||||
return result;
|
||||
else return Parent.GetRoot();
|
||||
}
|
||||
|
||||
public List<ScriptableObject> Childs = new();
|
||||
|
||||
// Hierarchy
|
||||
|
||||
public PropertiesWindow.ItemEntry MyHierarchyItem;
|
||||
public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem;
|
||||
public static int AllScriptableObjectCounter = 0;
|
||||
|
||||
// Cache
|
||||
|
||||
public static Dictionary<Type, Dictionary<string, MemberInfo>> MethodInvokerCache = new();
|
||||
|
||||
public void EnableScript(string sourcePath, string scriptPath, string scriptType, ScriptableObject parent)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -660,6 +680,57 @@ namespace Demo
|
||||
// parentHierarchyItem.GetPropertyListItem().RefreshChilds();
|
||||
}
|
||||
|
||||
public bool EnsureEnableScript()
|
||||
{
|
||||
if (isEnableScript == false)
|
||||
{
|
||||
Debug.LogError("ScriptableObject is currently disableScript", this);
|
||||
}
|
||||
return isEnableScript;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>使用<see cref="ScriptableCallAttribute"/>标记可编辑脚本所能够调用的函数,并附加注释</para>
|
||||
/// <para>使用<see cref="DefaultScriptAttribute"/>标记派生类,并附加默认模板</para>
|
||||
/// </summary>
|
||||
public partial class ScriptableObject : SerializedMonoBehaviour, IHierarchyItemClickEventListener
|
||||
{
|
||||
|
||||
public static Dictionary<string, Type> FastScriptableObjectTypen = new();
|
||||
public static bool IsAutoPlay = false;
|
||||
|
||||
public string SourcePath = "";
|
||||
public string ScriptName = "";
|
||||
public string ScriptPath;
|
||||
public string ScriptTypename;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public ProfilerMarker s_PreparePerfMarker;
|
||||
#endif
|
||||
public ScriptableObject Parent;
|
||||
|
||||
public RootObject GetRoot()
|
||||
{
|
||||
if (Parent == null)
|
||||
return this as RootObject;
|
||||
if (Parent is RootObject result)
|
||||
return result;
|
||||
else return Parent.GetRoot();
|
||||
}
|
||||
|
||||
public List<ScriptableObject> Childs = new();
|
||||
|
||||
// Hierarchy
|
||||
|
||||
public PropertiesWindow.ItemEntry MyHierarchyItem;
|
||||
public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem;
|
||||
public static int AllScriptableObjectCounter = 0;
|
||||
|
||||
// Cache
|
||||
|
||||
public static Dictionary<Type, Dictionary<string, MemberInfo>> MethodInvokerCache = new();
|
||||
|
||||
public const string RootObjectQuickPath = "project/";
|
||||
|
||||
public ScriptableObject FindWithPath(string path, bool isMustExist = true)
|
||||
@@ -790,8 +861,6 @@ namespace Demo
|
||||
yield return LoadSubScriptAsync(type, path, null);
|
||||
}
|
||||
|
||||
public object DynamicBindingTarget { get; protected set; } = null;
|
||||
|
||||
private enum ParseStats
|
||||
{
|
||||
None,
|
||||
@@ -899,8 +968,8 @@ namespace Demo
|
||||
if (a > b)
|
||||
{
|
||||
commandIterator = commandLabels[words[2]];
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Functions
|
||||
@@ -988,15 +1057,6 @@ namespace Demo
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnsureEnableScript()
|
||||
{
|
||||
if (isEnableScript == false)
|
||||
{
|
||||
Debug.LogError("ScriptableObject is currently disableScript", this);
|
||||
}
|
||||
return isEnableScript;
|
||||
}
|
||||
|
||||
[Content] private bool IsEnableUpdate = false;
|
||||
|
||||
public virtual IEnumerator LoadScript(string script)
|
||||
@@ -1043,10 +1103,9 @@ namespace Demo
|
||||
}
|
||||
this.isEnableScript = false;
|
||||
this.Parent = null;
|
||||
DynamicBindingTarget = null;
|
||||
this.name = "<Unload>";
|
||||
// 清理Cache
|
||||
DDTCache.Clear();
|
||||
//
|
||||
// 减数
|
||||
AllScriptableObjectCounter--;
|
||||
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}";
|
||||
@@ -1099,9 +1158,9 @@ namespace Demo
|
||||
|
||||
}
|
||||
|
||||
protected T ConvertValue<T>(string str)
|
||||
public virtual void ResetEnterGameStatus()
|
||||
{
|
||||
return ConventionUtility.convert_xvalue<T>(str);
|
||||
ResetScriptableObjectEnterGameStatus();
|
||||
}
|
||||
|
||||
public virtual void OnHierarchyItemRightClick(RectTransform item)
|
||||
|
||||
Reference in New Issue
Block a user