浏览代码

Remove selection stuff from inspector and move properties to the top

/main
Peter Bay Bastian 7 年前
当前提交
2a66a4bf
共有 3 个文件被更改,包括 14 次插入62 次删除
  1. 65
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  3. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

65
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing.Util;
using UnityEditor.Graphing;
using UnityEditor.Graphing;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Inspector
{

VisualElement m_PropertyItems;
VisualElement m_LayerItems;
VisualElement m_ContentContainer;
TypeMapper m_TypeMapper;
List<INode> m_SelectedNodes;
Vector2 m_PreviewScrollPosition;

public GraphInspectorView(string assetName, PreviewManager previewManager, AbstractMaterialGraph graph)
{
m_Graph = graph;
m_SelectedNodes = new List<INode>();
AddStyleSheetPath("Styles/MaterialGraph");

}
topContainer.Add(headerContainer);
m_ContentContainer = new VisualElement {name = "content"};
topContainer.Add(m_ContentContainer);
}
Add(topContainer);
var bottomContainer = new VisualElement {name = "bottom"};
{
var propertiesContainer = new VisualElement {name = "properties"};
{
var header = new VisualElement {name = "header"};

m_PropertyItems = new VisualContainer {name = "items"};
propertiesContainer.Add(m_PropertyItems);
}
bottomContainer.Add(propertiesContainer);
topContainer.Add(propertiesContainer);
}
Add(topContainer);
var bottomContainer = new VisualElement {name = "bottom"};
{
m_PreviewTextureView = new PreviewTextureView { name = "preview", image = Texture2D.blackTexture };
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDrag, true));
bottomContainer.Add(m_PreviewTextureView);

m_PreviewMeshPicker = new ObjectField() { objectType = typeof(Mesh) };
m_PreviewMeshPicker = new ObjectField { objectType = typeof(Mesh) };
m_PreviewMeshPicker.OnValueChanged(OnPreviewMeshChanged);
bottomContainer.Add(m_PreviewMeshPicker);

var resizeHandleBottom = new Label { name = "resize-bottom", text = "" };
resizeHandleBottom.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, ResizeDirection.Vertical, false)));
Add(resizeHandleBottom);
// Nodes missing custom editors:
// - PropertyNode
// - SubGraphInputNode
// - SubGraphOutputNode
m_TypeMapper = new TypeMapper(typeof(INode), typeof(AbstractNodeEditorView), typeof(StandardNodeEditorView))
{
// { typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeEditorView) }
};
}
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResize)

m_PreviewTextureView.Dirty(ChangeType.Repaint);
}
void OnPreviewMeshChanged(ChangeEvent<UnityEngine.Object> changeEvent)
void OnPreviewMeshChanged(ChangeEvent<Object> changeEvent)
{
Mesh changedMesh = changeEvent.newValue as Mesh;

}
m_Graph.previewData.serializedMesh.mesh = changedMesh;
}
public void UpdateSelection(IEnumerable<INode> nodes)
{
m_SelectedNodes.Clear();
m_SelectedNodes.AddRange(nodes);
var selectionHash = UIUtilities.GetHashCode(m_SelectedNodes.Count,
m_SelectedNodes != null ? m_SelectedNodes.FirstOrDefault() : null);
if (selectionHash != m_SelectionHash)
{
m_SelectionHash = selectionHash;
m_ContentContainer.Clear();
if (m_SelectedNodes.Count > 1)
{
var element = new Label(string.Format("{0} nodes selected.", m_SelectedNodes.Count))
{
name = "selectionCount"
};
m_ContentContainer.Add(element);
}
else if (m_SelectedNodes.Count == 1)
{
var node = m_SelectedNodes.First();
var view = (AbstractNodeEditorView)Activator.CreateInstance(m_TypeMapper.MapType(node.GetType()));
view.node = node;
m_ContentContainer.Add(view);
}
}
}
public void HandleGraphChanges()

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


m_GraphInspectorView = new GraphInspectorView(assetName, previewManager, graph) { name = "inspector" };
m_GraphInspectorView.AddManipulator(new Draggable(OnMouseDrag, true));
m_GraphInspectorView.RegisterCallback<PostLayoutEvent>(OnPostLayout);
m_GraphView.onSelectionChanged += m_GraphInspectorView.UpdateSelection;
m_GraphView.Add(m_GraphInspectorView);
m_GraphView.graphViewChanged = GraphViewChanged;

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


background-color: rgb(79, 79, 79);
}
GraphInspectorView > #bottom > #properties {
GraphInspectorView > #top > #properties {
border-color: rgb(41, 41, 41);
border-top-width: 1;
border-bottom-width: 1;

margin-right: 8;
}
GraphInspectorView > #bottom > #properties > #header {
GraphInspectorView > #top > #properties > #header {
border-color: rgb(41, 41, 41);
border-bottom-width: 1;
flex-direction: row;

GraphInspectorView > #bottom > #properties > #header > #title {
GraphInspectorView > #top > #properties > #header > #title {
text-color: rgb(180, 180, 180);
font-style: bold;
padding-top: 8;

}
GraphInspectorView > #bottom > #properties > #header > #addButton {
GraphInspectorView > #top > #properties > #header > #addButton {
height: 24;
margin-top: 0;
margin-bottom: 0;

GraphInspectorView > #bottom > #properties > #items {
GraphInspectorView > #top > #properties > #items {
padding-bottom: 4;
}

正在加载...
取消
保存