There is a way of obtaining Unity Editor's main window. From there you can just obtain window size and set your custom editor window position :). I will just leave you the link.
[In case the link is broken]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
public static class Extensions
{
public static System.Type[] GetAllDerivedTypes(this System.AppDomain aAppDomain, System.Type aType)
{
var result = new List<System.Type>();
var assemblies = aAppDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsSubclassOf(aType))
result.Add(type);
}
}
return result.ToArray();
}
public static Rect GetEditorMainWindowPos()
{
var containerWinType = System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(ScriptableObject)).Where(t => t.Name == "ContainerWindow").FirstOrDefault();
if (containerWinType == null)
throw new System.MissingMemberException("Can't find internal type ContainerWindow. Maybe something has changed inside Unity");
var showModeField = containerWinType.GetField("m_ShowMode", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var positionProperty = containerWinType.GetProperty("position", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (showModeField == null || positionProperty == null)
throw new System.MissingFieldException("Can't find internal fields 'm_ShowMode' or 'position'. Maybe something has changed inside Unity");
var windows = Resources.FindObjectsOfTypeAll(containerWinType);
foreach (var win in windows)
{
var showmode = (int)showModeField.GetValue(win);
if (showmode == 4) // main window
{
var pos = (Rect)positionProperty.GetValue(win, null);
return pos;
}
}
throw new System.NotSupportedException("Can't find internal main window. Maybe something has changed inside Unity");
}
public static void CenterOnMainWin(this UnityEditor.EditorWindow aWin)
{
var main = GetEditorMainWindowPos();
var pos = aWin.position;
float w = (main.width - pos.width)*0.5f;
float h = (main.height - pos.height)*0.5f;
pos.x = main.x + w;
pos.y = main.y + h;
aWin.position = pos;
}
}
This is a js script, so if you are using Unity 2017.x you should probably translate it to c#(which shouldn't be too difficult since the syntax is pretty much the same). In this script there is also a function that let's you position every editor window in the center of the Main Unity window. All we have done here was using Extensions.GetEditorMainWindowPos() to get back the rect of the main window in screen coordinates.