浏览代码

Merge pull request #188 from Unity-Technologies/window-layout-docking

Change window position serialization to track closest corner
/main
GitHub 7 年前
当前提交
4df636c0
共有 4 个文件被更改,包括 150 次插入35 次删除
  1. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs
  2. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  3. 105
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs.meta

26
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs


bool m_Active;
bool m_DockLeft;
bool m_DockTop;
WindowDockingLayout m_WindowDockingLayout;
Vector2 m_LocalMosueOffset;
Rect m_PreviousParentRect;

m_ResizeWithParentWindow = resizeWithParentwindow;
m_Active = false;
m_PreviousParentRect = new Rect(0f, 0f, 0f, 0f);
m_WindowDockingLayout = new WindowDockingLayout();
}
protected override void RegisterCallbacksOnTarget()

}
}
void OnMouseUp(MouseUpEvent evt)
{
bool emitDragFinishedEvent = m_Active;

evt.StopImmediatePropagation();
RefreshDocking();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(target.layout, target.parent.layout);
if (emitDragFinishedEvent && OnDragFinished != null)
{

void RefreshDocking()
{
Vector2 windowCenter = new Vector2(target.layout.x + target.layout.width * .5f, target.layout.y + target.layout.height * .5f);
windowCenter /= target.parent.layout.size;
m_DockLeft = windowCenter.x < .5f;
m_DockTop = windowCenter.y < .5f;
}
void InitialLayoutSetup(PostLayoutEvent postLayoutEvent)
{
m_PreviousParentRect = target.parent.layout;

RefreshDocking();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(target.layout, target.parent.layout);
}
void OnPostLayout(PostLayoutEvent postLayoutEvent)

}
Vector2 distanceFromParentEdge = Vector2.zero;
distanceFromParentEdge.x = m_DockLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromParentEdge.y = m_DockTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
distanceFromParentEdge.x = m_WindowDockingLayout.dockingLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromParentEdge.y = m_WindowDockingLayout.dockingTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
Vector2 normalizedDistanceFromEdge = distanceFromParentEdge / m_PreviousParentRect.size;

normalizedDistanceFromEdge = distanceFromParentEdge / target.parent.layout.size;
}
if (m_DockLeft)
if (m_WindowDockingLayout.dockingLeft)
{
windowRect.x = normalizedDistanceFromEdge.x * target.parent.layout.width;
}

}
if (m_DockTop)
if (m_WindowDockingLayout.dockingTop)
{
windowRect.y = normalizedDistanceFromEdge.y * target.parent.layout.height;
}

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


[Serializable]
class FloatingWindowsLayout
{
public Rect previewLayout;
public Rect blackboardLayout;
public WindowDockingLayout previewLayout = new WindowDockingLayout();
public WindowDockingLayout blackboardLayout = new WindowDockingLayout();
}
public class GraphEditorView : VisualElement, IDisposable

m_GraphView.graphViewChanged = GraphViewChanged;
m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout";
string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey);
if (!String.IsNullOrEmpty(serializedWindowLayout))
{
m_FloatingWindowsLayout = JsonUtility.FromJson<FloatingWindowsLayout>(serializedWindowLayout);
m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout;
if (m_FloatingWindowsLayout.blackboardLayout.width > 0)
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout;
}
else
{
m_FloatingWindowsLayout = new FloatingWindowsLayout();
}
RegisterCallback<PostLayoutEvent>(ApplySerializewindowLayouts);
}
m_SearchWindowProvider = ScriptableObject.CreateInstance<SearchWindowProvider>();

}
}
void ApplySerializewindowLayouts(PostLayoutEvent evt)
{
UnregisterCallback<PostLayoutEvent>(ApplySerializewindowLayouts);
m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout";
string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey);
if (!String.IsNullOrEmpty(serializedWindowLayout))
{
m_FloatingWindowsLayout = JsonUtility.FromJson<FloatingWindowsLayout>(serializedWindowLayout);
m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout.GetLayout(layout);
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(layout);
}
else
{
m_FloatingWindowsLayout = new FloatingWindowsLayout();
}
}
m_FloatingWindowsLayout.previewLayout = m_MasterPreviewView.layout;
m_FloatingWindowsLayout.blackboardLayout = m_BlackboardProvider.blackboard.layout;
m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_MasterPreviewView.layout, layout);
m_FloatingWindowsLayout.blackboardLayout.CalculateDockingCornerAndOffset(m_BlackboardProvider.blackboard.layout, layout);
string serializedWindowLayout = JsonUtility.ToJson(m_FloatingWindowsLayout);
EditorUserSettings.SetConfigValue(m_FloatingWindowsLayoutKey, serializedWindowLayout);

105
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs


using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing
{
[Serializable]
public class WindowDockingLayout
{
[SerializeField]
bool m_DockingLeft;
public bool dockingLeft
{
get { return m_DockingLeft; }
}
[SerializeField]
bool m_DockingTop;
public bool dockingTop
{
get { return m_DockingTop; }
}
[SerializeField]
float m_VerticalOffset;
public float verticalOffset
{
get { return m_VerticalOffset; }
}
[SerializeField]
float m_HorizontalOffset;
public float horizontalOffset
{
get { return m_HorizontalOffset; }
}
[SerializeField]
Vector2 m_Size;
public Vector2 size
{
get { return m_Size; }
}
public void CalculateDockingCornerAndOffset(Rect layout, Rect parentLayout)
{
Vector2 layoutCenter = new Vector2(layout.x + layout.width * .5f, layout.y + layout.height * .5f);
layoutCenter /= parentLayout.size;
m_DockingLeft = layoutCenter.x < .5f;
m_DockingTop = layoutCenter.y < .5f;
if (m_DockingLeft)
{
m_HorizontalOffset = layout.x;
}
else
{
m_HorizontalOffset = parentLayout.width - layout.x - layout.width;
}
if (m_DockingTop)
{
m_VerticalOffset = layout.y;
}
else
{
m_VerticalOffset = parentLayout.height - layout.y - layout.height;
}
m_Size = layout.size;
}
public Rect GetLayout(Rect parentLayout)
{
Rect layout = new Rect();
layout.size = size;
if (dockingLeft)
{
layout.x = horizontalOffset;
}
else
{
layout.x = parentLayout.width - size.x - horizontalOffset;
}
if (dockingTop)
{
layout.y = verticalOffset;
}
else
{
layout.y = parentLayout.height - size.y - verticalOffset;
}
return layout;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs.meta


fileFormatVersion: 2
guid: 5f70875ecccbc924b8f9f0d58bbb37e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存