Added defualt graph properties inspector;

Added sticky note;

Changed the name of BaseNode to SlotContainerNode in case we need other type of nodes in the future;
This commit is contained in:
Misaki
2024-11-04 01:02:30 +09:00
parent 5a9d8b9420
commit 7eec130b39
53 changed files with 517 additions and 436 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
@@ -9,15 +10,18 @@ namespace Misaki.GraphView
public abstract class GraphObject : ScriptableObject
{
[SerializeReference]
private List<BaseNode> _nodes = new();
private List<SlotContainerNode> _nodes = new();
[SerializeField]
private List<StickyNoteData> _stickyNotes = new();
[SerializeField]
private List<SlotConnection> _connections = new();
[SerializeReference]
private List<ExposedProperty> _exposedProperties = new();
private readonly Dictionary<string, BaseNode> _nodeMap = new();
private readonly Dictionary<string, SlotContainerNode> _nodeMap = new();
public ReadOnlyCollection<BaseNode> Nodes => _nodes.AsReadOnly();
public ReadOnlyCollection<SlotContainerNode> Nodes => _nodes.AsReadOnly();
public ReadOnlyCollection<StickyNoteData> StickyNotes => _stickyNotes.AsReadOnly();
public ReadOnlyCollection<SlotConnection> Connections => _connections.AsReadOnly();
public ReadOnlyCollection<ExposedProperty> ExposedProperties => _exposedProperties.AsReadOnly();
@@ -37,39 +41,49 @@ namespace Misaki.GraphView
}
}
public void AddNode(BaseNode baseNode)
public void AddNode(SlotContainerNode slotContainerNode)
{
_nodes.Add(baseNode);
TryAddNodeToMap(baseNode);
baseNode.Initialize(this);
_nodes.Add(slotContainerNode);
TryAddNodeToMap(slotContainerNode);
slotContainerNode.Initialize(this);
}
public void RemoveNode(BaseNode baseNode)
public void RemoveNode(SlotContainerNode slotContainerNode)
{
_nodes.Remove(baseNode);
RemoveNodeFromMap(baseNode);
baseNode.UnLoad();
baseNode.UnlinkAllSlots();
_nodes.Remove(slotContainerNode);
RemoveNodeFromMap(slotContainerNode);
slotContainerNode.UnLoad();
slotContainerNode.UnlinkAllSlots();
}
public bool TryAddNodeToMap(BaseNode baseNode)
public bool TryAddNodeToMap(SlotContainerNode slotContainerNode)
{
return _nodeMap.TryAdd(baseNode.Id, baseNode);
return _nodeMap.TryAdd(slotContainerNode.Id, slotContainerNode);
}
public void RemoveNodeFromMap(BaseNode baseNode)
public void RemoveNodeFromMap(SlotContainerNode slotContainerNode)
{
_nodeMap.Remove(baseNode.Id);
_nodeMap.Remove(slotContainerNode.Id);
}
public BaseNode GetNode(string id)
public SlotContainerNode GetNode(string id)
{
return _nodeMap.GetValueOrDefault(id);
}
public bool TryGetNode(string id, out BaseNode baseNode)
public bool TryGetNode(string id, out SlotContainerNode slotContainerNode)
{
return _nodeMap.TryGetValue(id, out baseNode);
return _nodeMap.TryGetValue(id, out slotContainerNode);
}
public void AddStickyNote(StickyNoteData stickyNote)
{
_stickyNotes.Add(stickyNote);
}
public void RemoveStickyNote(StickyNoteData stickyNote)
{
_stickyNotes.Remove(stickyNote);
}
public void AddConnection(SlotConnection connection)
@@ -104,7 +118,7 @@ namespace Misaki.GraphView
_exposedProperties.Remove(property);
}
public void SetTransform(ITransform transform)
public void SetGraphTransform(ITransform transform)
{
graphPosition = transform.position;
graphScale = transform.scale;

View File

@@ -3,7 +3,7 @@ using UnityEngine;
namespace Misaki.GraphView
{
public class PropertyInputNode : BaseNode
public class PropertyInputNode : SlotContainerNode
{
[SerializeReference]
private ExposedProperty _property;

View File

@@ -5,7 +5,7 @@ using UnityEngine;
namespace Misaki.GraphView
{
[Serializable]
public abstract class BaseNode : SlotContainer
public abstract class SlotContainerNode : SlotContainer
{
[SerializeField]
private GraphObject _graphObject;
@@ -20,16 +20,21 @@ namespace Misaki.GraphView
public string Id => _id;
public Action OnExecutionCompleted;
public Action<BaseNode> OnExecutionFailed;
public Action<SlotContainerNode> OnExecutionFailed;
public Action OnExecuteFlagCleared;
/// <summary>
/// Initialize the node with the graph object, this method is called when the node is added to the graph.
/// </summary>
public virtual void Initialize(GraphObject graph)
public void Initialize(GraphObject graph)
{
_graphObject = graph;
InitializeSlot();
}
public virtual void InitializeSlot()
{
var type = GetType();
var fields = type.GetFields(ConstResource.NODE_FIELD_BINDING_FLAGS);

View File

@@ -8,6 +8,7 @@ namespace Misaki.GraphView
public string id = Guid.NewGuid().ToString();
public string propertyName;
public string propertyType;
public bool showInInspector = true;
public virtual object Value { get; set; }
public virtual Type GetValueType() => Value == null ? typeof(object) : Value.GetType();

View File

@@ -50,12 +50,12 @@ namespace Misaki.GraphView
public ReadOnlyCollection<SlotData> LinkedSlotData => _linkedSlotData.AsReadOnly();
[SerializeReference]
public BaseNode owner;
public SlotContainerNode owner;
public SlotData slotData;
public object value;
public Slot(BaseNode owner, SlotData slotData)
public Slot(SlotContainerNode owner, SlotData slotData)
{
this.owner = owner;
this.slotData = slotData;

View File

@@ -0,0 +1,22 @@
using System;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
namespace Misaki.GraphView
{
[Serializable]
public class StickyNoteData
{
[SerializeField]
private string _id = Guid.NewGuid().ToString();
public string title;
public string contents;
public Rect position;
public StickyNoteTheme theme;
public StickyNoteFontSize fontSize;
public string Id => _id;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3b18c70789034fef8f94030eefab46bb
timeCreated: 1730597117