mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-04 14:24:54 +08:00
Fixed #128, #127, #64 - Added NodeEditorBase.OnCreate, OnGraphEditor.OnOpen, and NodeEditorBase.window
This commit is contained in:
parent
f6e0e3bc4d
commit
8adc4fd459
@ -269,7 +269,7 @@ namespace XNodeEditor {
|
|||||||
} else if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
} else if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
||||||
if (!Selection.Contains(hoveredNode)) SelectNode(hoveredNode, false);
|
if (!Selection.Contains(hoveredNode)) SelectNode(hoveredNode, false);
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
NodeEditor.GetEditor(hoveredNode).AddContextMenuItems(menu);
|
NodeEditor.GetEditor(hoveredNode, this).AddContextMenuItems(menu);
|
||||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||||
e.Use(); // Fixes copy/paste context menu appearing in Unity 5.6.6f2 - doesn't occur in 2018.3.2f1 Probably needs to be used in other places.
|
e.Use(); // Fixes copy/paste context menu appearing in Unity 5.6.6f2 - doesn't occur in 2018.3.2f1 Probably needs to be used in other places.
|
||||||
} else if (!IsHoveringNode) {
|
} else if (!IsHoveringNode) {
|
||||||
|
|||||||
@ -14,10 +14,11 @@ namespace XNodeEditor.Internal {
|
|||||||
/// <summary> Custom editors defined with [CustomNodeEditor] </summary>
|
/// <summary> Custom editors defined with [CustomNodeEditor] </summary>
|
||||||
private static Dictionary<Type, Type> editorTypes;
|
private static Dictionary<Type, Type> editorTypes;
|
||||||
private static Dictionary<K, T> editors = new Dictionary<K, T>();
|
private static Dictionary<K, T> editors = new Dictionary<K, T>();
|
||||||
|
public NodeEditorWindow window;
|
||||||
public K target;
|
public K target;
|
||||||
public SerializedObject serializedObject;
|
public SerializedObject serializedObject;
|
||||||
|
|
||||||
public static T GetEditor(K target) {
|
public static T GetEditor(K target, NodeEditorWindow window) {
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
T editor;
|
T editor;
|
||||||
if (!editors.TryGetValue(target, out editor)) {
|
if (!editors.TryGetValue(target, out editor)) {
|
||||||
@ -26,9 +27,12 @@ namespace XNodeEditor.Internal {
|
|||||||
editor = Activator.CreateInstance(editorType) as T;
|
editor = Activator.CreateInstance(editorType) as T;
|
||||||
editor.target = target;
|
editor.target = target;
|
||||||
editor.serializedObject = new SerializedObject(target);
|
editor.serializedObject = new SerializedObject(target);
|
||||||
|
editor.window = window;
|
||||||
|
editor.OnCreate();
|
||||||
editors.Add(target, editor);
|
editors.Add(target, editor);
|
||||||
}
|
}
|
||||||
if (editor.target == null) editor.target = target;
|
if (editor.target == null) editor.target = target;
|
||||||
|
if (editor.window != window) editor.window = window;
|
||||||
if (editor.serializedObject == null) editor.serializedObject = new SerializedObject(target);
|
if (editor.serializedObject == null) editor.serializedObject = new SerializedObject(target);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
@ -56,6 +60,9 @@ namespace XNodeEditor.Internal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Called on creation, after references have been set </summary>
|
||||||
|
public virtual void OnCreate() { }
|
||||||
|
|
||||||
public interface INodeEditorAttrib {
|
public interface INodeEditorAttrib {
|
||||||
Type GetInspectedType();
|
Type GetInspectedType();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,9 +18,7 @@ namespace XNodeEditor {
|
|||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
Matrix4x4 m = GUI.matrix;
|
Matrix4x4 m = GUI.matrix;
|
||||||
if (graph == null) return;
|
if (graph == null) return;
|
||||||
graphEditor = NodeGraphEditor.GetEditor(graph);
|
ValidateGraphEditor();
|
||||||
graphEditor.position = position;
|
|
||||||
|
|
||||||
Controls();
|
Controls();
|
||||||
|
|
||||||
DrawGrid(position, zoom, panOffset);
|
DrawGrid(position, zoom, panOffset);
|
||||||
@ -288,7 +286,7 @@ namespace XNodeEditor {
|
|||||||
_portConnectionPoints = _portConnectionPoints.Where(x => x.Key.node != node).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
_portConnectionPoints = _portConnectionPoints.Where(x => x.Key.node != node).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeEditor nodeEditor = NodeEditor.GetEditor(node);
|
NodeEditor nodeEditor = NodeEditor.GetEditor(node, this);
|
||||||
|
|
||||||
NodeEditor.portPositions = new Dictionary<XNode.NodePort, Vector2>();
|
NodeEditor.portPositions = new Dictionary<XNode.NodePort, Vector2>();
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
void OnFocus() {
|
void OnFocus() {
|
||||||
current = this;
|
current = this;
|
||||||
graphEditor = NodeGraphEditor.GetEditor(graph);
|
ValidateGraphEditor();
|
||||||
if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +84,15 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Make sure the graph editor is assigned and to the right object </summary>
|
||||||
|
private void ValidateGraphEditor() {
|
||||||
|
NodeGraphEditor graphEditor = NodeGraphEditor.GetEditor(graph, this);
|
||||||
|
if (this.graphEditor != graphEditor) {
|
||||||
|
this.graphEditor = graphEditor;
|
||||||
|
graphEditor.OnOpen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Create editor window </summary>
|
/// <summary> Create editor window </summary>
|
||||||
public static NodeEditorWindow Init() {
|
public static NodeEditorWindow Init() {
|
||||||
NodeEditorWindow w = CreateInstance<NodeEditorWindow>();
|
NodeEditorWindow w = CreateInstance<NodeEditorWindow>();
|
||||||
|
|||||||
@ -8,13 +8,16 @@ namespace XNodeEditor {
|
|||||||
/// <summary> Base class to derive custom Node Graph editors from. Use this to override how graphs are drawn in the editor. </summary>
|
/// <summary> Base class to derive custom Node Graph editors from. Use this to override how graphs are drawn in the editor. </summary>
|
||||||
[CustomNodeGraphEditor(typeof(XNode.NodeGraph))]
|
[CustomNodeGraphEditor(typeof(XNode.NodeGraph))]
|
||||||
public class NodeGraphEditor : XNodeEditor.Internal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, XNode.NodeGraph> {
|
public class NodeGraphEditor : XNodeEditor.Internal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, XNode.NodeGraph> {
|
||||||
/// <summary> The position of the window in screen space. </summary>
|
[Obsolete("Use window.position instead")]
|
||||||
public Rect position;
|
public Rect position { get { return window.position; } set { window.position = value; } }
|
||||||
/// <summary> Are we currently renaming a node? </summary>
|
/// <summary> Are we currently renaming a node? </summary>
|
||||||
protected bool isRenaming;
|
protected bool isRenaming;
|
||||||
|
|
||||||
public virtual void OnGUI() { }
|
public virtual void OnGUI() { }
|
||||||
|
|
||||||
|
/// <summary> Called when opened by NodeEditorWindow </summary>
|
||||||
|
public virtual void OnOpen() { }
|
||||||
|
|
||||||
public virtual Texture2D GetGridTexture() {
|
public virtual Texture2D GetGridTexture() {
|
||||||
return NodeEditorPreferences.GetSettings().gridTexture;
|
return NodeEditorPreferences.GetSettings().gridTexture;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user