74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System;
|
|
using UnityEditor;
|
|
using UnityEditor.Experimental.GraphView;
|
|
using UnityEngine;
|
|
|
|
namespace ImageProcessingGraph.Editor.Windows
|
|
{
|
|
public class ImageProcessingGraphEditorWindow : EditorWindow
|
|
{
|
|
[SerializeField] private ImageProcessingGraphAsset currentGraph;
|
|
[SerializeField] private SerializedObject serializedObject;
|
|
[SerializeField] private ImageProcessingGraphViewWindow currentView;
|
|
public ImageProcessingGraphAsset CurrentGraph => currentGraph;
|
|
|
|
public static void Open(ImageProcessingGraphAsset asset)
|
|
{
|
|
var existingWindows = Resources.FindObjectsOfTypeAll<ImageProcessingGraphEditorWindow>();
|
|
foreach (var w in existingWindows)
|
|
{
|
|
if (w.CurrentGraph == asset)
|
|
{
|
|
w.Focus(); // 👁 focus the OG window
|
|
return;
|
|
}
|
|
}
|
|
|
|
var window = CreateWindow<ImageProcessingGraphEditorWindow>(typeof(SceneView));
|
|
window.titleContent = new GUIContent($"{asset.name}",
|
|
EditorGUIUtility.ObjectContent(null, typeof(ImageProcessingGraphAsset)).image);
|
|
window.Load(asset);
|
|
window.Focus();
|
|
}
|
|
|
|
|
|
|
|
void OnEnable()
|
|
{
|
|
if(currentGraph != null)
|
|
DrawGraph();
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (currentGraph != null)
|
|
{
|
|
if(EditorUtility.IsDirty(currentGraph))
|
|
this.hasUnsavedChanges = true;
|
|
else
|
|
this.hasUnsavedChanges = false;
|
|
}
|
|
}
|
|
|
|
public void Load(ImageProcessingGraphAsset asset)
|
|
{
|
|
currentGraph = asset;
|
|
DrawGraph();
|
|
}
|
|
|
|
public void DrawGraph()
|
|
{
|
|
serializedObject = new SerializedObject(currentGraph);
|
|
currentView = new ImageProcessingGraphViewWindow(serializedObject, this);
|
|
currentView.graphViewChanged += OnChange;
|
|
rootVisualElement.Add(currentView);
|
|
}
|
|
|
|
private GraphViewChange OnChange(GraphViewChange graphviewchange)
|
|
{
|
|
EditorUtility.SetDirty(currentGraph);
|
|
return graphviewchange;
|
|
}
|
|
}
|
|
}
|