解决了node的问题(脚本编写错误并非代码错误)

This commit is contained in:
2025-10-06 17:43:21 +08:00
parent 334f55a250
commit 60a5347dde
4 changed files with 28 additions and 25 deletions

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
[CustomEditor(typeof(Demo.ScriptableObject), true)] //[CustomEditor(typeof(Demo.ScriptableObject), true)]
public class SOEditor : Convention.AbstractCustomEditor public class SOEditor : Convention.AbstractCustomEditor
{ {

View File

@@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
using Convention; using Convention;
using Convention.WindowsUI.Variant; using Convention.WindowsUI.Variant;
using Demo.Game; using Demo.Game;
using Sirenix.OdinInspector;
using Unity.Profiling; using Unity.Profiling;
using UnityEngine; using UnityEngine;
@@ -296,22 +297,17 @@ namespace Demo
{ {
// 上下文系统 // 上下文系统
public readonly Dictionary<string, float> ScriptContextSpace = new(); [Content] public Dictionary<string, float> ScriptContextSpace = new();
public Dictionary<string, float> GetCompleteScriptContext()
public bool GetCompleteScriptContext(string key, out float value)
{ {
if (Parent != null) if (ScriptContextSpace.TryGetValue(key, out value) == false)
{ {
Dictionary<string, float> context = Parent != null ? Parent.GetCompleteScriptContext() : new(); if (Parent == null)
foreach (var (name, value) in ScriptContextSpace) return false;
{ return Parent.GetCompleteScriptContext(key, out value);
context[name] = value;
}
return context;
}
else
{
return new(ScriptContextSpace);
} }
return true;
} }
/// <summary> /// <summary>
@@ -353,7 +349,7 @@ namespace Demo
value = value.Trim(); value = value.Trim();
if (TimePoints.TryGetValue(value, out var result)) if (TimePoints.TryGetValue(value, out var result))
return result; return result;
if (GetCompleteScriptContext().TryGetValue(value, out result)) if (GetCompleteScriptContext(value, out result))
return result; return result;
if(value.EndsWith(']')) if(value.EndsWith(']'))
{ {
@@ -503,7 +499,7 @@ namespace Demo
/// <para>使用<see cref="ScriptableCallAttribute"/>标记可编辑脚本所能够调用的函数,并附加注释</para> /// <para>使用<see cref="ScriptableCallAttribute"/>标记可编辑脚本所能够调用的函数,并附加注释</para>
/// <para>使用<see cref="DefaultScriptAttribute"/>标记派生类,并附加默认模板</para> /// <para>使用<see cref="DefaultScriptAttribute"/>标记派生类,并附加默认模板</para>
/// </summary> /// </summary>
public partial class ScriptableObject : MonoBehaviour, IHierarchyItemClickEventListener public partial class ScriptableObject : SerializedMonoBehaviour, IHierarchyItemClickEventListener
{ {
public static Dictionary<string, Type> FastScriptableObjectTypen = new(); public static Dictionary<string, Type> FastScriptableObjectTypen = new();
@@ -569,11 +565,13 @@ namespace Demo
MyHierarchyItem.GetHierarchyItem().title = this.ScriptName + $"<{scriptType}>"; MyHierarchyItem.GetHierarchyItem().title = this.ScriptName + $"<{scriptType}>";
MyHierarchyItem.GetHierarchyItem().target = this; MyHierarchyItem.GetHierarchyItem().target = this;
MyHierarchyItem.GetHierarchyItem().ButtonGameObject.GetComponent<Editor.UI.RightClick>().ScriptObjectMenu = OnHierarchyItemRightClick; MyHierarchyItem.GetHierarchyItem().ButtonGameObject.GetComponent<Editor.UI.RightClick>().ScriptObjectMenu = OnHierarchyItemRightClick;
var parentHierarchyItem = MyHierarchyItem.GetParent(); //var parentHierarchyItem = MyHierarchyItem.GetParent();
if (parentHierarchyItem != null) //if (parentHierarchyItem != null)
parentHierarchyItem.GetPropertyListItem().RefreshChilds(); // parentHierarchyItem.GetPropertyListItem().RefreshChilds();
} }
public const string RootObjectQuickPath = "project/";
public ScriptableObject FindWithPath(string path, bool isMustExist = true) public ScriptableObject FindWithPath(string path, bool isMustExist = true)
{ {
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
@@ -586,9 +584,10 @@ namespace Demo
// GetParent // GetParent
ScriptableObject result = Parent; ScriptableObject result = Parent;
if (path[0] == '/' || path[0]=='\\') if (path.Replace('\\','/').ToLower().StartsWith(RootObjectQuickPath))
{ {
result = GetRoot(); result = GetRoot();
path = path[RootObjectQuickPath.Length..];
} }
if (Parent == null) if (Parent == null)
@@ -654,8 +653,8 @@ namespace Demo
// 生成对象 // 生成对象
var child = creater(); var child = creater();
// 路径预处理 // 路径预处理
if (path.Replace('\\', '/').ToLower().StartsWith("project/")) if (path.Replace('\\', '/').ToLower().StartsWith(RootObjectQuickPath))
path = $"{new ToolFile(GetRoot().SourcePath) | path[5..]}"; path = $"{new ToolFile(GetRoot().SourcePath) | path[RootObjectQuickPath.Length..]}";
// 获取文件 // 获取文件
ToolFile file; ToolFile file;
if (File.Exists(path)) if (File.Exists(path))

View File

@@ -129,7 +129,7 @@ namespace Demo.Game
MyMeshGenerator = this.GetOrAddComponent<TMeshGenerator>(); MyMeshGenerator = this.GetOrAddComponent<TMeshGenerator>();
MyMeshGenerator.spline = MySplineCore.MySplineComputer; MyMeshGenerator.spline = MySplineCore.MySplineComputer;
SetupMeshGenerator(MyMeshGenerator); SetupMeshGenerator(MyMeshGenerator);
MyMeshGenerator.Rebuild(); MyMeshGenerator.RebuildImmediate();
} }
#region SetupMeshGenerator #region SetupMeshGenerator

View File

@@ -162,9 +162,13 @@ namespace Demo.Game
{ {
yield return LoadSubScriptAsync(nameof(SplineNode), path, node => yield return LoadSubScriptAsync(nameof(SplineNode), path, node =>
{ {
if (node != null) if (node is SplineNode _node)
{ {
MySplineNodes.Add(node as SplineNode); MySplineNodes.Add(_node );
}
else
{
Debug.LogError($"{path} is not {nameof(SplineNode)}", this);
} }
}); });
} }