From a0347dcfe666a39afff90c3c56e9047d1b62dc51 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Tue, 25 Nov 2025 17:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E8=BF=9B=E4=B8=AD,=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=AD=98=E5=9C=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Convention | 2 +- Assets/Scripts/Framework/DDT.cs | 21 +++++++- .../EditiorContent/EditorController.cs | 35 ++++++++------ .../Framework/GameContent/GameController.cs | 21 +++++--- Assets/Scripts/Framework/ScriptableObject.cs | 48 ++++++++++++------- Assets/Scripts/Framework/[RScript] | 2 +- Assets/Scripts/MoreSpline/SplineCore.cs | 6 +-- 7 files changed, 89 insertions(+), 46 deletions(-) diff --git a/Assets/Convention b/Assets/Convention index fced177..0b563f3 160000 --- a/Assets/Convention +++ b/Assets/Convention @@ -1 +1 @@ -Subproject commit fced17765c57c18e559f87d168dd14b633695514 +Subproject commit 0b563f393b631e97a014c2d3e96f4f2f8cfd0be5 diff --git a/Assets/Scripts/Framework/DDT.cs b/Assets/Scripts/Framework/DDT.cs index c4a2e52..826d33d 100644 --- a/Assets/Scripts/Framework/DDT.cs +++ b/Assets/Scripts/Framework/DDT.cs @@ -1,10 +1,11 @@ +using System.Collections; using System.Collections.Generic; using Convention; using UnityEngine; namespace Demo.Game { - public class DDT : ScriptableObject + public class DDT : ScriptableObject, IEnumerable { public static DDT Make() { @@ -24,5 +25,23 @@ namespace Demo.Game { Datas.Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime); } + + [Convention.RScript.Variable.Attr.Method] + public float At(int index) + { + return Datas[index]; + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)Datas).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)Datas).GetEnumerator(); + } + + public int Count => Datas.Count; } } diff --git a/Assets/Scripts/Framework/EditiorContent/EditorController.cs b/Assets/Scripts/Framework/EditiorContent/EditorController.cs index f74f2c5..fbc5f00 100644 --- a/Assets/Scripts/Framework/EditiorContent/EditorController.cs +++ b/Assets/Scripts/Framework/EditiorContent/EditorController.cs @@ -333,7 +333,7 @@ namespace Demo.Editor { LastLoadProjectName = ProjectName; StopRefreshFlag = false; - MainGameController = FindObjectOfType(); + MainGameController = FindFirstObjectByType(); MainGameController.IsMain = true; StartCoroutine(MainGameController.GameInit()); }; @@ -378,25 +378,30 @@ namespace Demo.Editor { GlobalConfig.ConstConfigFile = "config.easysave"; // Generate Framework - var generaters = DefaultInstantiate.GetScriptableObjectInstantiate(); - foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { - foreach (var type in asm.GetTypes()) + var generaters = DefaultInstantiate.GetScriptableObjectInstantiate(); + foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { - 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)) + foreach (var type in asm.GetTypes()) { - 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"); + 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"); } // Helper Files diff --git a/Assets/Scripts/Framework/GameContent/GameController.cs b/Assets/Scripts/Framework/GameContent/GameController.cs index 6f73f75..8b9011d 100644 --- a/Assets/Scripts/Framework/GameContent/GameController.cs +++ b/Assets/Scripts/Framework/GameContent/GameController.cs @@ -194,19 +194,26 @@ namespace Demo.Game var rootObject = new ToolFile(Path.Combine(content.RootSourceDir, rootFileName)); rootObject.MustExistsPath(); var rootGameObject = new GameObject(rootObject.GetName(true)).AddComponent(); + MainObject = rootGameObject; rootGameObject.transform.SetParent(transform); rootGameObject.ScriptName = rootObject.GetName(true); rootGameObject.audioSystem = MainAudio; rootGameObject.EnableScript(content.RootSourceDir, this); - try + rootGameObject.SetContent(nameof(SongOffset), SongOffset); + rootGameObject.SetContent(nameof(IsAutoPlay), IsAutoPlay ? 1 : 0); + rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length); + yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText()); + yield return rootGameObject.ApplyScript(); + IEnumerator DFS(ScriptableObject parent) { - yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText()); - yield return rootGameObject.ApplyScript(); - } - finally - { - MainObject = rootGameObject; + foreach (var child in parent.Childs) + { + if (child.IsScriptApply == false) + yield return child.ApplyScript(); + yield return DFS(child); + } } + yield return DFS(rootGameObject); } } finally diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index e47764c..d6c2eb5 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -109,9 +109,10 @@ namespace Demo /// public partial class ScriptableObject { - public Dictionary ScriptableObjectContents = new(); + public Dictionary ScriptableObjectContents = new(); - public object GetContent(string key) + [Convention.RScript.Variable.Attr.Method] + public float GetContent(string key) { if (ScriptableObjectContents.TryGetValue(key, out var result)) { @@ -121,12 +122,14 @@ namespace Demo { return Parent.GetContent(key); } - return null; + throw new InvalidOperationException($"Key {key} is not find in contnet"); } - public void SetContent(string key, object value) + [Convention.RScript.Variable.Attr.Method] + public float SetContent(string key, float value) { ScriptableObjectContents[key] = value; + return value; } } @@ -299,7 +302,7 @@ namespace Demo /// /// [Convention.RScript.Variable.Attr.Method] - public ScriptableObject NewSubScript([In] string type, [In] string name, [In] string path) + public ScriptableObject LoadSubScript([In] string type, [In] string name, [In] string path) { // 判断类型是否合法 if (DefaultInstantiate.GetScriptableObjectInstantiate().TryGetValue(type, out var creater) == false) @@ -390,6 +393,8 @@ namespace Demo RScriptImportClass importClass = new() { typeof(Mathf), + typeof(UnityEngine.Random), + typeof(MathExtension.EaseCurveType) }; RScriptVariables variables = new() { @@ -403,7 +408,11 @@ namespace Demo return engine.RunAsync(script, importClass, variables); } - [Content] private bool IsEnableUpdate = false; + [Content] + public bool IsScriptApply + { + get; private set; + } = false; public enum TickType { @@ -416,7 +425,7 @@ namespace Demo [Content, SerializeField] private int ScriptUpdateCounter = 0; public void ScriptUpdate(float currentTime, float deltaTime, TickType tickType) { - if (IsEnableUpdate == false) + if (IsScriptApply == false) return; if (gameObject.activeInHierarchy == false) return; @@ -480,7 +489,7 @@ namespace Demo AllScriptableObjectCounter++; AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}"; } - IsEnableUpdate = true; + IsScriptApply = true; } public virtual IEnumerator UnloadScript() @@ -497,22 +506,25 @@ namespace Demo } finally { - // 清理各种状态 - IsEnableUpdate = false; + this.isEnableScript = false; + this.Parent = null; + this.name = ""; + if (IsScriptApply) + { + // 清理各种状态 + IsScriptApply = false; + // 清理Cache + // + // 减数 + AllScriptableObjectCounter--; + AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}"; + } if (MyHierarchyItem != null) { // 卸载UI MyHierarchyItem.Release(); MyHierarchyItem = null; } - this.isEnableScript = false; - this.Parent = null; - this.name = ""; - // 清理Cache - // - // 减数 - AllScriptableObjectCounter--; - AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}"; } } } diff --git a/Assets/Scripts/Framework/[RScript] b/Assets/Scripts/Framework/[RScript] index 5b235a7..2f24d94 160000 --- a/Assets/Scripts/Framework/[RScript] +++ b/Assets/Scripts/Framework/[RScript] @@ -1 +1 @@ -Subproject commit 5b235a7f26deeffabdaf2e57d8d369975e609659 +Subproject commit 2f24d94db2826691ca2e465a5f70ef4c3c9e437a diff --git a/Assets/Scripts/MoreSpline/SplineCore.cs b/Assets/Scripts/MoreSpline/SplineCore.cs index 95a1d42..80ab8fb 100644 --- a/Assets/Scripts/MoreSpline/SplineCore.cs +++ b/Assets/Scripts/MoreSpline/SplineCore.cs @@ -42,7 +42,7 @@ namespace Demo.Game { var spline = self.SharedInterfaceScriptObject.FindWithPath(path, false); if (spline == null) - spline = self.SharedInterfaceScriptObject.NewSubScript(nameof(SplineCore), new ToolFile(path).GetFilename(true), path); + spline = self.SharedInterfaceScriptObject.LoadSubScript(nameof(SplineCore), new ToolFile(path).GetFilename(true), path); self.MySplineCore = (SplineCore)spline; return self.MySplineCore; } @@ -145,9 +145,9 @@ namespace Demo.Game /// /// 脚本位置 [Convention.RScript.Variable.Attr.Method] - public void LoadNode(ScriptableObject node) + public void LoadNode(SplineNode node) { - MySplineNodes.Add(node.GetOrAddComponent()); + MySplineNodes.Add(node); } } }