First commit
This commit is contained in:
43
Sample/Editor/ExposedPropertyTypeManager.cs
Normal file
43
Sample/Editor/ExposedPropertyTypeManager.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Codice.CM.Common;
|
||||
using Misaki.GraphView.Editor;
|
||||
|
||||
namespace Misaki.GraphView.Sample.Editor
|
||||
{
|
||||
public class ExposedPropertyTypeManager : IExposedPropertyTypeManager
|
||||
{
|
||||
private readonly Dictionary<Type, Type> _propertyTypes = new();
|
||||
|
||||
public void AddPropertyType<T, TV>() where T : ExposedProperty
|
||||
{
|
||||
_propertyTypes.Add(typeof(T), typeof(TV));
|
||||
}
|
||||
|
||||
public void AddPropertyType(Type type, Type valueType)
|
||||
{
|
||||
if (type.IsSubclassOf(typeof(ExposedProperty)))
|
||||
{
|
||||
_propertyTypes.Add(type, valueType);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePropertyType<T>()
|
||||
{
|
||||
_propertyTypes.Remove(typeof(T));
|
||||
}
|
||||
|
||||
public void RemovePropertyType(Type type)
|
||||
{
|
||||
_propertyTypes.Remove(type);
|
||||
}
|
||||
|
||||
public ReadOnlyDictionary<Type, Type> GetPropertyTypes()
|
||||
{
|
||||
//_propertyTypes.AsReadOnly(); // Ancient .NET version doesn't have this method :(
|
||||
return new ReadOnlyDictionary<Type, Type>(_propertyTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Sample/Editor/ExposedPropertyTypeManager.cs.meta
Normal file
3
Sample/Editor/ExposedPropertyTypeManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82e447a37b3c4c06acde96775d3b7935
|
||||
timeCreated: 1730458201
|
||||
33
Sample/Editor/GraphAssetEditor.cs
Normal file
33
Sample/Editor/GraphAssetEditor.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView.Sample.Editor
|
||||
{
|
||||
[CustomEditor(typeof(SampleGraphAsset))]
|
||||
public class SampleGraphAssetEditor : UnityEditor.Editor
|
||||
{
|
||||
[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 void OnInspectorGUI()
|
||||
{
|
||||
if (GUILayout.Button("Execute"))
|
||||
{
|
||||
var asset = target as SampleGraphAsset;
|
||||
asset?.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Sample/Editor/GraphAssetEditor.cs.meta
Normal file
3
Sample/Editor/GraphAssetEditor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d328a580873455bbc885370d71260fb
|
||||
timeCreated: 1730134525
|
||||
18
Sample/Editor/GraphView.Sample.Editor.asmdef
Normal file
18
Sample/Editor/GraphView.Sample.Editor.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "GraphView.Sample.Editor",
|
||||
"rootNamespace": "Misaki.GraphView.Sample.Editor",
|
||||
"references": [
|
||||
"GUID:f9745e3c5d586134288023f609b080e2",
|
||||
"GUID:533d7c0252a224f4b91c72a79c31c026",
|
||||
"GUID:ccfdc692d87db8b49b9ec88c2ec0ab79"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Sample/Editor/GraphView.Sample.Editor.asmdef.meta
Normal file
7
Sample/Editor/GraphView.Sample.Editor.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f931024d736a2d44a1ecb45293a4c31
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Sample/Editor/PortColorManager.cs
Normal file
22
Sample/Editor/PortColorManager.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Misaki.GraphView.Editor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView.Sample.Editor
|
||||
{
|
||||
public class PortColorManager : IPortColorManager
|
||||
{
|
||||
private readonly Dictionary<Type, Color> _colors = new();
|
||||
|
||||
public void SetColor<T>(Color color)
|
||||
{
|
||||
_colors[typeof(T)] = color;
|
||||
}
|
||||
|
||||
public bool TryGetColor(Type valueType, out Color color)
|
||||
{
|
||||
return _colors.TryGetValue(valueType, out color);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Sample/Editor/PortColorManager.cs.meta
Normal file
2
Sample/Editor/PortColorManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54afba377e1b7be4a902a175a3255c55
|
||||
140
Sample/Editor/SampleGraphEditor.cs
Normal file
140
Sample/Editor/SampleGraphEditor.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using Misaki.GraphView;
|
||||
using Misaki.GraphView.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.GraphView.Sample.Editor
|
||||
{
|
||||
public class SampleGraphEditor : EditorWindow
|
||||
{
|
||||
[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");
|
||||
}
|
||||
|
||||
public static void Open(GraphObject asset)
|
||||
{
|
||||
var window = GetWindow<SampleGraphEditor>(typeof(SceneView));
|
||||
window.Clear();
|
||||
window.LoadAsset(asset);
|
||||
window.titleContent = new GUIContent(asset.name);
|
||||
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/SampleGraphEditor.cs.meta
Normal file
14
Sample/Editor/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