public void OnGUI() { EnsureResources(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); _disablePopups = GUILayout.Toggle(_disablePopups, "Disable Dialog Boxes"); GUILayout.EndHorizontal(); GUILayout.Label("<b><size=25>About</size></b> If you've decided to change serializers (for example, from Json.NET to Full Serializer), then this utility will assist your migration.", RichLabel); fiEditorGUILayout.Splitter(3); IPropertyEditor editor = PropertyEditor.Get(typeof(TypeSpecifier <BaseSerializer>), null).FirstEditor; GUILayout.Label("Select the <i>current</i> serializer and then the <i>new</i> serializer", RichLabel); fiEditorGUILayout.WithIndent(50, () => { WithTemporaryLabelWidth(120, () => { editor.EditWithGUILayout(new GUIContent("Current Serializer"), _currentSerializer, _metadata.Enter(0)); editor.EditWithGUILayout(new GUIContent("New Serializer"), _newSerializer, _metadata.Enter(1)); }); }); fiEditorGUILayout.Splitter(3); if (_currentSerializer.Type == null || _newSerializer.Type == null) { return; } if (_currentSerializer.Type == _newSerializer.Type) { EditorGUILayout.HelpBox("You cannot migrate to the same serializer", MessageType.Error); return; } _selectedMode = GUILayout.SelectionGrid(_selectedMode, new string[] { "Migrate Active Selection", "Migrate Scene Objects", "Migrate Persistent Objects" }, 3); if (_selectedMode == 0) { GameObject[] toMigrate = DisplaySelection(); if (GUILayout.Button("Run Migration") && CheckAnnotationsPopup()) { BeforeMigrate(); foreach (var obj in toMigrate) { fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type); } DisplayPostSerializeMessage(); } } else if (_selectedMode == 1) { DisplayScenesGUI(); if (SceneObjectSelections == null) { SceneObjectSelections = new UnityObjectSelectionGroup(fiSerializerMigrationUtility.GetSceneObjects()); } GUILayout.Label("Scene Objects to Process", EditorStyles.boldLabel); SceneObjectSelections.OnGUI(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Run Migration", GUILayout.ExpandWidth(true)) && CheckAnnotationsPopup()) { BeforeMigrate(); foreach (var obj in SceneObjectSelections.Selected) { fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type); } DisplayPostSerializeMessage(); } } else if (_selectedMode == 2) { if (PersistentObjectSelections == null) { PersistentObjectSelections = new UnityObjectSelectionGroup(fiSerializerMigrationUtility.GetPersistentObjects()); } GUILayout.Label("Persistent GameObjects to Process", EditorStyles.boldLabel); PersistentObjectSelections.OnGUI(); if (GUILayout.Button("Run Migration", GUILayout.ExpandWidth(true)) && CheckAnnotationsPopup()) { BeforeMigrate(); foreach (var obj in PersistentObjectSelections.Selected) { fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type); } DisplayPostSerializeMessage(); } } }
public void OnGUI() { try { EditorGUIUtility.hierarchyMode = true; Type updatedType = _inspectedType; GUILayout.Label("Static Inspector", EditorStyles.boldLabel); { var label = new GUIContent("Inspected Type"); var typeEditor = PropertyEditor.Get(typeof(Type), null); updatedType = typeEditor.FirstEditor.EditWithGUILayout(label, _inspectedType, Metadata.Enter("TypeSelector")); } fiEditorGUILayout.Splitter(2); if (_inspectedType != null) { _inspectorScrollPosition = EditorGUILayout.BeginScrollView(_inspectorScrollPosition); var inspectedType = InspectedType.Get(_inspectedType); foreach (InspectedProperty staticProperty in inspectedType.GetProperties(InspectedMemberFilters.StaticInspectableMembers)) { var editorChain = PropertyEditor.Get(staticProperty.StorageType, staticProperty.MemberInfo); IPropertyEditor editor = editorChain.FirstEditor; GUIContent label = new GUIContent(staticProperty.Name); object currentValue = staticProperty.Read(null); EditorGUILayout.BeginHorizontal(); EditorGUILayout.GetControlRect(GUILayout.Width(8)); EditorGUILayout.BeginVertical(); GUI.enabled = staticProperty.CanWrite; object updatedValue = editor.EditWithGUILayout(label, currentValue, Metadata.Enter(staticProperty.Name)); if (staticProperty.CanWrite) { staticProperty.Write(null, updatedValue); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); } // For some reason, the type selection popup window cannot force the rest of the // Unity GUI to redraw. We do it here instead -- this removes any delay after // selecting the type in the popup window and the type actually being displayed. if (fiEditorUtility.ShouldInspectorRedraw.Enabled) { Repaint(); } if (_inspectedType != updatedType) { _inspectedType = updatedType; Repaint(); } EditorGUIUtility.hierarchyMode = false; } catch (ExitGUIException) { } catch (Exception e) { Debug.LogError(e); } }