浏览代码

Resize handle added only to preview node

/main
Jens Holm 7 年前
当前提交
ddc1113a
共有 2 个文件被更改,包括 65 次插入6 次删除
  1. 22
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PreviewNode.cs
  2. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs

22
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PreviewNode.cs


{
public override bool hasPreview { get { return true; } }
[SerializeField]
float m_Width;
[SerializeField]
float m_Height;
public void SetDimensions(float width, float height)
{
m_Width = width;
m_Height = height;
}
public float width
{
get { return m_Width; }
}
public float height
{
get { return m_Height; }
}
public PreviewNode()
{
name = "Preview";

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


Image m_PreviewImage;
bool m_IsScheduled;
bool m_ResizeHandleAdded;
public MaterialNodeView()
{
CreateContainers();

leftContainer.Add(m_PreviewImage);
m_ResizeHandle = new VisualElement() { name = "resize", text = "" };
m_ResizeHandle.AddManipulator(new Draggable(OnResize));
Add(m_ResizeHandle);
m_ResizeHandleAdded = false;
style.width = layout.width + deltaSize.x;
style.height = layout.height + deltaSize.y;
float updatedWidth = Mathf.Min(leftContainer.layout.width + deltaSize.x, 1000f);
float updatedHeight = m_PreviewImage.layout.height + deltaSize.y;
PreviewNode previewNode = GetPresenter<MaterialNodePresenter>().node as PreviewNode;
if (previewNode != null)
{
previewNode.SetDimensions(updatedWidth, updatedHeight);
UpdateSize();
}
}
void OnPreviewToggle()

UpdateControls(nodePresenter);
UpdatePreviewTexture(nodePresenter.node.previewExpanded ? nodePresenter.previewTexture : null);
if (GetPresenter<MaterialNodePresenter>().node is PreviewNode)
{
if (!m_ResizeHandleAdded)
{
m_ResizeHandle = new VisualElement() { name = "resize", text = "" };
m_ResizeHandle.AddManipulator(new Draggable(OnResize));
Add(m_ResizeHandle);
m_ResizeHandleAdded = true;
}
UpdateSize();
}
}
void UpdateSize()
{
var node = GetPresenter<MaterialNodePresenter>().node as PreviewNode;
if (node == null)
{
return;
}
float width = node.width;
float height = node.height;
leftContainer.style.width = width;
m_PreviewImage.style.height = height;
}
}
}
正在加载...
取消
保存