From 1811006eb1df3740036a03fb0e13e1c1d75cd8ae Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Tue, 11 Nov 2025 16:19:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8E?= =?UTF-8?q?=E7=BC=80=E4=B8=BArscript2.NewSubScript=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E4=B8=93=E7=94=A8=E4=BA=8E=E5=88=9B=E5=BB=BA=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Framework/GameContent/GameController.cs | 2 +- Assets/Scripts/Framework/ScriptableObject.cs | 35 +++++++++++++++++-- .../DefaultScriptableObjectInstantiate.cs | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Framework/GameContent/GameController.cs b/Assets/Scripts/Framework/GameContent/GameController.cs index b401b8d..10eb149 100644 --- a/Assets/Scripts/Framework/GameContent/GameController.cs +++ b/Assets/Scripts/Framework/GameContent/GameController.cs @@ -184,7 +184,7 @@ namespace Demo.Game { while (MainConfig.Contains("root") == false) { - string defaultRootPath = "root.cpp"; + string defaultRootPath = "root.rscript"; if (content.IsCreateNewProject) { MainConfig["root"] = defaultRootPath; diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index 0cafcee..47094ca 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -468,13 +468,42 @@ namespace Demo callback?.Invoke(child); } + public ScriptableObject DoGenerateSubScript([In] string type, string name, [Opt] Action callback) + { + // 判断类型是否合法 + if (DefaultInstantiate.GetScriptableObjectInstantiate().TryGetValue(type, out var creater) == false) + { + Debug.LogError($"{type} is not exist or {type}'s Instantiater is not valid", this); + callback?.Invoke(null); + return null; + } + // 生成对象 + var child = creater(); + child.ScriptName = name; + child.transform.SetParent(this.transform); + child.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); + child.transform.localScale = Vector3.one; + child.EnableScript("", "", type, this); + + // Add Child + Childs.Add(child); + + // Load Child Script + ConventionUtility.StartCoroutine(child.LoadScript("")); + + LastLoadedScriptableObject = child; + callback?.Invoke(child); + + return child; + } + /// - /// 创建子脚本 + /// 创建不需要脚本语句的子脚本对象 /// /// 指定类型 - public IEnumerator NewSubScript([In] string type) + public ScriptableObject NewSubScript([In] string type) { - return DoGenerateSubScriptAsync(type, $"New {type}", null); + return DoGenerateSubScript(type, $"New {type}", null); } /// diff --git a/Assets/Scripts/Framework/ScriptableObjectInstantiate/DefaultScriptableObjectInstantiate.cs b/Assets/Scripts/Framework/ScriptableObjectInstantiate/DefaultScriptableObjectInstantiate.cs index 9359527..042263f 100644 --- a/Assets/Scripts/Framework/ScriptableObjectInstantiate/DefaultScriptableObjectInstantiate.cs +++ b/Assets/Scripts/Framework/ScriptableObjectInstantiate/DefaultScriptableObjectInstantiate.cs @@ -84,7 +84,7 @@ namespace Demo.Game var childName = type; int childIndex = 1; var childFullNameWithoutExtension = childName; - var extension = ".h"; + var extension = ".rscript"; if (childDir.Exists()) { childFullNameWithoutExtension = $"{childName}{(childIndex == 1 ? "" : childIndex.ToString())}";