diff --git a/.gitmodules b/.gitmodules index ab70fda..c7842b4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "Assets/Convention"] path = Assets/Convention url = http://www.liubai.site:3000/ninemine/Convention-Unity.git +[submodule "Assets/Plugins/Flee"] + path = Assets/Plugins/Flee + url = http://www.liubai.site:3000/ninemine/Flee.git diff --git a/Assets/Plugins/Flee b/Assets/Plugins/Flee new file mode 160000 index 0000000..a09b3c1 --- /dev/null +++ b/Assets/Plugins/Flee @@ -0,0 +1 @@ +Subproject commit a09b3c1eb1f6b2ea840540d1e46737de6573560a diff --git a/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs b/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs index ba0fa77..8a73813 100644 --- a/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs +++ b/Assets/Scripts/Framework/EditiorContent/ProjectCreateHelper.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using Convention; +using UnityEngine; namespace Demo.Editor { @@ -18,9 +19,12 @@ namespace Demo.Editor private static void WriteCPPClassBase(StreamWriter stream, Type currentType) { if (currentType == typeof(ScriptableObject)) - { - - foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) + { + // 绘制工具宏 + stream.WriteLine("#define __build_in_pragma #"); + stream.WriteLine("#define __build_in_to_text(x) #x"); + // 绘制类定义标识符 + foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in asm.GetTypes()) { @@ -36,11 +40,31 @@ namespace Demo.Editor } } } - - stream.Write(@"/* + // 绘制Mathf + foreach (var method in typeof(Mathf).GetMethods()) + { + stream.WriteLine($"#define {method.Name}({string.Join(',', from param in method.GetParameters() select param.Name)})"); + } + // 绘制label与goto + stream.Write(@" +/* +控制流标签 +*/ +"); + stream.Write($"#define label(label_name) __build_in_pragma define label_name\n\n"); + stream.Write(@" +/* +控制流, 当a>b时跳转到指定的label处 +*/ +"); + stream.Write($"#define goto(a,b,label_name)\n\n"); + // 绘制工具 + stream.Write(@" +/* 临时设置上下文变量, 在运行完语句后将还原 e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1); -*/"); +*/ +"); stream.Write($"#define with(...)\n\n"); return; } @@ -56,9 +80,6 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1); { 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"); diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index d26e7d3..3eeb6d5 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -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 } } + /// + /// 涓婁笅鏂囩郴缁 + /// public partial class ScriptableObject { - // 涓婁笅鏂囩郴缁 - [Content] public Dictionary ScriptContextSpace = new(); public bool GetCompleteScriptContext(string key, out float value) @@ -391,6 +394,19 @@ namespace Demo return true; } + public void GetCompleteScriptContext(ref Dictionary context) + { + var current = this; + while (current != null) + { + foreach (var key in current.ScriptContextSpace.Keys) + { + context[key] = current.ScriptContextSpace[key]; + } + current = current.Parent; + } + } + /// /// 璁剧疆灞閮ㄤ笂涓嬫枃鍙橀噺锛屽皢浼氫紶閫掔粰瀛愮墿浣撲娇鐢 /// @@ -405,16 +421,28 @@ namespace Demo ")] public void SetContext(string name, string value) { - ScriptContextSpace[name] = float.Parse(value); + ScriptContextSpace[name] = Parse(value); } } + /// + /// 鏁板艰В鏋愬伐鍏 + /// public partial class ScriptableObject { - // 鏁板艰В鏋愬伐鍏 - - private readonly Dictionary DDTCache = new(); + private ExpressionContext ExpressionParserCreater() + { + ExpressionContext context = new(); + context.Imports.AddType(typeof(Mathf)); + Dictionary vars = new(); + GetCompleteScriptContext(ref vars); + foreach (var item in vars) + { + context.Variables[item.Key] = item.Value; + } + return context; + } public static float OneBarTime = 1; /// @@ -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(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(string str) + { + return ConventionUtility.convert_xvalue(str); + } } + /// + /// 鍏堝ぉ鏀寔鐨勫伐鍏峰嚱鏁 + /// public partial class ScriptableObject { - // 鍏堝ぉ鏀寔鐨勫伐鍏峰嚱鏁 - [Content, SerializeField] private Vector3 EnterGameLocalPosition = Vector3.zero, EnterGameEulerAngles = Vector3.zero, EnterGameLocalScaling = Vector3.one; + [Content, SerializeField] private bool IsSetObjectDisable = false; /// /// 璁剧疆鍧愭爣 @@ -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; - } - /// /// 鍏抽棴璇ョ墿浣擄紝 /// 鍦ㄩ潰瀵瑰澶欸ame鍦烘櫙鏃跺叧闂煇浜汫ameWorld涓粯璁ゅ瓨鍦ㄧ殑鍏ㄥ眬鐏厜绛夊満鏅椂闈炲父鏈夌敤 @@ -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); + } } } + /// + /// UpdatePerFrame鐩稿叧 + /// public partial class ScriptableObject { [Content] public int UpdatePerFrame = 1; @@ -584,47 +638,13 @@ namespace Demo } /// - /// 浣跨敤鏍囪鍙紪杈戣剼鏈墍鑳藉璋冪敤鐨勫嚱鏁帮紝骞堕檮鍔犳敞閲 - /// 浣跨敤鏍囪娲剧敓绫伙紝骞堕檮鍔犻粯璁ゆā鏉 + /// EnableScript鐩稿叧 /// - public partial class ScriptableObject : SerializedMonoBehaviour, IHierarchyItemClickEventListener + public partial class ScriptableObject { - public static Dictionary 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 Childs = new(); - - // Hierarchy - - public PropertiesWindow.ItemEntry MyHierarchyItem; - public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem; - public static int AllScriptableObjectCounter = 0; - - // Cache - - public static Dictionary> 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; + } + } + + /// + /// 浣跨敤鏍囪鍙紪杈戣剼鏈墍鑳藉璋冪敤鐨勫嚱鏁帮紝骞堕檮鍔犳敞閲 + /// 浣跨敤鏍囪娲剧敓绫伙紝骞堕檮鍔犻粯璁ゆā鏉 + /// + public partial class ScriptableObject : SerializedMonoBehaviour, IHierarchyItemClickEventListener + { + + public static Dictionary 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 Childs = new(); + + // Hierarchy + + public PropertiesWindow.ItemEntry MyHierarchyItem; + public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem; + public static int AllScriptableObjectCounter = 0; + + // Cache + + public static Dictionary> 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 = ""; // 娓呯悊Cache - DDTCache.Clear(); + // // 鍑忔暟 AllScriptableObjectCounter--; AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}"; @@ -1099,9 +1158,9 @@ namespace Demo } - protected T ConvertValue(string str) + public virtual void ResetEnterGameStatus() { - return ConventionUtility.convert_xvalue(str); + ResetScriptableObjectEnterGameStatus(); } public virtual void OnHierarchyItemRightClick(RectTransform item)