浏览代码

Minor drawer clean-up and replaced NodeExpander with Clickable

/main
Peter Bay Bastian 8 年前
当前提交
508a8634
共有 5 个文件被更改,包括 56 次插入100 次删除
  1. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarButtonDrawData.cs
  3. 48
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs
  4. 60
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  5. 42
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/NodeExpander.cs

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


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()));
var selectedNodes = asset.drawingData.selection.Select(asset.graph.GetNodeFromGuid);
EditorGUILayout.LabelField("Selected nodes", string.Join(", ", selectedNodes.Select(x => x.name).ToArray()));
}
}
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarButtonDrawData.cs


using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
public delegate void OnTitleBarButtonClicked();
public class TitleBarButtonDrawData : ScriptableObject
{
public delegate void ClickCallback();

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


{
private VisualElement m_Title;
private VisualElement m_ExpandButton;
private NodeExpander m_NodeExpander = new NodeExpander();
private HeaderDrawData m_dataProvider;
private HeaderDrawData m_DataProvider;
get { return m_dataProvider; }
get { return m_DataProvider; }
if (m_dataProvider == value)
if (m_DataProvider == value)
m_dataProvider = value;
m_DataProvider = value;
protected override object toWatch
{
get { return m_dataProvider; }
}
pickingMode = PickingMode.Ignore;
RemoveFromClassList("graphElement");
content = new GUIContent(),
pickingMode = PickingMode.Ignore
content = new GUIContent()
m_ExpandButton = new VisualElement()
m_ExpandButton = new VisualElement
content = new GUIContent("")
content = new GUIContent("teeest")
m_ExpandButton.AddManipulator(m_NodeExpander);
var clickable = new Clickable(OnExpandClick);
m_ExpandButton.AddManipulator(clickable);
AddChild(m_ExpandButton);
}

{
base.OnDataChanged();
var headerData = dataProvider as HeaderDrawData;
if (headerData == null)
if (dataProvider == null)
m_Title.content.text = headerData.title;
m_ExpandButton.content.text = headerData.expanded ? "Collapse" : "Expand";
m_NodeExpander.data = headerData;
m_Title.content.text = dataProvider.title;
m_ExpandButton.content.text = dataProvider.expanded ? "Collapse" : "Expand";
}
private void OnExpandClick()
{
if (dataProvider == null) return;
dataProvider.expanded = !dataProvider.expanded;
}
protected override object toWatch
{
get { return m_DataProvider; }
}
}
}

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


m_LeftContainer = new VisualContainer
{
classList = new ClassList("pane", "left"),
pickingMode = PickingMode.Ignore
{
m_HeaderDrawer = new HeaderDrawer();
m_HeaderDrawer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_HeaderDrawer);
m_InputContainer = new VisualContainer
{
name = "input",
pickingMode = PickingMode.Ignore,
};
m_InputContainer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_InputContainer);
m_ControlsContainer = new VisualContainer
{
name = "controls",
pickingMode = PickingMode.Ignore,
};
m_ControlsContainer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_ControlsContainer);
}
AddChild(m_LeftContainer);
m_RightContainer = new VisualContainer

};
AddChild(m_RightContainer);
m_HeaderDrawer = new HeaderDrawer();
m_HeaderDrawer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_HeaderDrawer);
m_InputContainer = new VisualContainer
name = "input",
pickingMode = PickingMode.Ignore,
};
m_InputContainer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_InputContainer);
m_ControlsContainer = new VisualContainer
{
name = "controls",
pickingMode = PickingMode.Ignore,
};
m_ControlsContainer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_ControlsContainer);
m_OutputContainer = new VisualContainer
{
name = "output",
pickingMode = PickingMode.Ignore,
};
m_OutputContainer.AddToClassList("paneItem");
m_RightContainer.AddChild(m_OutputContainer);
m_OutputContainer = new VisualContainer
{
name = "output",
pickingMode = PickingMode.Ignore,
};
m_OutputContainer.AddToClassList("paneItem");
m_RightContainer.AddChild(m_OutputContainer);
}
AddChild(m_RightContainer);
m_CurrentControlDrawData = new List<ControlDrawData>();
}

42
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/NodeExpander.cs


using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
public class NodeExpander : MouseManipulator
{
public HeaderDrawData data;
private VisualElement initialTarget;
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
{
switch (evt.type)
{
case EventType.MouseDown:
if (CanStartManipulation(evt))
{
this.TakeCapture();
initialTarget = finalTarget;
}
break;
case EventType.MouseUp:
if (CanStopManipulation(evt))
{
this.ReleaseCapture();
var withinInitialTarget = initialTarget != null && initialTarget.ContainsPoint(evt.mousePosition);
if (withinInitialTarget)
{
data.expanded = !data.expanded;
}
}
break;
}
return this.HasCapture() ? EventPropagation.Stop : EventPropagation.Continue;
}
}
}
正在加载...
取消
保存