{
bool m_Active;
bool m_DockLeft;
bool m_DockTop;
Rect m_PreviousParentRect;
m_PreviousParentRect = new Rect(0f, 0f, 0f, 0f);
}
protected override void RegisterCallbacksOnTarget()
target.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
target.RegisterCallback<PostLayoutEvent>(OnPostLayout);
target.RegisterCallback<PostLayoutEvent>(InitialLayoutSetup);
protected override void UnregisterCallbacksFromTarget()
evt.StopPropagation();
RefreshDocking();
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;
target.UnregisterCallback<PostLayoutEvent>(InitialLayoutSetup);
Rect inspectorViewRect = target.layout;
Rect windowRect = target.layout;
float minimumXPosition = target.layout.width - inspectorViewRect.width;
float maximumXPosition = target.parent.layout.width - target.layout.width;
Vector2 scaling = target.parent.layout.size / m_PreviousParentRect.size;
float minimumYPosition = target.layout.height - inspectorViewRect.height;
float maximumYPosition = target.parent.layout.height - target.layout.height;
Vector2 distanceFromEdge = Vector2.zero;
distanceFromEdge.x = m_DockLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromEdge.y = m_DockTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
inspectorViewRect.x = Mathf.Clamp(inspectorViewRect.x, minimumXPosition, maximumXPosition);
inspectorViewRect.y = Mathf.Clamp(inspectorViewRect.y, minimumYPosition, maximumYPosition);
Vector2 normalizedDistanceFromEdge = distanceFromEdge / m_PreviousParentRect.size;
windowRect.size *= scaling;
if (m_DockLeft)
windowRect.x = normalizedDistanceFromEdge.x * target.parent.layout.width;
else
windowRect.x = (1f - normalizedDistanceFromEdge.x) * target.parent.layout.width - windowRect.width;
if (m_DockTop)
windowRect.y = normalizedDistanceFromEdge.y * target.parent.layout.height;
windowRect.y = (1f - normalizedDistanceFromEdge.y) * target.parent.layout.height- windowRect.height;
inspectorViewRect.width = Mathf.Min(inspectorViewRect.width, target.layout.width);
inspectorViewRect.height = Mathf.Min(inspectorViewRect.height, target.layout.height);
float maximumXPosition = target.parent.layout.width - windowRect.width;
float maximumYPosition = target.parent.layout.height - windowRect.height;
target.layout = inspectorViewRect;
windowRect.x = Mathf.Clamp(windowRect.x, 0f, maximumXPosition);
windowRect.y = Mathf.Clamp(windowRect.y, 0f, maximumYPosition);
windowRect.width = Mathf.Min(windowRect.width, target.parent.layout.width);
windowRect.height = Mathf.Min(windowRect.height, target.parent.layout.height);
target.layout = windowRect;