private void GenerateEditor(Object obj) { if (!ObjectsToEditors.ContainsKey(obj)) { ObjectsToEditors[obj] = UEditor.CreateEditor(obj); } }
public IEnumerator SerializableTypeDrawerShouldShowWithoutErrors() { var editor = UEditor.CreateEditor(this); var testWindow = EditorWindow.GetWindow <TestEditorWindow>(); testWindow.onGui = new EditorEvent(() => editor.DrawDefaultInspector()); yield return(new WaitUntil(testWindow.OnGUIInitialized).OrTimeout(2000)); testWindow.Close(); }
public IEnumerator OnGUIShouldDrawWithoutErrors() { var obj = CreateInstance <ShowSerializeReferenceDrawerTest>(); var editor = UEditor.CreateEditor(obj); var testWindow = EditorWindow.GetWindow <TestEditorWindow>(); testWindow.onGui = new EditorEvent(() => editor.DrawDefaultInspector()); yield return(new WaitUntil(testWindow.OnGUIInitialized).OrTimeout(2000)); testWindow.Close(); }
protected override void OnGUI() { base.OnGUI(); // Reloaded from serialization if (treeView == null) { Close(); GUIUtility.ExitGUI(); } // Close on Escape if (e.type == EventType.KeyDown && e.modifiers == EventModifiers.None && e.keyCode == KeyCode.Escape) { Close(); GUIUtility.ExitGUI(); } var innerPosition = new Rect(0, 0, position.width, position.height); // Draw Background EditorGUI.DrawRect(innerPosition, ColorPalette.unityBackgroundMid); GUILayout.BeginVertical(); // Draw Search GUILayout.BeginHorizontal(LudiqStyles.searchFieldBackground, GUILayout.Height(LudiqStyles.searchFieldOuterHeight), GUILayout.ExpandWidth(true)); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName(searchFieldName); // Special keyboard controls while search field is selected if (GUI.GetNameOfFocusedControl() == searchFieldName && e.type == EventType.KeyDown) { // Pass arrow events to tree view if (e.keyCode == KeyCode.DownArrow || e.keyCode == KeyCode.UpArrow || !treeView.hasSearch && (e.keyCode == KeyCode.LeftArrow || e.keyCode == KeyCode.RightArrow)) { var selection = treeView.GetSelection(); treeView.SetFocus(); treeView.SetSelection(selection); } // Confirm search with enter else if (e.keyCode == KeyCode.Return) { if (treeView.SelectActive()) { Close(); GUIUtility.ExitGUI(); } else { e.Use(); } } // Close if pressing space again without search else if (e.keyCode == KeyCode.Space && !treeView.hasSearch) { Close(); GUIUtility.ExitGUI(); } } treeView.searchString = EditorGUILayout.TextField(treeView.searchString, LudiqStyles.searchField); // Focus on Search if (focusSearch && e.type == EventType.Repaint) { GUI.FocusControl(searchFieldName); focusSearch = false; } // Reload Tree View on Search if (EditorGUI.EndChangeCheck()) { treeView.Reload(); } // Search Cancel Button if (GUILayout.Button(GUIContent.none, treeView.hasSearch ? LudiqStyles.searchFieldCancelButton : LudiqStyles.searchFieldCancelButtonEmpty) && treeView.hasSearch) { treeView.searchString = string.Empty; treeView.Reload(); GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); // Horizontal Separator GUILayout.Box(GUIContent.none, LudiqStyles.horizontalSeparator); // Handle special keyboard strokes in tree view if (treeView.HasFocus() && e.type == EventType.KeyDown) { // Select current item if (e.keyCode == KeyCode.Space) { if (treeView.SelectActive()) { Close(); GUIUtility.ExitGUI(); } else { e.Use(); } } // Move back up to search field else if (e.keyCode == KeyCode.UpArrow) { if (treeView.GetSelection().FirstOrDefault() == treeView.GetRows().FirstOrDefault()?.id) { focusSearch = true; e.Use(); } } // Delete character from search else if (e.keyCode == KeyCode.Backspace) { treeView.searchString = treeView.searchString.Substring(0, Mathf.Max(0, treeView.searchString.Length - 1)); e.Use(); } // Append characters to search else if (e.modifiers == EventModifiers.None && !char.IsWhiteSpace(e.character) && !char.IsControl(e.character)) { treeView.searchString += e.character; e.Use(); } // Focus search else if (e.keyCode == KeyCode.F && e.CtrlOrCmd()) { focusSearch = true; e.Use(); } } // Draw Tree View var treeViewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); treeView.OnGUI(treeViewPosition); // Draw Preview previewEditorTargets.Clear(); previewEditorTargets.AddRange(treeView.GetActiveGameObjects()); if ((previewEditor == null && previewEditorTargets.Count > 0) || (previewEditor != null && !previewEditorTargets.SequenceEqual(previewEditor.targets))) { if (previewEditor != null) { DestroyImmediate(previewEditor); previewEditor = null; } previewEditor = UEditor.CreateEditor(previewEditorTargets.ToArray(), null); } if (previewEditor != null && (previewEditor.HasPreviewGUI() || previewEditorTargets.Any(PreviewUtility.HasPreview))) { GUILayout.Box(GUIContent.none, LudiqStyles.horizontalSeparator); var previewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(Styles.previewHeight), GUILayout.ExpandWidth(true)); previewEditor.DrawPreview(previewPosition); } GUILayout.EndVertical(); // Draw Border if (e.type == EventType.Repaint) { LudiqGUI.DrawEmptyRect(new Rect(Vector2.zero, position.size), ColorPalette.unityBackgroundVeryDark); } // Repaint on hover if (innerPosition.Contains(e.mousePosition)) { Repaint(); } }
public static Editor CreateEditor(UnityEngine.Object[] targetObjects) { Type editorType = null; return(Editor.CreateEditor(targetObjects, editorType)); }
public static Editor MakeCustomEditor(UnityEngine.Object obj) { return(Editor.CreateEditor(obj)); }
public override void OnInspectorGUI() { HandleUndoPerformed(); UpdateSelectedBone(); // case 837655. GUI.keyboardControl is overriden when changing scene selection. // Late update here to bypass this issue. if (s_KeyboardControl != 0) { GUIUtility.keyboardControl = s_KeyboardControl; s_KeyboardControl = 0; } GUILayout.BeginVertical(); { EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical("", "TE NodeBackground"); { m_BodyView = AvatarControl.ShowBoneMapping(m_BodyView, new AvatarControl.BodyPartFeedback(this.IsValidBodyPart), m_Bones, serializedObject, this); HandleBodyView(m_BodyView); } GUILayout.EndVertical(); m_FoldoutScroll = GUILayout.BeginScrollView(m_FoldoutScroll, styles.box, GUILayout.MinHeight(80), GUILayout.MaxHeight(500), GUILayout.ExpandHeight(true)); { DisplayFoldout(); GUILayout.FlexibleSpace(); } GUILayout.EndScrollView(); if (EditorGUI.EndChangeCheck()) { ValidateMapping(); SceneView.RepaintAll(); } DisplayMappingButtons(); } GUILayout.EndVertical(); if (EditorGUIUtility.hotControl == 0) { TransferPoseIfChanged(); } //DebugPoseButtons (); ApplyRevertGUI(); if (Selection.activeTransform != null) { // Selection is changing, clean up before we create a new editor if (m_CurrentTransformEditor != null && m_CurrentTransformEditor.target != Selection.activeTransform) { DestroyImmediate(m_CurrentTransformEditor); } if (m_CurrentTransformEditor == null) { m_CurrentTransformEditor = Editor.CreateEditor(Selection.activeTransform); } EditorGUILayout.Space(); m_CurrentTransformEditorFoldout = EditorGUILayout.InspectorTitlebar(m_CurrentTransformEditorFoldout, Selection.activeTransform, true); if (m_CurrentTransformEditorFoldout && m_CurrentTransformEditor != null) { m_CurrentTransformEditor.OnInspectorGUI(); } } else if (m_CurrentTransformEditor != null) { DestroyImmediate(m_CurrentTransformEditor); m_CurrentTransformEditor = null; } }
public void UpdateSelection(int newSelectedBrush) { m_SelectedBrush = newSelectedBrush; m_BrushEditor = Editor.CreateEditor(GetActiveBrush()); }
/// <summary> /// <para>Make a custom editor for targetObject or targetObjects.</para> /// </summary> /// <param name="objects">All objects must be of same exact type.</param> /// <param name="targetObject"></param> /// <param name="editorType"></param> /// <param name="targetObjects"></param> public static Editor CreateEditor(UnityEngine.Object targetObject, [DefaultValue("null")] System.Type editorType) { return(Editor.CreateEditor(new UnityEngine.Object[1] { targetObject }, editorType)); }
public static Editor CreateEditor(UnityEngine.Object targetObject) { System.Type editorType = (System.Type)null; return(Editor.CreateEditor(targetObject, editorType)); }
public override void OnInspectorGUI() { if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { AvatarSetupTool.TransferPoseToDescription(base.serializedObject, base.root); for (int i = 0; i < this.m_Bones.Length; i++) { this.m_Bones[i].Serialize(base.serializedObject); } } this.UpdateSelectedBone(); if (AvatarMappingEditor.s_KeyboardControl != 0) { GUIUtility.keyboardControl = AvatarMappingEditor.s_KeyboardControl; AvatarMappingEditor.s_KeyboardControl = 0; } GUILayout.BeginVertical(new GUILayoutOption[0]); EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical("", "TE NodeBackground", new GUILayoutOption[0]); this.m_BodyView = AvatarControl.ShowBoneMapping(this.m_BodyView, new AvatarControl.BodyPartFeedback(this.IsValidBodyPart), this.m_Bones, base.serializedObject, this); this.HandleBodyView(this.m_BodyView); GUILayout.EndVertical(); this.m_FoldoutScroll = GUILayout.BeginScrollView(this.m_FoldoutScroll, AvatarMappingEditor.styles.box, new GUILayoutOption[] { GUILayout.MinHeight(80f), GUILayout.MaxHeight(500f), GUILayout.ExpandHeight(true) }); this.DisplayFoldout(); GUILayout.FlexibleSpace(); GUILayout.EndScrollView(); if (EditorGUI.EndChangeCheck()) { this.ValidateMapping(); SceneView.RepaintAll(); } this.DisplayMappingButtons(); GUILayout.EndVertical(); if (GUIUtility.hotControl == 0) { this.TransferPoseIfChanged(); } base.ApplyRevertGUI(); if (Selection.activeTransform != null) { if (this.m_CurrentTransformEditor != null && this.m_CurrentTransformEditor.target != Selection.activeTransform) { UnityEngine.Object.DestroyImmediate(this.m_CurrentTransformEditor); } if (this.m_CurrentTransformEditor == null) { this.m_CurrentTransformEditor = Editor.CreateEditor(Selection.activeTransform); } EditorGUILayout.Space(); this.m_CurrentTransformEditorFoldout = EditorGUILayout.InspectorTitlebar(this.m_CurrentTransformEditorFoldout, Selection.activeTransform, true); if (this.m_CurrentTransformEditorFoldout && this.m_CurrentTransformEditor != null) { this.m_CurrentTransformEditor.OnInspectorGUI(); } } else if (this.m_CurrentTransformEditor != null) { UnityEngine.Object.DestroyImmediate(this.m_CurrentTransformEditor); this.m_CurrentTransformEditor = null; } }
public override void OnInspectorGUI() { if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { AvatarSetupTool.TransferPoseToDescription(this.serializedObject, this.root); for (int index = 0; index < this.m_Bones.Length; ++index) { this.m_Bones[index].Serialize(this.serializedObject); } } this.UpdateSelectedBone(); if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Backspace || Event.current.keyCode == KeyCode.Delete) && (AvatarMappingEditor.s_SelectedBoneIndex != -1 && AvatarMappingEditor.s_SelectedBoneIndex < this.m_Bones.Length)) { Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this, "Avatar mapping modified"); AvatarSetupTool.BoneWrapper bone = this.m_Bones[AvatarMappingEditor.s_SelectedBoneIndex]; bone.bone = (Transform)null; bone.state = BoneState.None; bone.Serialize(this.serializedObject); Selection.activeTransform = (Transform)null; GUI.changed = true; Event.current.Use(); } GUILayout.BeginVertical(); EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical(string.Empty, (GUIStyle)"TE NodeBackground", new GUILayoutOption[0]); this.m_BodyView = AvatarControl.ShowBoneMapping(this.m_BodyView, new AvatarControl.BodyPartFeedback(this.IsValidBodyPart), this.m_Bones, this.serializedObject, this); this.HandleBodyView(this.m_BodyView); GUILayout.EndVertical(); this.m_FoldoutScroll = GUILayout.BeginScrollView(this.m_FoldoutScroll, AvatarMappingEditor.styles.box, GUILayout.MinHeight(80f), GUILayout.MaxHeight(500f), GUILayout.ExpandHeight(true)); this.DisplayFoldout(); GUILayout.FlexibleSpace(); GUILayout.EndScrollView(); if (EditorGUI.EndChangeCheck()) { this.ValidateMapping(); SceneView.RepaintAll(); } this.DisplayMappingButtons(); GUILayout.EndVertical(); if (GUIUtility.hotControl == 0) { this.TransferPoseIfChanged(); } this.ApplyRevertGUI(); if ((UnityEngine.Object)Selection.activeTransform != (UnityEngine.Object)null) { if ((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null && this.m_CurrentTransformEditor.target != (UnityEngine.Object)Selection.activeTransform) { UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_CurrentTransformEditor); } if ((UnityEngine.Object) this.m_CurrentTransformEditor == (UnityEngine.Object)null) { this.m_CurrentTransformEditor = Editor.CreateEditor((UnityEngine.Object)Selection.activeTransform); } EditorGUILayout.Space(); this.m_CurrentTransformEditorFoldout = EditorGUILayout.InspectorTitlebar(this.m_CurrentTransformEditorFoldout, (UnityEngine.Object)Selection.activeTransform, true); if (!this.m_CurrentTransformEditorFoldout || !((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null)) { return; } this.m_CurrentTransformEditor.OnInspectorGUI(); } else { if (!((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null)) { return; } UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_CurrentTransformEditor); this.m_CurrentTransformEditor = (Editor)null; } }