1.create search panel when right click

main
taoria 3 years ago
parent 51d1973964
commit 7de3b8158c
  1. 13
      TNode/Attribute/NodeAttribute.cs
  2. 3
      TNode/Attribute/NodeAttribute.cs.meta
  3. 23
      TNode/Editor/BaseViews/DataGraphView.cs
  4. 2
      TNode/Editor/BaseViews/NodeView.cs
  5. 21
      TNode/Editor/GraphEditor.cs
  6. 2
      TNode/Editor/GraphEditorData.cs
  7. 18
      TNode/Editor/SearchWindowProvider.cs
  8. 3
      TNode/Editor/SearchWindowProvider.cs.meta
  9. 2
      TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs
  10. 2
      TNode/Models/NodeLink.cs

@ -0,0 +1,13 @@
using JetBrains.Annotations;
using TNode.Models;
namespace TNode.Attribute{
[MeansImplicitUse]
[BaseTypeRequired(typeof(NodeData))]
public class NodeAttribute:System.Attribute{
public NodeAttribute(GraphData graphData){
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2311dd22c61449b7aa44b37085623fc4
timeCreated: 1656298063

@ -1,7 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using TNode.BaseViews;
using TNode.Cache;
using TNode.Models;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
@ -28,10 +30,10 @@ namespace TNode.Editor.BaseViews{
RegisterCallback<ContextualMenuPopulateEvent>(evt => {
var pos = evt.mousePosition;
evt.menu.AppendAction("Add Node", (dropMenuAction) => {
evt.menu.AppendAction("Add NodeAttribute", (dropMenuAction) => {
DialogueNodeView nodeView = new DialogueNodeView{
GUID = Guid.NewGuid().ToString(),
title = "New Node"
title = "New NodeAttribute"
};
// make it a 200x100 box
nodeView.SetPosition(new Rect(pos.x - 100, pos.y - 50, 200, 100));
@ -102,7 +104,7 @@ namespace TNode.Editor.BaseViews{
*/
public abstract class DataGraphView<T>:GraphView where T:GraphData{
private T _data;
private SearchWindowProvider _searchWindowProvider;
public T Data{
get{ return _data; }
set{
@ -128,7 +130,7 @@ namespace TNode.Editor.BaseViews{
//Get the node type
var nodeType = dataNode.GetType();
//Get the derived type of Node View from the node type
//Get the derived type of NodeAttribute View from the node type
var nodeViewType = typeof(NodeView<>).MakeGenericType(nodeType);
//Fetch the node view from the node view type
@ -156,7 +158,18 @@ namespace TNode.Editor.BaseViews{
public event DataChangedEventHandler OnDataChanged;
public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs<T> e);
private void ConstructDefaultBehaviour(){
//Register a right click context menu
//ConstructContextualMenuOption();
}
public void ConstructViewContextualMenu(EventCallback<ContextualMenuPopulateEvent> callback){
RegisterCallback<ContextualMenuPopulateEvent>(callback);
}
private void OnInit(){
ConstructDefaultBehaviour();
OnGraphViewCreate();
}

@ -4,7 +4,7 @@ using UnityEditor.Experimental.GraphView;
namespace TNode.BaseViews{
//A Node monitor some type of node in the graph
//A NodeAttribute monitor some type of node in the graph
public abstract class NodeView<T> : Node where T:NodeData,new(){
protected T _data;

@ -5,6 +5,7 @@ using TNode.Editor.BaseViews;
using TNode.Editor.Model;
using TNode.Models;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
@ -38,6 +39,26 @@ namespace TNode.Editor{
_graphView = NodeEditorExtensions.CreateInstance<DataGraphView<T>>();
rootVisualElement.Add(_graphView);
_graphView.StretchToParentSize();
_graphView.ConstructViewContextualMenu(evt => {
//Current issue is that the search window don't show up at the exact position of the mouse click by dma.eventInfo.mousePosition
//So I have to manually set the position of the search window to fit the mouse click position by add an offset driven by Editor's position
//Maybe a better way exists to fix this issue
Vector2 editorPosition = this.position.position;
evt.menu.AppendAction("Create Node", dma => {
var dmaPos = dma.eventInfo.mousePosition+editorPosition;
SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200);
SearchWindow.Open(searchWindowContext, ScriptableObject.CreateInstance<SearchWindowProvider>());
});
});
}
private void ConstructSearchWindow(){
//Register a search window
}
private void DefineGraphEditorActions(){

@ -4,7 +4,7 @@ using UnityEngine;
namespace TNode.Editor{
[CreateAssetMenu(fileName = "Node Editor Config", menuName = "TNode/Node Editor Config")]
[CreateAssetMenu(fileName = "NodeAttribute Editor Config", menuName = "TNode/NodeAttribute Editor Config")]
public class GraphEditorData:ScriptableObject{
public List<NodeEditorData> nodesData;

@ -0,0 +1,18 @@
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
namespace TNode.Editor{
public class SearchWindowProvider:ScriptableObject,ISearchWindowProvider{
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context){
var list = new List<SearchTreeEntry>();
list.Add(new SearchTreeGroupEntry(new GUIContent("Add New Node"), 0));
list.Add(new SearchTreeGroupEntry(new GUIContent("Add Placemat"), 0));
return list;
}
public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context){
return false;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1daac5c2c1794f36933cdbc922840769
timeCreated: 1656314210

@ -138,7 +138,7 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
EditorApplication.update();
}
//Create an Node Editor Data Instance for the new graph editor
//Create an NodeAttribute Editor Data Instance for the new graph editor
NodeEditorData nodeEditorData = ScriptableObject.CreateInstance<NodeEditorData>();
nodeEditorData.name = editorName;
EditorUtility.SetDirty(nodeEditorData);

@ -2,7 +2,7 @@
using Dialogue;
namespace TNode.Models{
//Node links are stored in output side of the two node port.
//NodeAttribute links are stored in output side of the two node port.
[Serializable]
public class NodeLink{
// public DialogueNodePortData From{ get; }

Loading…
Cancel
Save