浏览代码

Merge pull request #194 from Unity-Technologies/master-preview-rendertexture-rescale

Make rendertexture on master adapt resolution on rescale
/main
GitHub 7 年前
当前提交
a4f6c1fd
共有 4 个文件被更改,包括 79 次插入35 次删除
  1. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
  2. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  3. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  4. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs


m_Graph.previewData.serializedMesh.mesh = changedMesh;
}
public void RefreshRenderTextureSize()
{
RenderTextureDescriptor descriptor = m_PreviewRenderHandle.renderTexture.descriptor;
var targetWidth = m_PreviewTextureView.contentRect.width;
var targetHeight = m_PreviewTextureView.contentRect.height;
if (Mathf.Approximately(descriptor.width, targetHeight) && Mathf.Approximately(descriptor.height, targetWidth))
{
return;
}
descriptor.width = (int)m_PreviewTextureView.contentRect.width;
descriptor.height = (int)m_PreviewTextureView.contentRect.height;
m_PreviewRenderHandle.renderTexture.Release();
Object.DestroyImmediate(m_PreviewRenderHandle.renderTexture);
m_PreviewRenderHandle.renderTexture = new RenderTexture(descriptor);
}
public void UpdateRenderTextureOnNextLayoutChange()
{
RegisterCallback<PostLayoutEvent>(AdaptRenderTextureOnLayoutChange);
}
void AdaptRenderTextureOnLayoutChange(PostLayoutEvent evt)
{
UnregisterCallback<PostLayoutEvent>(AdaptRenderTextureOnLayoutChange);
RefreshRenderTextureSize();
}
void OnMouseDragPreviwMesh(Vector2 deltaMouse)
{
Vector2 previewSize = m_PreviewTextureView.contentRect.size;

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs


set
{
m_StayWithinParentBounds = value;
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
{
resizeHandle.stayWithinParentBounds = value;
}
}
}
bool m_MaintainApsectRatio;
public bool maintainAspectRatio
{
get { return m_MaintainApsectRatio; }
set
{
m_MaintainApsectRatio = value;
resizeHandle.stayWithinPanretBounds = value;
resizeHandle.maintainAspectRatio = value;
}
}
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs


bool m_StayWithinParentBounds;
public bool stayWithinPanretBounds
public bool stayWithinParentBounds
}
bool m_MaintainAspectRatio;
public bool maintainAspectRatio
{
get { return m_MaintainAspectRatio; }
set { m_MaintainAspectRatio = value; }
}
public Action OnResizeFinished;

bool moveWhileResizeHorizontal = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical)));
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical, anchor)));
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizeVertical)
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizeVertical, ResizeHandleAnchor anchor)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;

Rect newLayout = m_ResizeTarget.layout;
// Resize from bottom/right
if (!moveWhileResizeHorizontal)
if (anchor == ResizeHandleAnchor.Left || anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft)
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, minSize.x);
normalizedResizeDelta.x = 0f;
newLayout.xMin = Mathf.Min(newLayout.xMin + normalizedResizeDelta.x, newLayout.xMax - minSize.x);
if (!moveWhileresizeVertical)
else
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, minSize.y);
normalizedResizeDelta.y = 0f;
newLayout.xMax = Mathf.Max(newLayout.xMax + normalizedResizeDelta.x, newLayout.xMin + minSize.x);
float previousFarX = m_ResizeTarget.layout.x + m_ResizeTarget.layout.width;
float previousFarY = m_ResizeTarget.layout.y + m_ResizeTarget.layout.height;
newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, minSize.x);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, minSize.y);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - minSize.x);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - minSize.y);
if (m_StayWithinParentBounds)
if (anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight)
float horizontalTranscendance = Mathf.Min(newLayout.x, 0f) + Mathf.Max(newLayout.xMax - m_ResizeTarget.parent.layout.width, 0f);
float verticalTranscendance = Mathf.Min(newLayout.y, 0f) + Mathf.Max(newLayout.yMax - m_ResizeTarget.parent.layout.height, 0f);
if (moveWhileResizeHorizontal)
{
newLayout.x -= horizontalTranscendance;
}
newLayout.width -= Mathf.Abs(horizontalTranscendance);
newLayout.yMin = Mathf.Min(newLayout.yMin + normalizedResizeDelta.y, newLayout.yMax - minSize.y);
}
else
{
newLayout.yMax = Mathf.Max(newLayout.yMax + normalizedResizeDelta.y, newLayout.yMin + minSize.y);
}
if (moveWhileresizeVertical)
{
newLayout.y -= verticalTranscendance;
}
newLayout.height -= Mathf.Abs(verticalTranscendance);
if (stayWithinParentBounds)
{
newLayout.xMin = Mathf.Max(newLayout.xMin, 0f);
newLayout.yMin = Mathf.Max(newLayout.yMin, 0f);
newLayout.xMax = Mathf.Min(newLayout.xMax, m_ResizeTarget.parent.layout.width);
newLayout.yMax = Mathf.Min(newLayout.yMax, m_ResizeTarget.parent.layout.height);
}
m_ResizeTarget.layout = newLayout;

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" };
masterPreviewResizeBorderFrame.stayWithinParentBounds = true;
masterPreviewResizeBorderFrame.maintainAspectRatio = true;
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);

m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout.GetLayout(layout);
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(layout);
m_MasterPreviewView.UpdateRenderTextureOnNextLayoutChange();
}
else
{

string serializedWindowLayout = JsonUtility.ToJson(m_FloatingWindowsLayout);
EditorUserSettings.SetConfigValue(m_FloatingWindowsLayoutKey, serializedWindowLayout);
m_MasterPreviewView.RefreshRenderTextureSize();
}
public void Dispose()

正在加载...
取消
保存