Added IExecutable and ISlotContainer interface.
Changed SlotContainerNode to ExecutableNode
This commit is contained in:
43
Editor/Views/Blackboard/BlackboardPropertyView.cs
Normal file
43
Editor/Views/Blackboard/BlackboardPropertyView.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.GraphView.Editor
|
||||
{
|
||||
public class BlackboardPropertyView : BlackboardField, IInspectable
|
||||
{
|
||||
private readonly ExposedPropertyEditor _editor;
|
||||
|
||||
public Action<IInspectable> OnItemSelected { get; set; }
|
||||
public string InspectorName => text;
|
||||
|
||||
public BlackboardPropertyView(ExposedPropertyEditor editor)
|
||||
{
|
||||
_editor = editor;
|
||||
}
|
||||
|
||||
public override bool IsDroppable() => true;
|
||||
|
||||
public override void OnSelected()
|
||||
{
|
||||
base.OnSelected();
|
||||
OnItemSelected?.Invoke(this);
|
||||
}
|
||||
|
||||
public override void OnUnselected()
|
||||
{
|
||||
base.OnUnselected();
|
||||
OnItemSelected?.Invoke(null);
|
||||
}
|
||||
|
||||
public virtual ExecutableNodeView CreateNodeView()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual VisualElement CreateInspector()
|
||||
{
|
||||
return _editor.CreateInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Views/Blackboard/BlackboardPropertyView.cs.meta
Normal file
3
Editor/Views/Blackboard/BlackboardPropertyView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcc0238bd86d4454bc8c03cf8feadff2
|
||||
timeCreated: 1730456603
|
||||
120
Editor/Views/Blackboard/GraphBlackboardView.cs
Normal file
120
Editor/Views/Blackboard/GraphBlackboardView.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.GraphView.Editor
|
||||
{
|
||||
public class GraphBlackboardView : Blackboard
|
||||
{
|
||||
private readonly GraphObject _graphObject;
|
||||
private readonly GraphView _owner;
|
||||
private readonly SerializedObject _serializedObject;
|
||||
private readonly IExposedPropertyTypeManager _exposedPropertyTypeManager;
|
||||
|
||||
public Action<IInspectable> OnPropertySelected;
|
||||
|
||||
public GraphBlackboardView(GraphObject graphObject, GraphView owner, SerializedObject serializedObject, IExposedPropertyTypeManager exposedPropertyTypeManager)
|
||||
{
|
||||
style.marginBottom = 8;
|
||||
style.marginTop = 8;
|
||||
style.marginLeft = 8;
|
||||
style.marginRight = 8;
|
||||
|
||||
_graphObject = graphObject;
|
||||
_owner = owner;
|
||||
_serializedObject = serializedObject;
|
||||
_exposedPropertyTypeManager = exposedPropertyTypeManager;
|
||||
|
||||
title = "Exposed Properties";
|
||||
subTitle = graphObject.name;
|
||||
|
||||
addItemRequested = OnAddItemRequested;
|
||||
editTextRequested += OnEditTextRequested;
|
||||
}
|
||||
|
||||
private void OnAddItemRequested(Blackboard blackboard)
|
||||
{
|
||||
if (_exposedPropertyTypeManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var menu = new GenericMenu();
|
||||
|
||||
foreach (var type in _exposedPropertyTypeManager.GetPropertyTypes())
|
||||
{
|
||||
menu.AddItem(new GUIContent(type.Value.Name), false, () =>
|
||||
{
|
||||
AddProperty(type.Key);
|
||||
});
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
private void OnEditTextRequested(Blackboard blackboard, VisualElement element, string newValue)
|
||||
{
|
||||
if (element is BlackboardPropertyView propertyView)
|
||||
{
|
||||
propertyView.text = newValue;
|
||||
|
||||
if (propertyView.userData is not ExposedProperty exposedProperty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
exposedProperty.propertyName = newValue;
|
||||
_owner.Query<PropertyInputNodeView>().ForEach(n =>
|
||||
{
|
||||
if (n.Data.Property.Equals(exposedProperty))
|
||||
{
|
||||
n.title = newValue;
|
||||
}
|
||||
});
|
||||
|
||||
_serializedObject.Update();
|
||||
}
|
||||
}
|
||||
|
||||
private void AddProperty(Type type)
|
||||
{
|
||||
var property = Activator.CreateInstance(type) as ExposedProperty;
|
||||
|
||||
if (property == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
property.propertyName = $"New {property.GetValueType().Name} Property";
|
||||
property.propertyType = type.FullName;
|
||||
|
||||
AddProperty(property);
|
||||
|
||||
_graphObject.AddExposedProperty(property);
|
||||
_serializedObject.Update();
|
||||
}
|
||||
|
||||
public void AddProperty(ExposedProperty property)
|
||||
{
|
||||
var shortTypeName = property.GetValueType().Name;
|
||||
|
||||
var editorTypes = TypeCache.GetTypesWithAttribute<CustomInspectorAttribute>();
|
||||
var type = editorTypes.FirstOrDefault(t => t.GetCustomAttribute<CustomInspectorAttribute>().InspectorType == property.GetType()) ?? typeof(ExposedPropertyEditor);
|
||||
var editor = Activator.CreateInstance(type, property, _serializedObject) as ExposedPropertyEditor;
|
||||
|
||||
var blackboardField = new BlackboardPropertyView (editor)
|
||||
{
|
||||
text = property.propertyName,
|
||||
typeText = shortTypeName,
|
||||
userData = property,
|
||||
OnItemSelected = OnPropertySelected
|
||||
};
|
||||
|
||||
Add(blackboardField);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Views/Blackboard/GraphBlackboardView.cs.meta
Normal file
3
Editor/Views/Blackboard/GraphBlackboardView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdc2c6e3a651497baf0a42a19619d193
|
||||
timeCreated: 1730453741
|
||||
Reference in New Issue
Block a user