mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
|
|
[InitializeOnLoad]
|
|
public partial class NodeEditorWindow : EditorWindow {
|
|
|
|
string saved;
|
|
|
|
public Dictionary<NodePort, Vector2> portConnectionPoints { get { return _portConnectionPoints; } }
|
|
private Dictionary<NodePort, Vector2> _portConnectionPoints = new Dictionary<NodePort, Vector2>();
|
|
private Dictionary<NodePort, Rect> portRects = new Dictionary<NodePort, Rect>();
|
|
public NodeGraph graph { get { return _graph != null ? _graph : _graph = new NodeGraph(); } }
|
|
public NodeGraph _graph;
|
|
public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } }
|
|
private Vector2 _panOffset;
|
|
public float zoom { get { return _zoom; } set { _zoom = Mathf.Clamp(value, 1f, 5f); Repaint(); } }
|
|
private float _zoom = 1;
|
|
|
|
partial void OnEnable();
|
|
|
|
[MenuItem("Window/UNEC")]
|
|
static void Init() {
|
|
NodeEditorWindow w = CreateInstance<NodeEditorWindow>();
|
|
w.titleContent = new GUIContent("UNEC");
|
|
w.wantsMouseMove = true;
|
|
w.Show();
|
|
}
|
|
|
|
public void Save() {
|
|
saved = graph.Serialize();
|
|
Debug.Log(saved);
|
|
}
|
|
|
|
public void Load() {
|
|
Debug.Log(saved);
|
|
_graph = NodeGraph.Deserialize(saved);
|
|
}
|
|
|
|
private void DraggableWindow(int windowID) {
|
|
GUI.DragWindow();
|
|
}
|
|
|
|
/*public byte[] ProtoSerialize<T>(T value) {
|
|
using (var ms = new MemoryStream()) {
|
|
ProtoBuf.Serializer.Serialize(ms, value);
|
|
return ms.ToArray();
|
|
}
|
|
}*/
|
|
|
|
public Vector2 WindowToGridPosition(Vector2 windowPosition) {
|
|
return (windowPosition - (position.size * 0.5f) - (panOffset / zoom)) * zoom;
|
|
}
|
|
|
|
public Vector2 GridToWindowPosition(Vector2 gridPosition) {
|
|
//Vector2 center = position.size * 0.5f;
|
|
return (position.size * 0.5f) + (panOffset / zoom) + (gridPosition/zoom);
|
|
}
|
|
|
|
public Vector2 GridToWindowPositionNoClipped(Vector2 gridPosition) {
|
|
Vector2 center = position.size * 0.5f;
|
|
float xOffset = (center.x * zoom + (panOffset.x + gridPosition.x));
|
|
float yOffset = (center.y * zoom + (panOffset.y + gridPosition.y));
|
|
return new Vector2(xOffset, yOffset);
|
|
}
|
|
|
|
public void SelectNode(Node node) {
|
|
selectedNode = node;
|
|
}
|
|
|
|
} |