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) { ImageProcessingGraphEditorWindow[] windows = Resources.FindObjectsOfTypeAll(); foreach (var w in windows) { w.Focus(); return; } ImageProcessingGraphEditorWindow window = CreateWindow(typeof(ImageProcessingGraphEditorWindow), typeof(SceneView)); window.titleContent = new GUIContent($"{asset.name}", EditorGUIUtility.ObjectContent(null, typeof(ImageProcessingGraphAsset)).image ); window.Load(asset); } 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; } } }