SNVZVI6EFLP6UDCYDY3CWR4TK5N2TEUCLYOTY3DUIOQLJ3SM2NIAC
fileFormatVersion: 2
guid: f06b9a389558b514a969be1abd1ea363
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7ecce817215a35042a6cf88cd1571091
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f4a34c9aed5be0f4d8f1a5b999e16107
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEditor;
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using TagFighter.Dialogue;
using System.Linq;
using System.Collections.Generic;
using System;
public class DialogueView : GraphView
{
Dialogue _dialogue;
public Dialogue DisplayedDialogue { get { return _dialogue; } }
public Action<DialogueNodeView> OnNodeSelected;
public new class UxmlFactory : UxmlFactory<DialogueView, GraphView.UxmlTraits> { }
public DialogueView() {
Insert(0, new GridBackground());
this.AddManipulator(new ContentZoomer());
this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector());
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Editor/Dialogue/DialogueEditor.uss");
styleSheets.Add(styleSheet);
}
internal void PopulateView(Dialogue dialogueCandidate) {
graphViewChanged -= OnGraphViewChanged;
DeleteElements(graphElements);
_dialogue = dialogueCandidate;
if (_dialogue == null) {
return;
}
graphViewChanged += OnGraphViewChanged;
CreateNodeViews();
CreateEdges();
}
void CreateNodeViews() {
foreach (var node in _dialogue.Nodes) {
CreateNodeView(node);
}
}
void CreateEdges() {
foreach (var parentNode in _dialogue.Nodes) {
var parentView = GetNodeByGuid(parentNode.name) as DialogueNodeView;
foreach (var child in parentNode.GetChildren()) {
var childView = GetNodeByGuid(child) as DialogueNodeView;
var edge = parentView.Output.ConnectTo(childView.Input);
AddElement(edge);
}
}
}
GraphViewChange OnGraphViewChanged(GraphViewChange graphViewChange) {
if (graphViewChange.elementsToRemove != null) {
foreach (var elementToRemove in graphViewChange.elementsToRemove) {
switch (elementToRemove) {
case DialogueNodeView dialogueNodeView:
_dialogue.DeleteNode(dialogueNodeView.Node);
break;
case Edge edge:
var parent = edge.output.node as DialogueNodeView;
var child = edge.input.node as DialogueNodeView;
parent.Node.RemoveChild(child.viewDataKey);
break;
}
}
}
if (graphViewChange.edgesToCreate != null) {
foreach (var edge in graphViewChange.edgesToCreate) {
var parent = edge.output.node as DialogueNodeView;
var child = edge.input.node as DialogueNodeView;
parent.Node.AddChild(child.viewDataKey);
}
}
return graphViewChange;
}
public override void BuildContextualMenu(ContextualMenuPopulateEvent e) {
// base.BuildContextualMenu(e);
{
e.menu.AppendAction($"Create DialogueNode", action => CreateNode(action.eventInfo.mousePosition));
}
}
public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) {
return ports.Where(endPort => endPort.direction != startPort.direction && endPort.node != startPort.node).ToList();
}
void CreateNode(UnityEngine.Vector2 position) {
if (_dialogue == null) {
return;
}
var node = _dialogue.CreateNode(null);
node.Position = viewTransform.matrix.inverse.MultiplyPoint(this.WorldToLocal(position));
CreateNodeView(node);
}
void CreateNodeView(DialogueNode node) {
DialogueNodeView nodeView = new(node) {
OnNodeSelected = OnNodeSelected,
};
AddElement(nodeView);
}
}
fileFormatVersion: 2
guid: 2874561c56f5f8b4aadc2d8392fde4d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.Dialogue;
using UnityEngine;
// using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using System;
using UnityEngine.UIElements;
public class DialogueNodeView : UnityEditor.Experimental.GraphView.Node
{
public Action<DialogueNodeView> OnNodeSelected;
public DialogueNode Node;
public Port Input;
public Port Output;
public DialogueNodeView(DialogueNode node) {
Node = node;
title = Node.name;
viewDataKey = Node.name;
name = Node.name;
style.left = Node.Position.x;
style.top = Node.Position.y;
CreateTextField();
CreateInputPorts();
CreateOutputPorts();
}
void CreateTextField() {
var textField = new TextField {
value = Node.Text
};
textField.RegisterValueChangedCallback(OnDialogueNodeTextChanged);
textField.RegisterCallback<FocusInEvent>(OnTextFieldFocusIn);
mainContainer.Add(textField);
}
void OnTextFieldFocusIn(FocusInEvent e) {
OnSelected();
}
void OnDialogueNodeTextChanged(ChangeEvent<string> e) {
Node.Text = e.newValue;
}
void CreateInputPorts() {
Input = InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(bool));
if (Input != null) {
Input.portName = "";
inputContainer.Add(Input);
}
}
void CreateOutputPorts() {
Output = InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(bool));
if (Output != null) {
Output.portName = "";
outputContainer.Add(Output);
}
}
public override void SetPosition(Rect newPosition) {
base.SetPosition(newPosition);
Node.Position = newPosition.position;
}
public override void OnSelected() {
base.OnSelected();
OnNodeSelected?.Invoke(this);
}
}
fileFormatVersion: 2
guid: 4f726eba9d15345479364bc37cfe449b
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<Style src="project://database/Assets/Editor/Dialogue/DialogueEditor.uss?fileID=7433441132597879392&guid=ca526201d16284e4fb91cfded5d4be36&type=3#DialogueEditor" />
<DialogueView focusable="true" style="flex-grow: 1;" />
</ui:UXML>
fileFormatVersion: 2
guid: ca526201d16284e4fb91cfded5d4be36
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
GridBackground {
--grid-background-color: rgb(40, 40, 40);
--line-color: rgba(193, 196, 192, 0.1);
--thick-line-color: rgba(193, 196, 192, 0.1);
--spacing: 15;
}
fileFormatVersion: 2
guid: 881772986d0760e418c4359a640e74d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.Dialogue;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.UIElements;
public class DialogueEditor : EditorWindow
{
DialogueView _dialogueView;
[SerializeField]
Dialogue _selectedDialogue;
[MenuItem("TagFighter/DialogueEditor")]
public static void ShowEditorWindow() {
var window = GetWindow<DialogueEditor>();
window.titleContent = new GUIContent("DialogueEditor");
window.UpdateEditorView();
}
[OnOpenAsset(1)]
public static bool OnOpenAsset(int instanceID, int line) {
var dialogue = EditorUtility.InstanceIDToObject(instanceID) as Dialogue;
if (dialogue != null) {
ShowEditorWindow();
return true;
}
return false;
}
public void CreateGUI() {
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// Import UXML
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/Dialogue/DialogueEditor.uxml");
visualTree.CloneTree(root);
// A stylesheet can be added to a VisualElement.
// The style will be applied to the VisualElement and all of its children.
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Editor/Dialogue/DialogueEditor.uss");
root.styleSheets.Add(styleSheet);
_dialogueView = root.Q<DialogueView>();
_dialogueView.OnNodeSelected = OnNodeSelectionChanged;
UpdateEditorView();
}
void UpdateEditorView() {
_dialogueView.PopulateView(_selectedDialogue);
}
void OnSelectionChanged() {
// AssetDatabase.CanOpenAssetInEditor(dialogueCandidate.GetInstanceID())
switch (Selection.activeObject) {
case Dialogue dialogue:
_selectedDialogue = dialogue;
UpdateEditorView();
break;
case DialogueNode node:
var dialogueCandidate = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(Selection.activeObject)) as Dialogue;
if (_selectedDialogue != dialogueCandidate) {
_selectedDialogue = dialogueCandidate;
UpdateEditorView();
}
break;
default:
if (_selectedDialogue == null) {
UpdateEditorView();
}
break;
}
}
void OnNodeSelectionChanged(DialogueNodeView nodeView) {
Selection.activeObject = nodeView.Node;
}
void OnUndoRedo() {
_dialogueView.PopulateView(_selectedDialogue);
}
void OnEnable() {
Undo.undoRedoPerformed += OnUndoRedo;
Selection.selectionChanged += OnSelectionChanged;
}
void OnDisable() {
Undo.undoRedoPerformed -= OnUndoRedo;
Selection.selectionChanged -= OnSelectionChanged;
}
}