public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(rect, label, property); EditorGUI.LabelField(rect, label); var contentRect = rect.GetValueRect().Indent(2.0f); var spacing = 2.0f; var copy = property.Copy(); copy.Next(true); copy.Next(false); var durationRect = new Rect(contentRect.position, new Vector2(contentRect.width * 0.6f, rect.height)); var remainder = new Rect(new Vector2(durationRect.xMax, rect.yMin), new Vector2(contentRect.width - durationRect.width, rect.height)); durationRect = durationRect.Stretch(0.0f, -spacing, 0.0f, 0.0f); var toggleWidth = EditorGUIUtility.singleLineHeight; var loopingRect = new Rect(remainder.position, new Vector2(toggleWidth, rect.height)); var buttonRect = new Rect(new Vector2(loopingRect.xMax, rect.yMin), new Vector2(remainder.width - toggleWidth, rect.height)); loopingRect = loopingRect.Stretch(0.0f, -spacing, 0.0f, 0.0f); EditorGUI.PropertyField(durationRect, copy, GUIContent.none); copy.Next(false); EditorGUI.PropertyField(loopingRect, copy, GUIContent.none); if (GUI.Button(buttonRect, "Edit")) { window = ScriptableObject.CreateInstance(typeof(TimetableEditor)) as TimetableEditor; window.titleContent = EditorGUIUtility.TrTextContentWithIcon("Timetable", "SceneViewFx"); var position = GUIUtility.GUIToScreenPoint(UnityEngine.Event.current.mousePosition); var fullRect = EditorGUIUtility.GetMainWindowPosition(); var width = fullRect.width - position.x - padding; if (width < minWidth) { width = minWidth; position.x = fullRect.width - width - padding; } var height = fullRect.height - position.y - padding; if (height < minHeight) { height = minHeight; position.y = fullRect.height - height - padding; } window.ShowUtility(); window.position = new Rect(position, new Vector2(width, height)); window.Initialize(property); } EditorGUI.EndProperty(); }
public static Rect GetMainWindowPosition() { #if UNITY_2020_1_OR_NEWER return(EditorGUIUtility.GetMainWindowPosition()); #else return(EditorGUIUtilityProxy.GetMainWindowPosition()); #endif }
/* * Static. */ public static void Open() { var main = EditorGUIUtility.GetMainWindowPosition(); var centerWidth = (main.width - Width) * 0.5f; var centerHeight = (main.height - Height) * 0.5f; var window = GetWindow <AssetBundlesWindow>(false, "Asset Bundles Tool", true); window.position = new Rect(main.x + centerWidth, main.y + centerHeight, Width, Height); window.minSize = new Vector2(Width, Height); }
/// <summary> /// Centers the window in the main Unity window. This is not the same as centering a window on screen, /// because the Unity window may not be maximized. /// </summary> /// <param name="window">The window to center.</param> [PublicAPI] public static void CenterOnMainWin(this EditorWindow window) { #if UNITY_2020_1_OR_NEWER Rect main = EditorGUIUtility.GetMainWindowPosition(); #else Rect main = GetEditorMainWindowPos(); #endif Rect pos = window.position; float centerWidth = (main.width - pos.width) * 0.5f; float centerHeight = (main.height - pos.height) * 0.5f; pos.x = main.x + centerWidth; pos.y = main.y + centerHeight; window.position = pos; }
public static Rect GetMainWindowPositon() { #if !UNITY_2020_1_OR_NEWER return(EditorGUIUtility.GetMainWindowPosition()); #else UnityEngine.Object mainWindow = null; var containerWinType = TypeCache.GetTypesDerivedFrom(typeof(ScriptableObject)).FirstOrDefault(t => t.Name == "ContainerWindow"); if (containerWinType == null) { throw new 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); if (showModeField == null) { throw new MissingFieldException("Can't find internal fields 'm_ShowMode'. 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) { mainWindow = win; break; } } if (mainWindow == null) { Debug.LogWarning("Unity mainWindow API change,Please Check!"); return(new Rect(0f, 0f, 1000f, 600f)); } var positionProperty = mainWindow.GetType().GetProperty("position", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (positionProperty == null) { throw new MissingFieldException("Can't find internal fields 'position'. Maybe something has changed inside Unity."); } return((Rect)positionProperty.GetValue(mainWindow, null)); #endif }
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(rect, label, property); var header = rect.GetLayout(); EditorGUI.LabelField(header.label, label); if (GUI.Button(header.value, new GUIContent("Edit"))) { window = ScriptableObject.CreateInstance(typeof(SequenceGraph)) as SequenceGraph; window.titleContent = EditorGUIUtility.TrTextContentWithIcon("Sequence", "SceneViewFx"); var position = GUIUtility.GUIToScreenPoint(UnityEngine.Event.current.mousePosition); var fullRect = EditorGUIUtility.GetMainWindowPosition(); var width = fullRect.width - position.x - padding; if (width < minWidth) { width = minWidth; position.x = fullRect.width - width - padding; } var height = fullRect.height - position.y - padding; if (height < minHeight) { height = minHeight; position.y = fullRect.height - height - padding; } window.ShowUtility(); window.position = new Rect(position, new Vector2(width, height)); window.Initialize(property); } property.serializedObject.ApplyModifiedProperties(); EditorGUI.EndProperty(); }
internal static Rect GetMainWindowCenteredPosition(Vector2 size) { var mainWindowRect = EditorGUIUtility.GetMainWindowPosition(); return(EditorGUIUtility.GetCenteredWindowPosition(mainWindowRect, size)); }