浏览代码

Fix visual selection issue (no border + title disappearing) and extract header into its own drawer

/main
Peter Bay Bastian 8 年前
当前提交
14f32a76
共有 5 个文件被更改,包括 103 次插入29 次删除
  1. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  2. 17
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  3. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss
  4. 18
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs
  5. 39
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


name = inNode.name;
var headerData = CreateInstance<HeaderDrawData>();
headerData.Initialize(inNode);
m_Children.Add(headerData);
foreach (var input in node.GetSlots<ISlot>())
{
var data = CreateInstance<AnchorDrawData>();

17
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


{
public class NodeDrawer : GraphElement
{
HeaderDrawer m_HeaderDrawer;
VisualContainer m_SlotContainer;
List<AnchorDrawData> m_currentAnchors;
VisualContainer m_ControlsContainer;

AddToClassList("NodeDrawer");
}
public override void DoRepaint(IStylePainter painter)
private void AddContainers()
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
m_HeaderDrawer = new HeaderDrawer()
painter.DrawRect(position, backgroundColor, 0.0f, borderRadius);
}
}
name = "header"
};
AddChild(m_HeaderDrawer);
private void AddContainers()
{
// Add slots (with input & output sub-containers) container
m_SlotContainer = new VisualContainer
{

}
}
content = new GUIContent(nodeData.name);
// content.text = nodeData.name;
}
private void AddControls(NodeDrawData nodeData)

return;
}
m_HeaderDrawer.dataProvider = nodeData.elements.OfType<HeaderDrawData>().FirstOrDefault();
AddSlots(nodeData);
AddControls(nodeData);
}

54
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss


flex-direction: column;
}
MaterialNodeDrawer #header #title {
text-color: #FFFFFF;
width: 200;
text-alignment: middle-center;
}
background-color:#444;
flex:1;
background-color: #444;
width: 200;
}
MaterialNodeDrawer #slots #input{

MaterialNodeDrawer #slots #output {
flex:1;
justify-content: flex-end;
}
/* NodeAnchor */
MaterialNodeDrawer #slots NodeAnchor {
align-items: center;
}
MaterialNodeDrawer #slots #input NodeAnchor {
flex-direction: row;
NodeAnchor {
margin-top:5;
margin-bottom:5;
MaterialNodeDrawer #slots #output NodeAnchor {
flex-direction: row-reverse;
/* NodeAnchor #connector */
margin-left: 5;
margin-right: 5;
}
NodeAnchor #connector.anchorHighlight {

NodeAnchor #type {
/* NodeAnchor #type */
MaterialNodeDrawer #slots NodeAnchor #type {
MaterialNodeDrawer #slots #input NodeAnchor {
flex-direction: row;
MaterialNodeDrawer #slots #input NodeAnchor #type {
text-alignment: middle-left;
MaterialNodeDrawer #slots #output NodeAnchor {
flex-direction: row-reverse;
}
MaterialNodeDrawer #output NodeAnchor #type {
text-alignment:middle-right;
}
Node.horizontal NodeAnchor #connector {
margin-left: 5;
margin-right: 5;
MaterialNodeDrawer #slots #output NodeAnchor #type {
text-alignment: middle-right;
background-color: #444;
}
MaterialNodeDrawer #controls #element{

MaterialNodeDrawer #preview {
flex-direction: column;
background-color: #444;
}
MaterialNodeDrawer #preview #image {

18
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs


using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class HeaderDrawData : NodeDrawData
{
protected HeaderDrawData()
{}
public INode node { get; private set; }
public void Initialize(INode inNode)
{
node = inNode;
name = inNode.name + " Header";
}
}
}

39
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs


using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
public class HeaderDrawer : GraphElement
{
private VisualElement m_Title;
public HeaderDrawer()
{
pickingMode = PickingMode.Ignore;
RemoveFromClassList("graphElement");
m_Title = new VisualElement()
{
name = "title",
content = new GUIContent(),
pickingMode = PickingMode.Ignore
};
AddChild(m_Title);
}
public override void OnDataChanged()
{
base.OnDataChanged();
var headerData = dataProvider as HeaderDrawData;
if (headerData == null)
{
m_Title.content.text = "";
return;
}
m_Title.content.text = headerData.node.name;
}
}
}
正在加载...
取消
保存