DataEditor & StorySystem Graph
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using SLSFramework.StorySystem.Dialog;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SLSFramework.StorySystem
|
||||
{
|
||||
// 自定义节点的基础类,用于存储对应的数据
|
||||
public abstract class BaseGraphNode : Node
|
||||
{
|
||||
public BaseNodeData NodeData { get; private set; }
|
||||
|
||||
protected BaseGraphNode(BaseNodeData data)
|
||||
{
|
||||
NodeData = data;
|
||||
title = data.GetType().Name.Replace("Data", ""); // 自动设置标题, e.g. "StartNodeData" -> "StartNode"
|
||||
SetPosition(new Rect(data.position, Vector2.zero)); // Vector2.zero size 会被自动计算
|
||||
viewDataKey = data.guid; // 确保GUID一致
|
||||
}
|
||||
|
||||
// 辅助方法:创建端口
|
||||
protected Port CreatePort(Direction direction, Port.Capacity capacity = Port.Capacity.Single, string portName = "")
|
||||
{
|
||||
// 如果未指定端口名,则使用方向的默认值
|
||||
if (string.IsNullOrEmpty(portName))
|
||||
{
|
||||
portName = direction == Direction.Input ? "Input" : "Output";
|
||||
}
|
||||
|
||||
var port = InstantiatePort(Orientation.Horizontal, direction, capacity, typeof(bool));
|
||||
port.portName = portName;
|
||||
port.name = portName;
|
||||
|
||||
return port;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89062ba4c7f90314c86ed9cedb4053cf
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace SLSFramework.StorySystem
|
||||
{
|
||||
public class ConditionGraphNode : BaseGraphNode
|
||||
{
|
||||
private ConditionNodeData _data;
|
||||
|
||||
public ConditionGraphNode(ConditionNodeData data) : base(data)
|
||||
{
|
||||
_data = data;
|
||||
|
||||
var titleContainer = this.Q("title");
|
||||
titleContainer.style.backgroundColor = new StyleColor(new Color(0.4f, 0.2f, 0.6f)); // 紫色
|
||||
|
||||
// 1. 添加端口
|
||||
var inputPort = CreatePort(Direction.Input, Port.Capacity.Multi, "Previous");
|
||||
|
||||
// Condition 节点有两个输出
|
||||
var truePort = CreatePort(Direction.Output, Port.Capacity.Single, "True");
|
||||
var falsePort = CreatePort(Direction.Output, Port.Capacity.Single, "False");
|
||||
|
||||
inputContainer.Add(inputPort);
|
||||
outputContainer.Add(truePort);
|
||||
outputContainer.Add(falsePort);
|
||||
|
||||
// 2. 添加自定义UI字段 (条件语句)
|
||||
var conditionField = new TextField("Condition") { multiline = true };
|
||||
|
||||
conditionField.SetValueWithoutNotify(_data.conditionString);
|
||||
conditionField.RegisterValueChangedCallback(evt => {
|
||||
_data.conditionString = evt.newValue;
|
||||
});
|
||||
|
||||
// 调整TextArea的样式
|
||||
conditionField.Q("unity-text-input").style.minWidth = 150;
|
||||
|
||||
extensionContainer.Add(conditionField);
|
||||
|
||||
// 刷新布局
|
||||
RefreshExpandedState();
|
||||
RefreshPorts();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95a4ba99bc298c74283b008b8b25b8bd
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace SLSFramework.StorySystem
|
||||
{
|
||||
public class EndGraphNode : BaseGraphNode
|
||||
{
|
||||
public EndGraphNode(EndNodeData data) : base(data)
|
||||
{
|
||||
var titleContainer = this.Q("title");
|
||||
titleContainer.style.backgroundColor = new StyleColor(new Color(0.4f, 0.4f, 0.2f)); // 红色
|
||||
|
||||
// End 节点只有一个输入端口
|
||||
var inputPort = CreatePort(Direction.Input, Port.Capacity.Multi, "Previous");
|
||||
inputContainer.Add(inputPort);
|
||||
|
||||
// 刷新端口和布局
|
||||
RefreshExpandedState();
|
||||
RefreshPorts();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e82960b057418454eab7e7eefcc71a14
|
||||
@@ -0,0 +1,43 @@
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace SLSFramework.StorySystem.Dialog
|
||||
{
|
||||
public class EventGraphNode : BaseGraphNode
|
||||
{
|
||||
private EventNodeData _data;
|
||||
|
||||
public EventGraphNode(EventNodeData data) : base(data)
|
||||
{
|
||||
_data = data;
|
||||
|
||||
var titleContainer = this.Q("title");
|
||||
titleContainer.style.backgroundColor = new StyleColor(new Color(0.1f, 0.5f, 0.5f)); // 青色
|
||||
|
||||
// 1. 添加端口
|
||||
var inputPort = CreatePort(Direction.Input, Port.Capacity.Multi, "Previous");
|
||||
var outputPort = CreatePort(Direction.Output, Port.Capacity.Single, "Next");
|
||||
|
||||
inputContainer.Add(inputPort);
|
||||
outputContainer.Add(outputPort);
|
||||
|
||||
// 2. 添加自定义UI字段 (事件语句)
|
||||
var eventField = new TextField("Event") { multiline = true };
|
||||
|
||||
eventField.SetValueWithoutNotify(_data.eventString);
|
||||
eventField.RegisterValueChangedCallback(evt => {
|
||||
_data.eventString = evt.newValue;
|
||||
});
|
||||
|
||||
// 调整TextArea的样式
|
||||
eventField.Q("unity-text-input").style.minWidth = 150;
|
||||
|
||||
extensionContainer.Add(eventField);
|
||||
|
||||
// 刷新布局
|
||||
RefreshExpandedState();
|
||||
RefreshPorts();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baf926c674d6ea842b99cda704461ee2
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace SLSFramework.StorySystem
|
||||
{
|
||||
public class StartGraphNode : BaseGraphNode
|
||||
{
|
||||
public StartGraphNode(StartNodeData data) : base(data)
|
||||
{
|
||||
VisualElement titleContainer = this.Q("title");
|
||||
titleContainer.style.backgroundColor = new StyleColor(new Color(0.2f, 0.5f, 0.2f)); // 绿色
|
||||
|
||||
// Start 节点只有一个输出端口
|
||||
var outputPort = CreatePort(Direction.Output, Port.Capacity.Single, "Next");
|
||||
outputContainer.Add(outputPort);
|
||||
|
||||
// 刷新端口和布局
|
||||
RefreshExpandedState();
|
||||
RefreshPorts();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3bf9fbf0029def4bbb8ce1e1ed0628c
|
||||
Reference in New Issue
Block a user