浏览代码

Put preview in a separate pixel cache for performance

/main
Peter Bay Bastian 7 年前
当前提交
cab9a4b5
共有 2 个文件被更改,包括 45 次插入28 次删除
  1. 44
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  2. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

44
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


{
List<VisualElement> m_ControlViews;
PreviewRenderData m_PreviewRenderData;
PreviewTextureView m_PreviewTextureView;
Image m_PreviewImage;
VisualElement m_PreviewElement;
VisualElement m_ControlsContainer;
VisualElement m_PreviewContainer;
List<Attacher> m_Attachers;

m_PreviewContainer = new VisualElement { name = "previewContainer" };
m_PreviewContainer.AddToClassList("expanded");
{
m_PreviewTextureView = new PreviewTextureView
m_PreviewElement = new VisualElement
{
name = "previewElement",
clippingOptions = ClippingOptions.ClipAndCacheContents,
pickingMode = PickingMode.Ignore
};
m_PreviewImage = new Image
image = Texture2D.whiteTexture
image = Texture2D.whiteTexture,
m_PreviewElement.Add(m_PreviewImage);
m_PreviewRenderData = previewManager.GetPreview(inNode);
m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
UpdatePreviewTexture();

UpdatePreviewExpandedState(false);
}));
UpdatePreviewExpandedState(node.previewExpanded);
m_PreviewTextureView.Add(collapsePreviewButton);
m_PreviewImage.Add(collapsePreviewButton);
var expandPreviewButton = new VisualElement { name = "expand" };
expandPreviewButton.Add(new VisualElement { name = "icon" });

return;
if (expanded)
{
if (m_PreviewTextureView.parent != m_PreviewContainer)
if (m_PreviewElement.parent != this)
m_PreviewContainer.Add(m_PreviewTextureView);
Add(m_PreviewElement);
}
m_PreviewContainer.AddToClassList("expanded");
m_PreviewContainer.RemoveFromClassList("collapsed");

if (m_PreviewTextureView.parent == m_PreviewContainer)
if (m_PreviewElement.parent == m_PreviewContainer)
m_PreviewTextureView.RemoveFromHierarchy();
m_PreviewElement.RemoveFromHierarchy();
}
m_PreviewContainer.RemoveFromClassList("expanded");
m_PreviewContainer.AddToClassList("collapsed");

void OnResize(Vector2 deltaSize)
{
var updatedWidth = topContainer.layout.width + deltaSize.x;
var updatedHeight = m_PreviewTextureView.layout.height + deltaSize.y;
var updatedHeight = m_PreviewImage.layout.height + deltaSize.y;
var previewNode = node as PreviewNode;
if (previewNode != null)

{
if (m_PreviewRenderData.texture == null || !node.previewExpanded)
{
m_PreviewTextureView.visible = false;
m_PreviewTextureView.image = Texture2D.blackTexture;
m_PreviewImage.visible = false;
m_PreviewImage.image = Texture2D.blackTexture;
m_PreviewTextureView.visible = true;
m_PreviewTextureView.AddToClassList("visible");
m_PreviewTextureView.RemoveFromClassList("hidden");
if (m_PreviewTextureView.image != m_PreviewRenderData.texture)
m_PreviewTextureView.image = m_PreviewRenderData.texture;
m_PreviewImage.visible = true;
m_PreviewImage.AddToClassList("visible");
m_PreviewImage.RemoveFromClassList("hidden");
if (m_PreviewImage.image != m_PreviewRenderData.texture)
m_PreviewImage.image = m_PreviewRenderData.texture;
m_PreviewTextureView.Dirty(ChangeType.Repaint);
m_PreviewImage.Dirty(ChangeType.Repaint);
}
}

var width = previewNode.width;
var height = previewNode.height;
m_PreviewTextureView.style.height = height;
m_PreviewImage.style.height = height;
}
public void Dispose()

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


margin-right: 0;
}
MaterialNodeView #previewContainer.expanded {
width: 200;
height: 200;
}
MaterialNodeView #previewContainer,
MaterialNodeView #controls {
background-color: rgba(63, 63, 63, 0.8);

padding-bottom: 4;
}
MaterialNodeView #previewContainer > #preview {
MaterialNodeView > #previewElement {
position-type: absolute;
position-bottom: 4;
position-left: 4;
border-radius: 6;
padding-top: 6;
}
MaterialNodeView > #previewElement > #preview {
MaterialNodeView #previewContainer > #preview > #collapse {
MaterialNodeView > #previewElement > #preview > #collapse {
background-color: #000;
border-color: #F0F0F0;
width: 0;

}
MaterialNodeView #previewContainer:hover > #preview > #collapse {
MaterialNodeView:hover > #previewElement > #preview > #collapse {
MaterialNodeView #previewContainer > #preview > #collapse > #icon
{
MaterialNodeView > #previewElement > #preview > #collapse > #icon {
MaterialNodeView #previewContainer > #preview > #collapse:hover {
MaterialNodeView > #previewElement > #preview > #collapse:hover {
}
MaterialNodeView #previewContainer.collapsed > #preview > #collapse {
height: 0;
}
MaterialNodeView #previewContainer > #expand {

正在加载...
取消
保存