浏览代码

Refactored title bar button into own drawer

/main
Peter Bay Bastian 8 年前
当前提交
c6e6d4e4
共有 8 个文件被更改,包括 151 次插入56 次删除
  1. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
  2. 41
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarDrawData.cs
  3. 68
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs
  4. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/TitleBar.uss
  5. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarButtonDrawData.cs
  6. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarButtonDrawData.cs.meta
  7. 58
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarButtonDrawer.cs
  8. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarButtonDrawer.cs.meta

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs


var source = CreateDataSource();
source.Initialize(m_LastSelection);
var titleBarData = CreateInstance<TitleBarDrawData>();
titleBarData.title = m_LastSelection != null ? m_LastSelection.GetScriptableObject().name : "";
m_TitleBarDrawer = new TitleBarDrawer(titleBarData);
m_TitleBarDrawer = new TitleBarDrawer(source.titleBar);
m_GraphView.dataSource = source;
rootVisualContainer.AddChild(m_TitleBarDrawer);

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


using RMGUI.GraphView;
using UnityEngine;
using UnityEngine;
using System.Collections.Generic;
List<TitleBarButtonDrawData> m_leftItems;
List<TitleBarButtonDrawData> m_rightItems;
public IEnumerable<TitleBarButtonDrawData> leftItems
{
get { return m_leftItems; }
}
public IEnumerable<TitleBarButtonDrawData> rightItems
{
get { return m_rightItems; }
}
public string title;
public void Initialize(IGraphAsset graphAsset)
{
m_leftItems = new List<TitleBarButtonDrawData>();
m_rightItems = new List<TitleBarButtonDrawData>();
public void Initialize(IGraphAsset graphAsset)
{
if (graphAsset == null)
title = "";
else
title = graphAsset.GetScriptableObject().name;
}
var currentGraphItem = CreateInstance<TitleBarButtonDrawData>();
currentGraphItem.text = graphAsset != null ? graphAsset.GetScriptableObject().name : "";
m_leftItems.Add(currentGraphItem);
var showInProjectItem = CreateInstance<TitleBarButtonDrawData>();
showInProjectItem.text = "Show in project";
m_leftItems.Add(showInProjectItem);
var optionsItem = CreateInstance<TitleBarButtonDrawData>();
optionsItem.text = "Options";
m_rightItems.Add(optionsItem);
}
}
}

68
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.RMGUI.StyleEnums;
using UnityEngine.RMGUI.StyleSheets;
namespace UnityEditor.Graphing.Drawing

{
private TitleBarDrawData m_dataProvider;
private VisualElement m_title;
TitleBarDrawData m_dataProvider;
VisualContainer m_leftContainer;
VisualContainer m_rightContainer;
public TitleBarDrawData dataProvider
{

name = "TitleBar";
zBias = 99;
var leftContainer = new VisualContainer()
m_leftContainer = new VisualContainer()
AddChild(leftContainer);
AddChild(m_leftContainer);
var rightContainer = new VisualContainer()
m_rightContainer = new VisualContainer()
AddChild(rightContainer);
var titleItem = new VisualContainer() { classList = new ClassList("titleBarItem") };
titleItem.AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
m_title = new VisualElement()
{
classList = new ClassList("titleBarItemLabel"),
content = new GUIContent("")
};
titleItem.AddChild(m_title);
titleItem.AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
leftContainer.AddChild(titleItem);
AddChild(m_rightContainer);
var showInProjectItem = new VisualContainer() { classList = new ClassList("titleBarItem") };
showInProjectItem.AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
var showInProjectLabel = new VisualElement()
{
classList = new ClassList("titleBarItemLabel"),
content = new GUIContent("Show in project")
};
showInProjectItem.AddChild(showInProjectLabel);
showInProjectItem.AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
leftContainer.AddChild(showInProjectItem);
foreach (var leftItemData in dataProvider.leftItems)
m_leftContainer.AddChild(new TitleBarButtonDrawer(leftItemData));
var optionsItem = new VisualContainer() { classList = new ClassList("titleBarItem") };
optionsItem.AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
var optionsLabel = new VisualElement()
{
classList = new ClassList("titleBarItemLabel"),
content = new GUIContent("Options")
};
optionsItem.AddChild(optionsLabel);
optionsItem.AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
rightContainer.AddChild(optionsItem);
foreach (var rightItemData in dataProvider.rightItems)
m_rightContainer.AddChild(new TitleBarButtonDrawer(rightItemData));
this.dataProvider = dataProvider;
}

if (m_dataProvider == null)
return;
m_title.content.text = m_dataProvider.title;
UpdateContainer(m_leftContainer, m_dataProvider.leftItems);
UpdateContainer(m_rightContainer, m_dataProvider.rightItems);
}
this.Touch(ChangeType.Repaint);
void UpdateContainer(VisualContainer container, IEnumerable<TitleBarButtonDrawData> itemDatas)
{
// The number of items can't change for now.
int i = 0;
foreach (var itemData in itemDatas)
{
var item = container.GetChildAtIndex(i) as TitleBarButtonDrawer;
if (item != null)
item.dataProvider = itemData;
i++;
}
}
protected override object toWatch

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/TitleBar.uss


font-size: 9;
text-alignment: middle-left;
padding-left: 5;
padding-right: 5;
}

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


using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
public class TitleBarButtonDrawData : ScriptableObject
{
public string text;
protected TitleBarButtonDrawData() { }
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarButtonDrawData.cs.meta


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

58
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarButtonDrawer.cs


using UnityEngine.RMGUI;
using RMGUI.GraphView;
using UnityEngine.RMGUI.StyleSheets;
using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
public class TitleBarButtonDrawer : DataWatchContainer
{
TitleBarButtonDrawData m_dataProvider;
VisualElement m_label;
public TitleBarButtonDrawData dataProvider
{
get { return m_dataProvider; }
set
{
if (m_dataProvider == value)
return;
RemoveWatch();
m_dataProvider = value;
OnDataChanged();
AddWatch();
}
}
public TitleBarButtonDrawer(TitleBarButtonDrawData dataProvider)
{
classList = new ClassList("titleBarItem");
AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
m_label = new VisualElement()
{
classList = new ClassList("titleBarItemLabel"),
content = new GUIContent("")
};
AddChild(m_label);
AddChild(new VisualElement() { classList = new ClassList("titleBarItemBorder") });
this.dataProvider = dataProvider;
}
public override void OnDataChanged()
{
if (m_dataProvider == null)
return;
m_label.content.text = m_dataProvider.text;
this.Touch(ChangeType.Repaint);
}
protected override object toWatch
{
get { return dataProvider; }
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarButtonDrawer.cs.meta


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