浏览代码

Added basic inspector for graph editor and added the selected nodes to the graph asset

It currently just shows the names of the currently selected nodes
/main
Peter Bay Bastian 8 年前
当前提交
5960f11a
共有 14 个文件被更改,包括 187 次插入3 次删除
  1. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarDrawData.cs
  2. 49
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  3. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/IGraphAsset.cs
  4. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs
  5. 7
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.cs
  6. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs
  7. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MaterialRemapAsset.cs
  8. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/MaterialSubGraphAsset.cs
  9. 16
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs
  10. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs.meta
  11. 37
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphDrawingData.cs
  12. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphDrawingData.cs.meta
  13. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs
  14. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs.meta

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarDrawData.cs


if (m_graphAsset != null)
EditorGUIUtility.PingObject(m_graphAsset.GetScriptableObject());
}
void UpdateAsset()
{
if (m_graphAsset != null && m_graphAsset is MaterialGraphAsset)

49
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs


return EventPropagation.Stop;
}
public override void OnDataChanged()
{
base.OnDataChanged();
var graphDataSource = dataSource as AbstractGraphDataSource;
if (graphDataSource == null) return;
var graphAsset = graphDataSource.graphAsset;
if (graphAsset == null || selection.Count != 0 || !graphAsset.drawingData.selection.Any()) return;
var selectedDrawers = graphDataSource.graphAsset.drawingData.selection
.Select(guid => contentViewContainer.children
.OfType<NodeDrawer>()
.FirstOrDefault(drawer => ((NodeDrawData) drawer.dataProvider).node.guid == guid));
foreach (var drawer in selectedDrawers)
AddToSelection(drawer);
}
private void PropagateSelection()
{
var graphDataSource = dataSource as AbstractGraphDataSource;
if (graphDataSource == null) return;
var selectedNodeGuids = selection.OfType<NodeDrawer>().Select(x => ((NodeDrawData) x.dataProvider).node.guid);
graphDataSource.graphAsset.drawingData.selection = selectedNodeGuids;
// TODO: Maybe put somewhere else
Selection.activeObject = graphDataSource.graphAsset.GetScriptableObject();
}
public override void AddToSelection(ISelectable selectable)
{
base.AddToSelection(selectable);
PropagateSelection();
}
public override void RemoveFromSelection(ISelectable selectable)
{
base.RemoveFromSelection(selectable);
PropagateSelection();
}
public override void ClearSelection()
{
base.ClearSelection();
PropagateSelection();
}
}
}

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/IGraphAsset.cs


{
IGraph graph { get; }
bool shouldRepaint { get; }
GraphDrawingData drawingData { get; }
ScriptableObject GetScriptableObject();
void OnEnable();
}

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs


{
graph.OnEnable();
}
[SerializeField]
private GraphDrawingData m_DrawingData = new GraphDrawingData();
public GraphDrawingData drawingData
{
get { return m_DrawingData; }
}
}
}

7
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.cs


if (!m_DataSource.elements.Contains(c.dataProvider))
{
c.parent.RemoveChild(c);
selection.Remove(c);
}
}

public List<ISelectable> selection { get; protected set; }
// functions to ISelection extensions
public void AddToSelection(ISelectable selectable)
public virtual void AddToSelection(ISelectable selectable)
{
var graphElement = selectable as GraphElement;
if (graphElement != null && graphElement.dataProvider != null)

}
public void RemoveFromSelection(ISelectable selectable)
public virtual void RemoveFromSelection(ISelectable selectable)
{
var graphElement = selectable as GraphElement;
if (graphElement != null && graphElement.dataProvider != null)

}
public void ClearSelection()
public virtual void ClearSelection()
{
foreach (var graphElement in selection.OfType<GraphElement>())
{

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs


{
return m_GeneratedShader == null ? 0 : m_GeneratedShader.GetInstanceID();
}
[SerializeField]
private GraphDrawingData m_DrawingData = new GraphDrawingData();
public GraphDrawingData drawingData
{
get { return m_DrawingData; }
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MaterialRemapAsset.cs


{
graph.OnEnable();
}
[SerializeField]
private GraphDrawingData m_DrawingData = new GraphDrawingData();
public GraphDrawingData drawingData
{
get { return m_DrawingData; }
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/MaterialSubGraphAsset.cs


{
m_MaterialSubGraph.PostCreate();
}
[SerializeField]
private GraphDrawingData m_DrawingData = new GraphDrawingData();
public GraphDrawingData drawingData
{
get { return m_DrawingData; }
}
}
}

16
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs


using System.Linq;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public abstract class AbstractGraphInspector : Editor
{
public override void OnInspectorGUI()
{
var asset = target as IGraphAsset;
if (asset == null)
return;
EditorGUILayout.LabelField("Selected nodes", string.Join(", ", asset.drawingData.selection.Select(x => asset.graph.GetNodeFromGuid(x).name).ToArray()));
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs.meta


fileFormatVersion: 2
guid: 0e3ca0203324c4b0791cb3c1a53eeecb
timeCreated: 1482322349
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

37
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphDrawingData.cs


using System;
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.Graphing
{
[Serializable]
public class GraphDrawingData : ISerializationCallbackReceiver
{
[SerializeField]
private List<string> m_SerializableSelection = new List<string>();
[NonSerialized]
private List<Guid> m_Selection = new List<Guid>();
public IEnumerable<Guid> selection
{
get { return m_Selection; }
set
{
m_Selection.Clear();
m_Selection.AddRange(value);
}
}
public void OnBeforeSerialize()
{
m_SerializableSelection.Clear();
m_SerializableSelection.AddRange(m_Selection.Select(x => x.ToString()));
}
public void OnAfterDeserialize()
{
selection = m_SerializableSelection.Select(x => new Guid(x));
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphDrawingData.cs.meta


fileFormatVersion: 2
guid: 4bc9112caeee14b29b0a521463985007
timeCreated: 1482330187
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs


using System.Linq;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[CustomEditor(typeof(MaterialGraphAsset))]
public class MaterialGraphInspector : AbstractGraphInspector
{
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs.meta


fileFormatVersion: 2
guid: 10d843e32398c4de8be413134662f863
timeCreated: 1482316609
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存