浏览代码

Add collapse button on master preview

/main
Jens Holm 6 年前
当前提交
b1e38c12
共有 3 个文件被更改,包括 115 次插入8 次删除
  1. 71
      com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs
  2. 14
      com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
  3. 38
      com.unity.shadergraph/Editor/Resources/Styles/MasterPreviewView.uss

71
com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs


IMasterNode m_MasterNode;
Mesh m_PreviousMesh;
bool m_Expanded = true;
public bool expanded
{
get { return m_Expanded;}
}
Vector2 m_ExpandedPreviewSize;
VisualElement m_CollapsePreviewContainer;
VisualElement m_CollapsePreviewButton;
ResizeBorderFrame m_PreviewResizeBorderFrame;
public ResizeBorderFrame previewResizeBorderFrame
{
get { return m_PreviewResizeBorderFrame; }
}
VisualElement m_Preview;
public VisualElement preview

var topContainer = new VisualElement() { name = "top" };
{
var title = new Label(assetName.Split('/').Last()) { name = "title" };
// Add preview collapse button on top of preview
m_CollapsePreviewContainer = new VisualElement { name = "collapse-container" };
m_CollapsePreviewContainer.AddToClassList("collapse-container");
m_CollapsePreviewButton = new VisualElement { name = "icon" };
m_CollapsePreviewButton.AddToClassList("icon");
m_CollapsePreviewContainer.Add(m_CollapsePreviewButton);
m_CollapsePreviewContainer.AddManipulator(new Clickable(() =>
{
m_Graph.owner.RegisterCompleteObjectUndo("Collapse Preview");
m_Expanded ^= true;
UpdateExpandedButtonState();
UpdatePreviewVisibility();
}));
topContainer.Add(m_CollapsePreviewContainer);
}
Add(topContainer);

}
m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged;
Add(preview);
m_PreviewResizeBorderFrame = new ResizeBorderFrame(previewTextureView, this) { name = "resizeBorderFrame" };
m_PreviewResizeBorderFrame.stayWithinParentBounds = true;
m_PreviewResizeBorderFrame.maintainAspectRatio = true;
Add(m_PreviewResizeBorderFrame);
m_ExpandedPreviewSize = new Vector2(256f, 256f);
}
void UpdateExpandedButtonState()
{
m_CollapsePreviewButton.RemoveFromClassList(!m_Expanded ? "expanded" : "collapsed");
m_CollapsePreviewButton.AddToClassList(!m_Expanded ? "collapsed" : "expanded");
}
void UpdatePreviewVisibility()
{
if (m_Expanded)
{
RemoveFromClassList("collapsed");
AddToClassList("expanded");
m_PreviewResizeBorderFrame.visible = true;
previewTextureView.style.width = StyleValue<float>.Create(m_ExpandedPreviewSize.x);
previewTextureView.style.height = StyleValue<float>.Create(m_ExpandedPreviewSize.y);
}
else
{
m_ExpandedPreviewSize = previewTextureView.layout.size;
m_PreviewResizeBorderFrame.visible = false;
previewTextureView.style.width = StyleValue<float>.Create(0f);
previewTextureView.style.height = StyleValue<float>.Create(0f);
RemoveFromClassList("expanded");
AddToClassList("collapsed");
}
}
Image CreatePreview(Texture texture)

public void RefreshRenderTextureSize()
{
if (!expanded)
return;
var currentWidth = m_PreviewRenderHandle.texture != null ? m_PreviewRenderHandle.texture.width : -1;
var currentHeight = m_PreviewRenderHandle.texture != null ? m_PreviewRenderHandle.texture.height : -1;

14
com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs


m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable);
m_GraphView.Add(m_MasterPreviewView);
ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView.previewTextureView, m_MasterPreviewView) { name = "resizeBorderFrame" };
masterPreviewResizeBorderFrame.stayWithinParentBounds = true;
masterPreviewResizeBorderFrame.maintainAspectRatio = true;
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.previewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_GraphView.graphViewChanged = GraphViewChanged;

m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_MasterPreviewView.layout, layout);
m_FloatingWindowsLayout.blackboardLayout.CalculateDockingCornerAndOffset(m_BlackboardProvider.blackboard.layout, layout);
m_FloatingWindowsLayout.masterPreviewSize = m_MasterPreviewView.previewTextureView.layout.size;
if (m_MasterPreviewView.expanded)
{
m_FloatingWindowsLayout.masterPreviewSize = m_MasterPreviewView.previewTextureView.layout.size;
}
string serializedWindowLayout = JsonUtility.ToJson(m_FloatingWindowsLayout);
EditorUserSettings.SetConfigValue(k_FloatingWindowsLayoutKey, serializedWindowLayout);

38
com.unity.shadergraph/Editor/Resources/Styles/MasterPreviewView.uss


}
MasterPreviewView > #top {
flex-direction: row;
justify-content: space-between;
background-color: rgb(64, 64, 64);
padding-top: 8;
padding-bottom: 8;

padding-right: 2;
}
MasterPreviewView > #top > #collapse-container {
align-self : center;
width : 12;
}
MasterPreviewView > #top > #collapse-container > #icon{
align-self: center;
background-image : resource("GraphView/Nodes/NodeChevronDown");
width: 12;
height: 12;
margin-right: 10;
margin-left: 10;
}
MasterPreviewView > #top > #collapse-container > #icon.collapsed {
align-self: center;
background-image : resource("GraphView/Nodes/NodeChevronLeft");
width: 12;
height: 12;
}
MasterPreviewView > #top > #collapse-container > #icon.expanded {
align-self: center;
background-image : resource("GraphView/Nodes/NodeChevronDown");
width: 12;
height: 12;
}
MasterPreviewView > #middle {
flex-grow: 1;
border-width: 10;

width: 200;
height: 200;
}
MasterPreviewView.collapsed{
background-color: rgb(206, 53, 185);
}
MasterPreviewView.expanded{
background-color: rgb(206, 53, 185);
}
正在加载...
取消
保存