From a1a78efbb54c74e3c3b327ae20f0bd159132d5de Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Thu, 30 Jan 2025 23:28:24 +0800 Subject: [PATCH 1/9] Fix CeresPortSetup namespace --- Runtime/Core/Models/Graph/Ports/CeresPortSetup.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Runtime/Core/Models/Graph/Ports/CeresPortSetup.cs b/Runtime/Core/Models/Graph/Ports/CeresPortSetup.cs index 04dad84..41cc294 100644 --- a/Runtime/Core/Models/Graph/Ports/CeresPortSetup.cs +++ b/Runtime/Core/Models/Graph/Ports/CeresPortSetup.cs @@ -1,8 +1,7 @@ -using Ceres.Graph; -using Chris.Schedulers; +using Chris.Schedulers; using Unity.Collections.LowLevel.Unsafe; using UnityEngine; -namespace Chris.Gameplay.Flow.Utilities +namespace Ceres.Graph { internal static class CeresPortSetup { From bdbd0f784352e2f374c22fecd89390e6b8a5dcaf Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Thu, 30 Jan 2025 23:28:38 +0800 Subject: [PATCH 2/9] Add SharedDouble --- .../Core/UIElements/Graph/CeresBlackboard.cs | 1 + .../Core/UIElements/Graph/Fields/EnumField.cs | 4 --- .../Core/UIElements/Graph/Fields/ListField.cs | 22 ++++++++-------- .../Fields/Resolvers/BoundsIntResolver.cs | 4 --- .../Graph/Fields/Resolvers/BoundsResolver.cs | 4 --- .../Graph/Fields/Resolvers/DoubleResolver.cs | 4 --- .../Graph/Fields/Resolvers/FloatResolver.cs | 4 --- .../Graph/Fields/Resolvers/IntResolver.cs | 4 --- .../Fields/Resolvers/List/EnumListResolver.cs | 3 +-- .../Fields/Resolvers/List/ListResolver.cs | 1 + .../Resolvers/List/ObjectListResolver.cs | 1 + .../Graph/Fields/Resolvers/LongResolver.cs | 4 --- .../Graph/Fields/Resolvers/RectIntResolver.cs | 4 --- .../Graph/Fields/Resolvers/RectResolver.cs | 4 --- .../Resolvers/Shared/SharedObjectResolver.cs | 10 +++++--- .../Resolvers/Shared/SharedStringResolver.cs | 4 +-- .../Resolvers/Shared/SharedTObjectResolver.cs | 25 +++++++++++++++---- .../Shared/SharedVariableResolver.cs | 17 +++++++++---- .../Fields/Resolvers/Vector2IntResolver.cs | 4 --- .../Graph/Fields/Resolvers/Vector2Resolver.cs | 4 --- .../Fields/Resolvers/Vector3IntResolver.cs | 4 --- .../Graph/Fields/Resolvers/Vector3Resolver.cs | 4 --- .../Graph/Fields/Resolvers/Vector4Resolver.cs | 4 --- .../Fields/Resolvers/WrapFieldResolver.cs | 6 ++--- .../Graph/Fields/SharedVariableField.cs | 8 +++--- .../Variables/Interfaces/IBindableVariable.cs | 17 ------------- .../Models/Variables/Interfaces/IVariable.cs | 11 ++++++++ ...ableVariable.cs.meta => IVariable.cs.meta} | 2 +- Runtime/Core/Models/Variables/SharedDouble.cs | 22 ++++++++++++++++ .../Models/Variables/SharedDouble.cs.meta | 11 ++++++++ .../Core/Models/Variables/SharedUObject.cs | 8 +++--- .../Core/Models/Variables/SharedVariable.cs | 16 ++++++------ 32 files changed, 120 insertions(+), 121 deletions(-) delete mode 100644 Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs create mode 100644 Runtime/Core/Models/Variables/Interfaces/IVariable.cs rename Runtime/Core/Models/Variables/Interfaces/{IBindableVariable.cs.meta => IVariable.cs.meta} (83%) create mode 100644 Runtime/Core/Models/Variables/SharedDouble.cs create mode 100644 Runtime/Core/Models/Variables/SharedDouble.cs.meta diff --git a/Editor/Core/UIElements/Graph/CeresBlackboard.cs b/Editor/Core/UIElements/Graph/CeresBlackboard.cs index 52b822a..277faae 100644 --- a/Editor/Core/UIElements/Graph/CeresBlackboard.cs +++ b/Editor/Core/UIElements/Graph/CeresBlackboard.cs @@ -116,6 +116,7 @@ protected void CreateBuiltInSharedVariableMenu(GenericMenu menu) { menu.AddItem(new GUIContent("Int"), false, () => AddVariable(new SharedInt(), true)); menu.AddItem(new GUIContent("Float"), false, () => AddVariable(new SharedFloat(), true)); + menu.AddItem(new GUIContent("Double"), false, () => AddVariable(new SharedDouble(), true)); menu.AddItem(new GUIContent("Bool"), false, () => AddVariable(new SharedBool(), true)); menu.AddItem(new GUIContent("Vector2Int"), false, () => AddVariable(new SharedVector2Int(), true)); menu.AddItem(new GUIContent("Vector2"), false, () => AddVariable(new SharedVector2(), true)); diff --git a/Editor/Core/UIElements/Graph/Fields/EnumField.cs b/Editor/Core/UIElements/Graph/Fields/EnumField.cs index 390a227..c656c2a 100644 --- a/Editor/Core/UIElements/Graph/Fields/EnumField.cs +++ b/Editor/Core/UIElements/Graph/Fields/EnumField.cs @@ -1,10 +1,6 @@ using System; using System.Collections.Generic; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif namespace Ceres.Editor.Graph { public class EnumField : PopupField diff --git a/Editor/Core/UIElements/Graph/Fields/ListField.cs b/Editor/Core/UIElements/Graph/Fields/ListField.cs index f348469..6581a0b 100644 --- a/Editor/Core/UIElements/Graph/Fields/ListField.cs +++ b/Editor/Core/UIElements/Graph/Fields/ListField.cs @@ -5,20 +5,20 @@ namespace Ceres.Editor.Graph { public class ListField : BaseField> { - protected readonly ListView ListView; + private readonly ListView _listView; protected readonly Func ElementCreator; - - protected readonly Func ValueCreator; - - protected const int DefaultListItemHeight = 20; + + private readonly Func _valueCreator; + + private const int DefaultListItemHeight = 20; private ListField(string label, Func elementCreator, Func valueCreator, VisualElement listContainer) : base(label, listContainer) { value ??= new List(); ElementCreator = elementCreator; - ValueCreator = valueCreator; - listContainer.Add(ListView = CreateListView()); + _valueCreator = valueCreator; + listContainer.Add(_listView = CreateListView()); } public ListField(string label, Func elementCreator, Func valueCreator) : this(label, elementCreator, valueCreator, new VisualElement()) @@ -58,8 +58,8 @@ protected virtual VisualElement OnMakeListItem() protected virtual void OnRequestAddListItem() { - value.Add((T)ValueCreator.Invoke()); - ListView.RefreshItems(); + value.Add((T)_valueCreator.Invoke()); + _listView.RefreshItems(); } public sealed override List value @@ -74,8 +74,8 @@ public sealed override List value private void UpdateValue() { - if (ListView == null) return; - ListView.itemsSource = value; ListView.RefreshItems(); + if (_listView == null) return; + _listView.itemsSource = value; _listView.RefreshItems(); } } } \ No newline at end of file diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsIntResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsIntResolver.cs index bd9b0cc..027bed5 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsIntResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsIntResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsResolver.cs index 43be79d..fc0f4fa 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/BoundsResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/DoubleResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/DoubleResolver.cs index 0214064..409be4b 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/DoubleResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/DoubleResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif namespace Ceres.Editor.Graph { public class DoubleResolver : FieldResolver diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/FloatResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/FloatResolver.cs index 82388de..0614cea 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/FloatResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/FloatResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif namespace Ceres.Editor.Graph { public class FloatResolver : FieldResolver diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/IntResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/IntResolver.cs index d769780..756c30c 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/IntResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/IntResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif namespace Ceres.Editor.Graph { public class IntResolver : FieldResolver diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/List/EnumListResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/List/EnumListResolver.cs index 39fe4cc..a742ce3 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/List/EnumListResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/List/EnumListResolver.cs @@ -18,8 +18,7 @@ protected override ListField CreateEditorField(FieldInfo fieldInfo) public override bool IsAcceptable(Type fieldValueType, FieldInfo _) { if (fieldValueType.IsGenericType && fieldValueType.GetGenericTypeDefinition() == typeof(List<>) && fieldValueType.GenericTypeArguments[0].IsEnum) return true; - if (fieldValueType.IsArray && fieldValueType.GetElementType()!.IsEnum) return true; - return false; + return fieldValueType.IsArray && fieldValueType.GetElementType()!.IsEnum; } } } \ No newline at end of file diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ListResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ListResolver.cs index 512981d..ae6f5e1 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ListResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ListResolver.cs @@ -9,6 +9,7 @@ public class ListResolver : FieldResolver, List, IList> { protected readonly IFieldResolver ChildResolver; + // ReSharper disable once MemberCanBeProtected.Global public ListResolver(FieldInfo fieldInfo, IFieldResolver resolver) : base(fieldInfo) { ChildResolver = resolver; diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ObjectListResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ObjectListResolver.cs index 1008d0e..e5a2924 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ObjectListResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/List/ObjectListResolver.cs @@ -7,6 +7,7 @@ public class ObjectListResolver : ListResolver where T : UnityEngine.Objec { } + protected override ListField CreateEditorField(FieldInfo fieldInfo) { return new ObjectListField(fieldInfo.Name, () => ChildResolver.CreateField(), () => null); diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/LongResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/LongResolver.cs index b67cb8a..e39346b 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/LongResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/LongResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif namespace Ceres.Editor.Graph { public class LongResolver : FieldResolver diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/RectIntResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/RectIntResolver.cs index ea67a08..4b6309c 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/RectIntResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/RectIntResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/RectResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/RectResolver.cs index 688cd77..3ac0926 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/RectResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/RectResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedObjectResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedObjectResolver.cs index 92d6537..b575124 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedObjectResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedObjectResolver.cs @@ -2,9 +2,10 @@ using UnityEditor.UIElements; using System; using UnityEngine.UIElements; +using UObject = UnityEngine.Object; namespace Ceres.Editor.Graph { - public class SharedObjectResolver : FieldResolver + public sealed class SharedObjectResolver : FieldResolver { public SharedObjectResolver(FieldInfo fieldInfo) : base(fieldInfo) { @@ -20,13 +21,14 @@ public override bool IsAcceptable(Type fieldValueType, FieldInfo _) return fieldValueType == typeof(SharedUObject); } } - public class SharedObjectField : SharedVariableField + + public sealed class SharedObjectField : SharedVariableField { public SharedObjectField(string label, Type objectType, FieldInfo fieldInfo) : base(label, objectType, fieldInfo) { } - protected override BaseField CreateValueField() + protected override BaseField CreateValueField() { return new ObjectField { @@ -34,7 +36,7 @@ public SharedObjectField(string label, Type objectType, FieldInfo fieldInfo) : b }; } - protected sealed override void OnRepaint() + protected override void OnRepaint() { ((ObjectField)ValueField).objectType = value.GetValueType(); } diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedStringResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedStringResolver.cs index cf717b2..83613ec 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedStringResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedStringResolver.cs @@ -4,7 +4,7 @@ using UnityEngine.UIElements; namespace Ceres.Editor.Graph { - public class SharedStringResolver : SharedVariableResolver + public sealed class SharedStringResolver : SharedVariableResolver { public SharedStringResolver(FieldInfo fieldInfo) : base(fieldInfo) { @@ -15,7 +15,7 @@ protected override Field CreateEditorField(FieldInfo fieldInfo) return new SharedStringField(fieldInfo.Name, fieldInfo.FieldType, fieldInfo); } - public class SharedStringField : Field + public sealed class SharedStringField : Field { private readonly bool _multiline; public SharedStringField(string label, Type objectType, FieldInfo fieldInfo) : base(label, objectType, fieldInfo) diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedTObjectResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedTObjectResolver.cs index 1e6e0d0..353ad73 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedTObjectResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedTObjectResolver.cs @@ -6,9 +6,10 @@ using Ceres.Annotations; using UnityEditor.UIElements; using UnityEngine.UIElements; +using UObject = UnityEngine.Object; namespace Ceres.Editor.Graph { - public class SharedTObjectResolver : FieldResolver, SharedUObject> where T : UnityEngine.Object + public sealed class SharedTObjectResolver : FieldResolver, SharedUObject> where T : UObject { public SharedTObjectResolver(FieldInfo fieldInfo) : base(fieldInfo) { @@ -25,7 +26,8 @@ public override bool IsAcceptable(Type fieldValueType, FieldInfo _) return fieldValueType.IsSharedTObject() && fieldValueType.GenericTypeArguments.Length == 1 && fieldValueType.GenericTypeArguments[0] == typeof(T); } } - public class SharedTObjectField : BaseField>, IBindableField where T : UnityEngine.Object + + public class SharedTObjectField : BaseField>, IBindableField where T : UObject { private readonly bool _forceShared; @@ -38,6 +40,7 @@ public class SharedTObjectField : BaseField>, IBindableField private DropdownField _nameDropdown; private SharedVariable _bindExposedProperty; + public SharedTObjectField(string label, FieldInfo fieldInfo) : base(label, null) { _forceShared = fieldInfo.GetCustomAttribute() != null; @@ -59,6 +62,7 @@ public SharedTObjectField(string label, FieldInfo fieldInfo) : base(label, null) } _foldout.Add(_toggle); } + public void BindGraph(CeresGraphView graph) { _graphView = graph; @@ -70,6 +74,7 @@ public void BindGraph(CeresGraphView graph) }); OnToggle(_toggle.value); } + private static List GetList(CeresGraphView graphView) { return graphView.SharedVariables @@ -78,6 +83,7 @@ private static List GetList(CeresGraphView graphView) .Select(v => v.Name) .ToList(); } + private void BindProperty() { if (_graphView == null) return; @@ -86,6 +92,7 @@ private void BindProperty() && sharedObject.GetValueType().IsAssignableTo(typeof(T)) && x.Name.Equals(value.Name)); } + private void OnToggle(bool isShared) { if (isShared) @@ -101,26 +108,30 @@ private void OnToggle(bool isShared) AddValueField(); } } + private void AddNameDropDown() { var list = GetList(_graphView); - value.Name = value.Name ?? string.Empty; + value.Name ??= string.Empty; int index = list.IndexOf(value.Name); _nameDropdown = new DropdownField($"Shared {typeof(T).Name}", list, index); _nameDropdown.RegisterCallback((evt) => { _nameDropdown.choices = GetList(_graphView); }); _nameDropdown.RegisterValueChangedCallback(evt => { value.Name = evt.newValue; BindProperty(); NotifyValueChange(); }); _foldout.Insert(0, _nameDropdown); } + private void RemoveNameDropDown() { if (_nameDropdown != null) _foldout.Remove(_nameDropdown); _nameDropdown = null; } + private void RemoveValueField() { if (ValueField != null) _foldout.Remove(ValueField); ValueField = null; } + private void AddValueField() { ValueField = new ObjectField() @@ -131,6 +142,7 @@ private void AddValueField() if (value != null) ValueField.value = value.Value; _foldout.Insert(0, ValueField); } + public sealed override SharedUObject value { get => base.value; set @@ -147,7 +159,9 @@ public sealed override SharedUObject value Repaint(); } } + private ObjectField ValueField { get; set; } + public void Repaint() { _toggle.value = value.IsShared; @@ -156,9 +170,10 @@ public void Repaint() OnToggle(value.IsShared); NotifyValueChange(); } - protected void NotifyValueChange() + + private void NotifyValueChange() { - using ChangeEvent> changeEvent = ChangeEvent>.GetPooled(value, value); + using var changeEvent = ChangeEvent>.GetPooled(value, value); changeEvent.target = this; SendEvent(changeEvent); } diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedVariableResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedVariableResolver.cs index aa7131c..f75f063 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedVariableResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Shared/SharedVariableResolver.cs @@ -1,11 +1,10 @@ using System.Reflection; using System; using UnityEngine.UIElements; -using UnityEditor.UIElements; using UnityEngine; namespace Ceres.Editor.Graph { - public class SharedVariableResolver : + public abstract class SharedVariableResolver : FieldResolver.Field, TVariable> where TVariable : SharedVariable, new() where TField: BaseField, new() @@ -20,16 +19,17 @@ public Field(string label, Type objectType, FieldInfo fieldInfo) : base(label, o protected override BaseField CreateValueField() => new TField(); } - - public SharedVariableResolver(FieldInfo fieldInfo) : base(fieldInfo) + + protected SharedVariableResolver(FieldInfo fieldInfo) : base(fieldInfo) { } + protected override Field CreateEditorField(FieldInfo fieldInfo) { return new Field(fieldInfo.Name, fieldInfo.FieldType, fieldInfo); } + public override bool IsAcceptable(Type fieldValueType, FieldInfo _) => fieldValueType == typeof(TVariable); - } public class SharedBoolResolver : SharedVariableResolver @@ -53,6 +53,13 @@ public SharedFloatResolver(FieldInfo fieldInfo) : base(fieldInfo) } } + public class SharedDoubleResolver : SharedVariableResolver + { + public SharedDoubleResolver(FieldInfo fieldInfo) : base(fieldInfo) + { + } + } + public class SharedVector2IntResolver : SharedVariableResolver { public SharedVector2IntResolver(FieldInfo fieldInfo) : base(fieldInfo) diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2IntResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2IntResolver.cs index 4476fb1..90024db 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2IntResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2IntResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2Resolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2Resolver.cs index d3177ef..e23fbe4 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2Resolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector2Resolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3IntResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3IntResolver.cs index 1598ff0..0c60c20 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3IntResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3IntResolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3Resolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3Resolver.cs index 275407a..a7dcfaf 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3Resolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector3Resolver.cs @@ -1,10 +1,6 @@ using System; using System.Reflection; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif using UnityEngine; namespace Ceres.Editor.Graph { diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector4Resolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector4Resolver.cs index 4dd5c57..1aee3f1 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector4Resolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/Vector4Resolver.cs @@ -1,11 +1,7 @@ using System; using System.Reflection; using UnityEngine; -#if UNITY_2022_1_OR_NEWER using UnityEngine.UIElements; -#else -using UnityEditor.UIElements; -#endif namespace Ceres.Editor.Graph { public class Vector4Resolver : FieldResolver diff --git a/Editor/Core/UIElements/Graph/Fields/Resolvers/WrapFieldResolver.cs b/Editor/Core/UIElements/Graph/Fields/Resolvers/WrapFieldResolver.cs index 9bb84b3..ccee23b 100644 --- a/Editor/Core/UIElements/Graph/Fields/Resolvers/WrapFieldResolver.cs +++ b/Editor/Core/UIElements/Graph/Fields/Resolvers/WrapFieldResolver.cs @@ -39,8 +39,8 @@ public class WrapField : BaseField private SoftObjectHandle _wrapperHandle; private readonly FieldInfo _fieldInfo; - - protected WrapField(string label, FieldInfo fieldInfo, IMGUIContainer container) : base(label, container) + + private WrapField(string label, FieldInfo fieldInfo, IMGUIContainer container) : base(label, container) { _fieldInfo = fieldInfo; container.onGUIHandler = OnGUI; @@ -68,7 +68,7 @@ private SerializedObjectWrapper GetInstance() private void OnGUI() { - var instance = GetInstance(); + GetInstance(); _serializedObject.Update(); EditorGUILayout.PropertyField(_serializedProperty, GUIContent.none); _serializedObject.ApplyModifiedProperties(); diff --git a/Editor/Core/UIElements/Graph/Fields/SharedVariableField.cs b/Editor/Core/UIElements/Graph/Fields/SharedVariableField.cs index 01a4676..931cfa8 100644 --- a/Editor/Core/UIElements/Graph/Fields/SharedVariableField.cs +++ b/Editor/Core/UIElements/Graph/Fields/SharedVariableField.cs @@ -22,10 +22,10 @@ namespace Ceres.Editor.Graph private SharedVariable _bindExposedProperty; private readonly Type _bindType; - - public BaseField ValueField { get; private set; } - - public SharedVariableField(string label, Type objectType, FieldInfo fieldInfo) : base(label, null) + + protected BaseField ValueField { get; private set; } + + protected SharedVariableField(string label, Type objectType, FieldInfo fieldInfo) : base(label, null) { _forceShared = fieldInfo.GetCustomAttribute() != null; AddToClassList("SharedVariableField"); diff --git a/Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs b/Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs deleted file mode 100644 index 30cf747..0000000 --- a/Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Ceres -{ - /// - /// Interface to bind value between different type of variables - /// - /// - public interface IBindableVariable - { - T Value { get; set; } - - /// - /// Bind to other bindable variable with type constraint - /// - /// - void Bind(IBindableVariable other); - } -} \ No newline at end of file diff --git a/Runtime/Core/Models/Variables/Interfaces/IVariable.cs b/Runtime/Core/Models/Variables/Interfaces/IVariable.cs new file mode 100644 index 0000000..29eefa5 --- /dev/null +++ b/Runtime/Core/Models/Variables/Interfaces/IVariable.cs @@ -0,0 +1,11 @@ +namespace Ceres +{ + /// + /// Interface for variables + /// + /// + public interface IVariable + { + T Value { get; set; } + } +} \ No newline at end of file diff --git a/Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs.meta b/Runtime/Core/Models/Variables/Interfaces/IVariable.cs.meta similarity index 83% rename from Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs.meta rename to Runtime/Core/Models/Variables/Interfaces/IVariable.cs.meta index df16a62..942714f 100644 --- a/Runtime/Core/Models/Variables/Interfaces/IBindableVariable.cs.meta +++ b/Runtime/Core/Models/Variables/Interfaces/IVariable.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a0918352be1702441bae07e4c00f0353 +guid: c20609964cd0ead47a660d8d9d22fb4b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Core/Models/Variables/SharedDouble.cs b/Runtime/Core/Models/Variables/SharedDouble.cs new file mode 100644 index 0000000..9090519 --- /dev/null +++ b/Runtime/Core/Models/Variables/SharedDouble.cs @@ -0,0 +1,22 @@ +using System; +namespace Ceres +{ + [Serializable] + public class SharedDouble : SharedVariable + { + public SharedDouble(int value) + { + this.value = value; + } + + public SharedDouble() + { + + } + + protected override SharedVariable CloneT() + { + return new SharedDouble { Value = value }; + } + } +} \ No newline at end of file diff --git a/Runtime/Core/Models/Variables/SharedDouble.cs.meta b/Runtime/Core/Models/Variables/SharedDouble.cs.meta new file mode 100644 index 0000000..542bdd3 --- /dev/null +++ b/Runtime/Core/Models/Variables/SharedDouble.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 930cc5665f5ee2040887bce1e95933be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Core/Models/Variables/SharedUObject.cs b/Runtime/Core/Models/Variables/SharedUObject.cs index 1deb97f..c386a5b 100644 --- a/Runtime/Core/Models/Variables/SharedUObject.cs +++ b/Runtime/Core/Models/Variables/SharedUObject.cs @@ -33,10 +33,10 @@ public override Type GetValueType() } [Serializable] - public class SharedUObject : SharedVariable, IBindableVariable where TObject : UObject + public class SharedUObject : SharedVariable, IVariable where TObject : UObject { // Special case of binding SharedTObject to SharedObject - UObject IBindableVariable.Value + UObject IVariable.Value { get => Value; @@ -61,7 +61,7 @@ protected override SharedVariable CloneT() public override void Bind(SharedVariable other) { //Special case of binding SharedObject to SharedTObject - if (other is IBindableVariable sharedObject) + if (other is IVariable sharedObject) { Bind(sharedObject); } @@ -71,7 +71,7 @@ public override void Bind(SharedVariable other) } } - public void Bind(IBindableVariable other) + public void Bind(IVariable other) { Getter = () => (TObject)other.Value; Setter = newValue => other.Value = newValue; diff --git a/Runtime/Core/Models/Variables/SharedVariable.cs b/Runtime/Core/Models/Variables/SharedVariable.cs index 07c8839..9d48fec 100644 --- a/Runtime/Core/Models/Variables/SharedVariable.cs +++ b/Runtime/Core/Models/Variables/SharedVariable.cs @@ -97,8 +97,9 @@ object ICloneable.Clone() return Clone(); } } + [Serializable] - public abstract class SharedVariable : SharedVariable, IBindableVariable + public abstract class SharedVariable : SharedVariable, IVariable { public T Value { @@ -141,15 +142,15 @@ public sealed override void SetValue(object newValue) protected Action Setter; - public void Bind(IBindableVariable other) + public void Bind(IVariable other) { Getter = () => other.Value; - Setter = (evt) => other.Value = evt; + Setter = newValue => other.Value = newValue; } public override void Bind(SharedVariable other) { - if (other is IBindableVariable variable) + if (other is IVariable variable) { Bind(variable); } @@ -207,6 +208,7 @@ public override Type GetValueType() return typeof(T); } } + public class SetterWrapper : IDisposable { private readonly Action> _unregister; @@ -239,7 +241,7 @@ public abstract class ObserveProxyVariable : IDisposable public abstract void Dispose(); } - public class ObserveProxyVariable : ObserveProxyVariable, IBindableVariable + public class ObserveProxyVariable : ObserveProxyVariable, IVariable { public T Value { @@ -252,8 +254,8 @@ public T Value private Action _setter; private readonly SetterWrapper _setterWrapper; - - public void Bind(IBindableVariable other) + + private void Bind(IVariable other) { _getter = () => other.Value; _setter = evt => other.Value = evt; From c6848df0aecd8a5b4d3667645c74eb444e4025c1 Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Thu, 30 Jan 2025 23:28:58 +0800 Subject: [PATCH 3/9] FrameSelection after copy paste nodes --- Editor/Flow/FlowGraphView.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Editor/Flow/FlowGraphView.cs b/Editor/Flow/FlowGraphView.cs index 8d2bff2..be44f21 100644 --- a/Editor/Flow/FlowGraphView.cs +++ b/Editor/Flow/FlowGraphView.cs @@ -312,6 +312,7 @@ public void DeserializeGraph(FlowGraph flowGraph, bool copyPaste = false) { _graphView.ClearSelection(); newElements.ForEach(x=> _graphView.AddToSelection(x)); + _graphView.schedule.Execute(() => _graphView.FrameSelection()).ExecuteLater(10); } } } From fded0357358a4730bd3b354c73c10e68185ca446 Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Fri, 31 Jan 2025 13:49:05 +0800 Subject: [PATCH 4/9] Speed up ExecutableFunctionRegistry --- Runtime/Core/Utilities/SubclassSearchUtility.cs | 16 ++++++---------- .../Flow/Utilities/ExecutableFunctionRegistry.cs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Runtime/Core/Utilities/SubclassSearchUtility.cs b/Runtime/Core/Utilities/SubclassSearchUtility.cs index 5e9a987..a300751 100644 --- a/Runtime/Core/Utilities/SubclassSearchUtility.cs +++ b/Runtime/Core/Utilities/SubclassSearchUtility.cs @@ -11,20 +11,16 @@ public static class SubClassSearchUtility public static List FindSubClassTypes(Type searchType) { - return AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(a => a.GetTypes()) - .Where(t => t.IsAssignableTo(searchType) && !t.IsAbstract) - .ToList(); + return FindSubClassTypes(AppDomain.CurrentDomain.GetAssemblies(), searchType); } - public static List FindStructTypes() + public static List FindSubClassTypes(IEnumerable assemblies, Type searchType) { - return AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(a => a.GetTypes()) - .Where(t => t.IsValueType && !t.IsEnum && !t.IsPrimitive) - .ToList(); + return assemblies.SelectMany(a => a.GetTypes()) + .Where(t => t.IsAssignableTo(searchType) && !t.IsAbstract) + .ToList(); } - + public static List FindSubClassTypes(Type[] searchTypes) { return AppDomain.CurrentDomain.GetAssemblies() diff --git a/Runtime/Flow/Utilities/ExecutableFunctionRegistry.cs b/Runtime/Flow/Utilities/ExecutableFunctionRegistry.cs index f18034e..bc8f720 100644 --- a/Runtime/Flow/Utilities/ExecutableFunctionRegistry.cs +++ b/Runtime/Flow/Utilities/ExecutableFunctionRegistry.cs @@ -54,8 +54,17 @@ public class ExecutableFunctionRegistry private ExecutableFunctionRegistry() { + var referencedAssemblies = AppDomain.CurrentDomain.GetAssemblies() + .Where(x => + { + if (x.GetReferencedAssemblies().Any(name => name.Name != nameof(Ceres)) && x.GetName().Name != nameof(Ceres)) + return false; + return x.GetName().Name.Contains(".Editor"); + }) + .ToArray(); + // Collect static functions - var methodInfos = SubClassSearchUtility.FindSubClassTypes(typeof(ExecutableFunctionLibrary)) + var methodInfos = SubClassSearchUtility.FindSubClassTypes(referencedAssemblies, typeof(ExecutableFunctionLibrary)) .SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.Static)) .Where(x=>x.GetCustomAttribute() != null) .Distinct() @@ -67,7 +76,7 @@ private ExecutableFunctionRegistry() _retargetFunctionTables = groups.ToDictionary(x => x.Key, x => x.ToArray()); // Collect instance functions - _instanceFunctionTables = AppDomain.CurrentDomain.GetAssemblies() + _instanceFunctionTables = referencedAssemblies .SelectMany(a => a.GetTypes()) .Where(x=> !x.IsAbstract && GetInstanceExecutableFunctions(x).Any()) .ToDictionary(x => x, x=> GetInstanceExecutableFunctions(x).ToArray()); From 86b5cec0a291d4b0b69c8e6f725d0e0fc9d4e4d2 Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Fri, 31 Jan 2025 14:04:31 +0800 Subject: [PATCH 5/9] Update Editor Assertion --- Editor/Core/UIElements/Graph/CeresGraphView.cs | 4 +--- Editor/Core/UIElements/Graph/Nodes/CeresNodeView.cs | 1 - Editor/Flow/FlowGraphView.cs | 3 +-- Runtime/Flow/Models/ExecutableReflection.cs | 1 - 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Editor/Core/UIElements/Graph/CeresGraphView.cs b/Editor/Core/UIElements/Graph/CeresGraphView.cs index cab2f46..050bab1 100644 --- a/Editor/Core/UIElements/Graph/CeresGraphView.cs +++ b/Editor/Core/UIElements/Graph/CeresGraphView.cs @@ -80,9 +80,7 @@ protected virtual void OnPasteSerializedGraph(string operationName, string seria /// public void AddBlackboard(CeresBlackboard blackboard) { - Blackboard = blackboard; - Blackboard.SetPosition(new Rect(20, 70, 250, 400)); - Add(blackboard); + AddBlackboard(blackboard, new Rect(20, 70, 250, 400)); } /// diff --git a/Editor/Core/UIElements/Graph/Nodes/CeresNodeView.cs b/Editor/Core/UIElements/Graph/Nodes/CeresNodeView.cs index 5b32639..524b78a 100644 --- a/Editor/Core/UIElements/Graph/Nodes/CeresNodeView.cs +++ b/Editor/Core/UIElements/Graph/Nodes/CeresNodeView.cs @@ -6,7 +6,6 @@ using Ceres.Annotations; using Ceres.Graph; using UnityEditor.Experimental.GraphView; -using UnityEngine; using UnityEngine.UIElements; using NodeElement = UnityEditor.Experimental.GraphView.Node; namespace Ceres.Editor.Graph diff --git a/Editor/Flow/FlowGraphView.cs b/Editor/Flow/FlowGraphView.cs index be44f21..68e4ef7 100644 --- a/Editor/Flow/FlowGraphView.cs +++ b/Editor/Flow/FlowGraphView.cs @@ -9,7 +9,6 @@ using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; -using UnityEngine.Assertions; using UnityEngine.Pool; using UnityEngine.UIElements; namespace Ceres.Editor.Graph.Flow @@ -282,7 +281,7 @@ public void DeserializeGraph(FlowGraph flowGraph, bool copyPaste = false) { var nodeView = NodeViewFactory.Get().CreateInstance(nodeInstance.GetType(), _graphView) as CeresNodeView; /* Missing node class should be handled before get graph */ - Assert.IsNotNull(nodeView, $"[Ceres] Can not construct node view for type {nodeInstance.GetType()}"); + CeresAPI.Assert(nodeView != null, $"Can not construct node view for type {nodeInstance.GetType()}"); _graphView.AddNodeView(nodeView); newElements.Add(nodeView.NodeElement); try diff --git a/Runtime/Flow/Models/ExecutableReflection.cs b/Runtime/Flow/Models/ExecutableReflection.cs index 6ce41e3..728436d 100644 --- a/Runtime/Flow/Models/ExecutableReflection.cs +++ b/Runtime/Flow/Models/ExecutableReflection.cs @@ -5,7 +5,6 @@ using Ceres.Annotations; using Ceres.Graph.Flow.Annotations; using Ceres.Graph.Flow.Utilities; -using UnityEngine; using UnityEngine.Assertions; namespace Ceres.Graph.Flow { From a7e74c763a50f9b17b7c4d970b9c942b7fd18ef8 Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Fri, 31 Jan 2025 14:06:18 +0800 Subject: [PATCH 6/9] Update PropertyNode_GetPropertyTValue.cs --- .../Nodes/Properties/PropertyNode_GetPropertyTValue.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Runtime/Flow/Models/Nodes/Properties/PropertyNode_GetPropertyTValue.cs b/Runtime/Flow/Models/Nodes/Properties/PropertyNode_GetPropertyTValue.cs index dc62afa..981e09c 100644 --- a/Runtime/Flow/Models/Nodes/Properties/PropertyNode_GetPropertyTValue.cs +++ b/Runtime/Flow/Models/Nodes/Properties/PropertyNode_GetPropertyTValue.cs @@ -5,6 +5,7 @@ using UObject = UnityEngine.Object; namespace Ceres.Graph.Flow.Properties { + [Serializable] public abstract class PropertyNode_PropertyValue : PropertyNode { [HideInGraphEditor] @@ -12,6 +13,11 @@ public abstract class PropertyNode_PropertyValue : PropertyNode protected TValue GetTargetOrDefault(CeresPort inputPort, ExecutionContext context) { + if (!isSelfTarget) + { + return inputPort.Value; + } + bool isNull; if(inputPort.Value is UObject value) { From fc597d95db58a0f7a53d8d8b36e357601e3e11ff Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Fri, 31 Jan 2025 14:22:21 +0800 Subject: [PATCH 7/9] Add event name validation after paste ExecutableEventNodeView --- Editor/Flow/FlowGraphView.cs | 4 +- Editor/Flow/Nodes/ExecutableEventNodeView.cs | 38 ++++++++++++++++--- .../Models/Graph/Nodes/NodeAPIUpdateConfig.cs | 1 - 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Editor/Flow/FlowGraphView.cs b/Editor/Flow/FlowGraphView.cs index 68e4ef7..0510645 100644 --- a/Editor/Flow/FlowGraphView.cs +++ b/Editor/Flow/FlowGraphView.cs @@ -283,7 +283,7 @@ public void DeserializeGraph(FlowGraph flowGraph, bool copyPaste = false) /* Missing node class should be handled before get graph */ CeresAPI.Assert(nodeView != null, $"Can not construct node view for type {nodeInstance.GetType()}"); _graphView.AddNodeView(nodeView); - newElements.Add(nodeView.NodeElement); + newElements.Add(nodeView!.NodeElement); try { nodeView.SetNodeInstance(nodeInstance); @@ -293,7 +293,7 @@ public void DeserializeGraph(FlowGraph flowGraph, bool copyPaste = false) CeresAPI.LogError($"Failed to restore properties from {nodeInstance}\n{e}"); } } - foreach (var nodeView in newElements.OfType().Select(x=>x.View).ToArray()) + foreach (var nodeView in newElements.OfType().Select(x=> x.View).ToArray()) { // Restore edges nodeView.ReconnectEdges(); diff --git a/Editor/Flow/Nodes/ExecutableEventNodeView.cs b/Editor/Flow/Nodes/ExecutableEventNodeView.cs index 7185f4d..4254911 100644 --- a/Editor/Flow/Nodes/ExecutableEventNodeView.cs +++ b/Editor/Flow/Nodes/ExecutableEventNodeView.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Reflection; using Ceres.Graph; using Ceres.Graph.Flow; @@ -34,22 +35,46 @@ public override void SetNodeInstance(CeresNode ceresNode) var eventNode = (ExecutableEvent)ceresNode; base.SetNodeInstance(eventNode); IsImplementable = eventNode.isImplementable; - if(IsImplementable) + if (IsImplementable) { var methodInfo = GetContainerType().GetMethod(eventNode.eventName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - if (methodInfo == null) + if (methodInfo != null) { - CeresAPI.LogWarning($"{eventNode.eventName} is not an implementable event of {GetContainerType().Name}"); + SetMethodInfo(methodInfo); + UpdateEventTitle(); return; } - SetMethodInfo(methodInfo); + /* Change to normal execution event and validate event name */ + CeresAPI.LogWarning($"{eventNode.eventName} is not an implementable event of {GetContainerType().Name}"); + IsImplementable = false; } + ValidateEventName(); UpdateEventTitle(); } - protected void UpdateEventTitle() + private void ValidateEventName() + { + var existEventNodes = GraphView.NodeViews + .OfType() + .Except(new [] { this }) + .ToArray(); + var eventName = GetEventName(); + var newEventName = eventName; + int i = 0; + while (existEventNodes.Any(node => node.GetEventName() == newEventName)) + { + newEventName = $"{eventName} {++i}"; + } + + if (newEventName != eventName) + { + _eventNameResolver.Value = newEventName; + } + } + + private void UpdateEventTitle() { - string label = "Event " + GetEventName(); + var label = "Event " + GetEventName(); if(IsImplementable) { label += CeresNode.GetTargetSubtitle(GetContainerType().Name); @@ -78,6 +103,7 @@ public string GetEventName() public void SetEventName(string eventName) { _eventNameResolver.Value = eventName; + ValidateEventName(); } private void FillNodeTitle() diff --git a/Runtime/Core/Models/Graph/Nodes/NodeAPIUpdateConfig.cs b/Runtime/Core/Models/Graph/Nodes/NodeAPIUpdateConfig.cs index bddddae..db39b90 100644 --- a/Runtime/Core/Models/Graph/Nodes/NodeAPIUpdateConfig.cs +++ b/Runtime/Core/Models/Graph/Nodes/NodeAPIUpdateConfig.cs @@ -21,7 +21,6 @@ public Type ToType() if (!overrideType.Enabled) return nodeType; var tokens = overrideType.Value.Split(' '); return new CeresNodeData.NodeType(tokens[0], tokens[1], tokens[2]).ToType(); - } public string GetFullTypeName() From 1331e7e19ff845972dff80a6c1da10bf09618316 Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Fri, 31 Jan 2025 14:24:35 +0800 Subject: [PATCH 8/9] Update Test Scene.unity --- Tests/Assets/Test Scene.unity | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Tests/Assets/Test Scene.unity b/Tests/Assets/Test Scene.unity index 6805b50..b5ece56 100644 --- a/Tests/Assets/Test Scene.unity +++ b/Tests/Assets/Test Scene.unity @@ -170,23 +170,23 @@ MonoBehaviour: graphData: variables: [] nodes: - - rid: 3700340990917214291 - - rid: 3700340990917214292 - - rid: 3700340990917214293 + - rid: 3700341120743243790 + - rid: 3700341120743243791 + - rid: 3700341120743243792 - rid: -2 - - rid: 3700340990917214294 + - rid: 3700341120743243793 - rid: -2 - rid: -2 - rid: -2 - rid: -2 - rid: -2 - - rid: 3700340990917214295 + - rid: 3700341120743243794 - rid: -2 - rid: -2 - rid: -2 - - rid: 3700340990917214296 - - rid: 3700340990917214297 - - rid: 3700340990917214298 + - rid: 3700341120743243795 + - rid: 3700341120743243796 + - rid: 3700341120743243797 - rid: -2 nodeData: - graphPosition: @@ -292,7 +292,7 @@ MonoBehaviour: _asm: Ceres genericParameters: - Ceres.Tests.TestFlowGraphObject, Ceres.Tests##0 - serializedData: '{"input":{"defaultValue":{"guid":""}},"exec":{"defaultValue":{"guid":""}},"methodName":"TestFunctionVoid","parameterCount":0,"isStatic":false,"executeInDependency":false,"isSelfTarget":false,"isScriptMethod":false,"target":{"defaultValue":{"instanceID":0}}}' + serializedData: '{"input":{"defaultValue":{"guid":""}},"exec":{"defaultValue":{"guid":""}},"methodName":"TestFunctionVoid","parameterCount":0,"isStatic":false,"executeInDependency":false,"isSelfTarget":true,"isScriptMethod":false,"target":{"defaultValue":{"instanceID":0}}}' executionPath: 0 portData: - type: Ceres.Graph.NodeReference, Ceres##0 @@ -427,7 +427,7 @@ MonoBehaviour: - System.String, mscorlib##0 - System.String, mscorlib##0 - System.String, mscorlib##0 - serializedData: '{"input":{"defaultValue":{"guid":""}},"exec":{"defaultValue":{"guid":""}},"methodName":"TestFunctionReturn","parameterCount":2,"isStatic":false,"executeInDependency":false,"isSelfTarget":false,"isScriptMethod":false,"target":{"defaultValue":{"instanceID":0}},"input1":{"defaultValue":""},"input2":{"defaultValue":""},"output":{"defaultValue":""}}' + serializedData: '{"input":{"defaultValue":{"guid":""}},"exec":{"defaultValue":{"guid":""}},"methodName":"TestFunctionReturn","parameterCount":2,"isStatic":false,"executeInDependency":false,"isSelfTarget":true,"isScriptMethod":false,"target":{"defaultValue":{"instanceID":0}},"input1":{"defaultValue":""},"input2":{"defaultValue":""},"output":{"defaultValue":""}}' executionPath: 0 portData: - type: Ceres.Graph.NodeReference, Ceres##0 @@ -822,7 +822,7 @@ MonoBehaviour: _asm: Ceres genericParameters: - Ceres.Tests.TestFlowGraphObject, Ceres.Tests##0 - serializedData: '{"input":{"defaultValue":{"guid":""}},"exec":{"defaultValue":{"guid":""}},"methodName":"TestImplementableEvent","parameterCount":0,"isStatic":false,"executeInDependency":false,"isSelfTarget":false,"isScriptMethod":false,"target":{"defaultValue":{"instanceID":0}}}' + serializedData: '{"input":{"defaultValue":{"guid":""}},"exec":{"defaultValue":{"guid":""}},"methodName":"TestImplementableEvent","parameterCount":0,"isStatic":false,"executeInDependency":false,"isSelfTarget":true,"isScriptMethod":false,"target":{"defaultValue":{"instanceID":0}}}' executionPath: 0 portData: - type: Ceres.Graph.NodeReference, Ceres##0 @@ -863,7 +863,7 @@ MonoBehaviour: RefIds: - rid: -2 type: {class: , ns: , asm: } - - rid: 3700340990917214291 + - rid: 3700341120743243790 type: {class: FlowNode_DebugLogString, ns: Ceres.Graph.Flow.Utilities, asm: Ceres} data: input: @@ -875,7 +875,7 @@ MonoBehaviour: logType: 3 inString: defaultValue: Test Object Start - - rid: 3700340990917214292 + - rid: 3700341120743243791 type: {class: ExecutionEvent, ns: Ceres.Graph.Flow, asm: Ceres} data: eventName: Start @@ -883,7 +883,7 @@ MonoBehaviour: exec: defaultValue: guid: - - rid: 3700340990917214293 + - rid: 3700341120743243792 type: {class: ExecutionEvent, ns: Ceres.Graph.Flow, asm: Ceres} data: eventName: OnTimerEnd @@ -891,7 +891,7 @@ MonoBehaviour: exec: defaultValue: guid: - - rid: 3700340990917214294 + - rid: 3700341120743243793 type: {class: FlowNode_Sequence, ns: Ceres.Graph.Flow.Utilities, asm: Ceres} data: input: @@ -899,7 +899,7 @@ MonoBehaviour: guid: outputs: [] outputCount: 3 - - rid: 3700340990917214295 + - rid: 3700341120743243794 type: {class: FlowNode_DebugLogString, ns: Ceres.Graph.Flow.Utilities, asm: Ceres} data: input: @@ -911,7 +911,7 @@ MonoBehaviour: logType: 3 inString: defaultValue: - - rid: 3700340990917214296 + - rid: 3700341120743243795 type: {class: FlowNode_DebugLogString, ns: Ceres.Graph.Flow.Utilities, asm: Ceres} data: input: @@ -923,7 +923,7 @@ MonoBehaviour: logType: 3 inString: defaultValue: Try Destroy Test Object - - rid: 3700340990917214297 + - rid: 3700341120743243796 type: {class: ExecutionEvent, ns: Ceres.Graph.Flow, asm: Ceres} data: eventName: OnDestroy @@ -931,7 +931,7 @@ MonoBehaviour: exec: defaultValue: guid: - - rid: 3700340990917214298 + - rid: 3700341120743243797 type: {class: FlowNode_DebugLogString, ns: Ceres.Graph.Flow.Utilities, asm: Ceres} data: input: From 61c6b94199e2b6b620d3305fbe7aff17b69ada70 Mon Sep 17 00:00:00 2001 From: AkiKurisu <2683987717@qq.com> Date: Fri, 31 Jan 2025 14:25:19 +0800 Subject: [PATCH 9/9] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 808c80d..407ec2f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.kurisu.ceres", "displayName": "Ceres", - "version": "0.1.5", + "version": "0.1.6", "unity": "2022.3", "description": "Powerful visual scripting toolkit for Unity.", "keywords": [