Added defualt graph properties inspector;
Added sticky note; Changed the name of BaseNode to SlotContainerNode in case we need other type of nodes in the future;
This commit is contained in:
45
Sample/Editor/View/SampleGraphAssetEditor.cs
Normal file
45
Sample/Editor/View/SampleGraphAssetEditor.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Misaki.GraphView.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.GraphView.Sample.Editor
|
||||
{
|
||||
[CustomEditor(typeof(SampleGraphAsset))]
|
||||
public class SampleGraphAssetEditor : GraphObjectEditor
|
||||
{
|
||||
[OnOpenAsset]
|
||||
public static bool OnOpenAsset(int instanceID, int line)
|
||||
{
|
||||
var asset = EditorUtility.InstanceIDToObject(instanceID) as SampleGraphAsset;
|
||||
|
||||
if (asset != null)
|
||||
{
|
||||
SampleGraphEditor.Open(asset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
var root = new VisualElement();
|
||||
var graphProperties = CreateInspectorProperty();
|
||||
|
||||
var executeButton = new Button(() =>
|
||||
{
|
||||
var graph = target as SampleGraphAsset;
|
||||
graph?.Execute();
|
||||
})
|
||||
{
|
||||
text = "Execute"
|
||||
};
|
||||
|
||||
root.Add(graphProperties);
|
||||
root.Add(executeButton);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Sample/Editor/View/SampleGraphAssetEditor.cs.meta
Normal file
3
Sample/Editor/View/SampleGraphAssetEditor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d328a580873455bbc885370d71260fb
|
||||
timeCreated: 1730134525
|
||||
142
Sample/Editor/View/SampleGraphEditor.cs
Normal file
142
Sample/Editor/View/SampleGraphEditor.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using Misaki.GraphView;
|
||||
using Misaki.GraphView.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.GraphView.Sample.Editor
|
||||
{
|
||||
public class SampleGraphEditor : EditorWindow
|
||||
{
|
||||
private const string Icon_Path = "Packages/com.misaki.graph-view/Sample/Icon/icons8-workflow-96.png";
|
||||
|
||||
[SerializeField]
|
||||
private StyleSheet _styleSheet;
|
||||
|
||||
private readonly PortColorManager _portColorManager = new ();
|
||||
private readonly ExposedPropertyTypeManager _exposedPropertyTypeManager = new ();
|
||||
private GraphObject _currentAsset;
|
||||
|
||||
private GraphViewConfig _config;
|
||||
|
||||
[MenuItem("Tools/SampleGraphEditor")]
|
||||
private static void Open()
|
||||
{
|
||||
var window = CreateWindow<SampleGraphEditor>(typeof(SceneView));
|
||||
window.titleContent = new GUIContent("Sample Graph Editor", EditorGUIUtility.IconContent(Icon_Path).image);
|
||||
}
|
||||
|
||||
public static void Open(GraphObject asset)
|
||||
{
|
||||
var window = GetWindow<SampleGraphEditor>(typeof(SceneView));
|
||||
window.titleContent = new GUIContent(asset.name, EditorGUIUtility.IconContent(Icon_Path).image);
|
||||
window.Clear();
|
||||
window.LoadAsset(asset);
|
||||
window.DrawGraph();
|
||||
window.Focus();
|
||||
}
|
||||
|
||||
public SampleGraphEditor()
|
||||
{
|
||||
_portColorManager.SetColor<uint>(Color.cyan);
|
||||
|
||||
_exposedPropertyTypeManager.AddPropertyType<FloatProperty, float>();
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
rootVisualElement.Clear();
|
||||
}
|
||||
|
||||
private void LoadAsset(GraphObject asset)
|
||||
{
|
||||
Clear();
|
||||
|
||||
_currentAsset = asset;
|
||||
_config = new()
|
||||
{
|
||||
direction = GraphDirection.Horizontal,
|
||||
miniMapConfig = new ()
|
||||
{
|
||||
enable = false,
|
||||
},
|
||||
zoomConfig = new ()
|
||||
{
|
||||
minScale = 0.25f,
|
||||
maxScale = 2f,
|
||||
scaleStep = 0.1f
|
||||
},
|
||||
graphObject = _currentAsset,
|
||||
serializedObject = new SerializedObject(_currentAsset),
|
||||
portColorManager = _portColorManager,
|
||||
exposedPropertyTypeManager = _exposedPropertyTypeManager
|
||||
};
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_currentAsset == null)
|
||||
{
|
||||
var label = new Label("No asset loaded")
|
||||
{
|
||||
style =
|
||||
{
|
||||
flexGrow = 1,
|
||||
unityTextAlign = TextAnchor.MiddleCenter,
|
||||
fontSize = 20
|
||||
}
|
||||
};
|
||||
rootVisualElement.Add(label);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadAsset(_currentAsset);
|
||||
DrawGraph();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGraph()
|
||||
{
|
||||
var graphContainer = new VisualElement
|
||||
{
|
||||
name = "GraphContainer",
|
||||
style =
|
||||
{
|
||||
flexDirection = FlexDirection.Column
|
||||
}
|
||||
};
|
||||
graphContainer.StretchToParentSize();
|
||||
|
||||
var graphView = new GraphView.Editor.GraphView(this, _config);
|
||||
graphView.styleSheets.Add(_styleSheet);
|
||||
graphView.UpdateViewTransform(_currentAsset.graphPosition, _currentAsset.graphScale);
|
||||
|
||||
var toolbar = new GraphToolbarView(_currentAsset);
|
||||
toolbar.BlackboardButtonClicked += graphView.ToggleBlackboardViewVisibility;
|
||||
toolbar.InspectButtonClicked += graphView.ToggleInspectorViewVisibility;
|
||||
|
||||
// We can not directly add the graph view to the graphContainer since the RectangleSelector is calculated base on the parent position, so we need to add it to a container first
|
||||
var graphViewContainer = new VisualElement
|
||||
{
|
||||
name = "GraphViewContainer",
|
||||
style =
|
||||
{
|
||||
flexGrow = 1
|
||||
}
|
||||
};
|
||||
|
||||
graphContainer.Add(toolbar);
|
||||
|
||||
graphViewContainer.Add(graphView);
|
||||
graphContainer.Add(graphViewContainer);
|
||||
|
||||
rootVisualElement.Add(graphContainer);
|
||||
|
||||
// // If no asset is loaded, show a warning label
|
||||
// if (currentAsset == null)
|
||||
// {
|
||||
// RenderNoAssetAlert();
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Sample/Editor/View/SampleGraphEditor.cs.meta
Normal file
14
Sample/Editor/View/SampleGraphEditor.cs.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa9791125630bcc4fb4153e625061b57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_ViewDataDictionary: {instanceID: 0}
|
||||
- _styleSheet: {fileID: 7433441132597879392, guid: ad06b58f16bdc1c429c7a82e0552c636,
|
||||
type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user