private void DoPrefabButtons(PrefabType prefabType, GameObject go) { if (this.m_HasInstance) { using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode)) { EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIContent gUIContent = (base.targets.Length <= 1) ? GameObjectInspector.s_Styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_Styles.goTypeLabelMultiple; if (gUIContent != null) { EditorGUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Width(24f + GameObjectInspector.s_Styles.tagFieldWidth) }); GUILayout.FlexibleSpace(); if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; GUILayout.Label(gUIContent, EditorStyles.whiteLabel, new GUILayoutOption[] { GUILayout.ExpandWidth(false) }); GUI.contentColor = Color.white; } else { GUILayout.Label(gUIContent, new GUILayoutOption[] { GUILayout.ExpandWidth(false) }); } EditorGUILayout.EndHorizontal(); } if (base.targets.Length > 1) { GUILayout.Label("Instance Management Disabled", GameObjectInspector.s_Styles.instanceManagementInfo, new GUILayoutOption[0]); } else { if (prefabType != PrefabType.MissingPrefabInstance) { if (GUILayout.Button("Select", "MiniButtonLeft", new GUILayoutOption[0])) { Selection.activeObject = PrefabUtility.GetPrefabParent(base.target); EditorGUIUtility.PingObject(Selection.activeObject); } } if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { if (GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0])) { List <UnityEngine.Object> hierarchy = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(hierarchy, go); Undo.RegisterFullObjectHierarchyUndo(go, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(go); Undo.RegisterCreatedObjectUndo(PrefabUtility.GetPrefabObject(go), "Revert to prefab"); PrefabUtility.RevertPrefabInstance(go); this.CalculatePrefabStatus(); List <UnityEngine.Object> list = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(list, go); this.RegisterNewComponents(list, hierarchy); } } using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode())) { if (prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) { if (GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0])) { List <UnityEngine.Object> hierarchy2 = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(hierarchy2, go); Undo.RegisterFullObjectHierarchyUndo(go, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(go); this.CalculatePrefabStatus(); List <UnityEngine.Object> list2 = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(list2, go); this.RegisterNewComponents(list2, hierarchy2); } } if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GameObject gameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go); GUI.enabled = (gameObject != null && !AnimationMode.InAnimationMode()); if (GUILayout.Button("Apply", "MiniButtonRight", new GUILayoutOption[0])) { UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(gameObject); string assetPath = AssetDatabase.GetAssetPath(prefabParent); bool flag = Provider.PromptAndCheckoutIfNeeded(new string[] { assetPath }, "The version control requires you to check out the prefab before applying changes."); if (flag) { PrefabUtility.ReplacePrefab(gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); EditorSceneManager.MarkSceneDirty(gameObject.scene); GUIUtility.ExitGUI(); } } } } if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) { if (GUILayout.Button("Open", "MiniButtonRight", new GUILayoutOption[0])) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(base.target)); GUIUtility.ExitGUI(); } } } EditorGUILayout.EndHorizontal(); } } }
internal bool DrawInspector(Rect contentRect) { if (GameObjectInspector.s_styles == null) { GameObjectInspector.s_styles = new GameObjectInspector.Styles(); } base.serializedObject.Update(); GameObject gameObject = this.target as GameObject; EditorGUIUtility.labelWidth = 52f; bool enabled = GUI.enabled; GUI.enabled = true; GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig); GUI.enabled = enabled; float width = contentRect.width; float y = contentRect.y; GUIContent gUIContent = null; PrefabType prefabType = PrefabType.None; if (this.m_AllOfSamePrefabType) { prefabType = PrefabUtility.GetPrefabType(gameObject); switch (prefabType) { case PrefabType.None: gUIContent = GameObjectInspector.s_styles.goIcon; break; case PrefabType.Prefab: case PrefabType.PrefabInstance: case PrefabType.DisconnectedPrefabInstance: gUIContent = GameObjectInspector.s_styles.prefabIcon; break; case PrefabType.ModelPrefab: case PrefabType.ModelPrefabInstance: case PrefabType.DisconnectedModelPrefabInstance: gUIContent = GameObjectInspector.s_styles.modelIcon; break; case PrefabType.MissingPrefabInstance: gUIContent = GameObjectInspector.s_styles.prefabIcon; break; } } else { gUIContent = GameObjectInspector.s_styles.typelessIcon; } EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, gUIContent.image as Texture2D, this.m_Icon); using (new EditorGUI.DisabledScope(prefabType == PrefabType.ModelPrefab)) { EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none); float num = GameObjectInspector.s_styles.staticFieldToggleWidth + 15f; float width2 = width - 52f - num - 5f; EditorGUI.DelayedTextField(new Rect(52f, 4f + y + 1f, width2, 16f), this.m_Name, GUIContent.none); Rect rect = new Rect(width - num, 4f + y, GameObjectInspector.s_styles.staticFieldToggleWidth, 16f); EditorGUI.BeginProperty(rect, GUIContent.none, this.m_StaticEditorFlags); EditorGUI.BeginChangeCheck(); Rect position = rect; EditorGUI.showMixedValue |= GameObjectInspector.ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue); Event current = Event.current; EventType type = current.type; bool flag = current.type == EventType.MouseDown && current.button != 0; if (flag) { current.type = EventType.Ignore; } bool flagValue = EditorGUI.ToggleLeft(position, "Static", gameObject.isStatic); if (flag) { current.type = type; } EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, -1, flagValue); base.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues; int changedFlags; bool flagValue2; EditorGUI.EnumMaskField(new Rect(rect.x + GameObjectInspector.s_styles.staticFieldToggleWidth, rect.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(gameObject), GameObjectInspector.s_styles.staticDropdown, out changedFlags, out flagValue2); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, changedFlags, flagValue2); base.serializedObject.SetIsDifferentCacheDirty(); } float num2 = 4f; float num3 = 4f; EditorGUIUtility.fieldWidth = (width - num2 - 52f - GameObjectInspector.s_styles.layerFieldWidth - num3) / 2f; string tag = null; try { tag = gameObject.tag; } catch (Exception) { tag = "Undefined"; } EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.tagFieldWidth; Rect rect2 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect2, GUIContent.none, this.m_Tag); EditorGUI.BeginChangeCheck(); string text = EditorGUI.TagField(rect2, EditorGUIUtility.TempContent("Tag"), tag); if (EditorGUI.EndChangeCheck()) { this.m_Tag.stringValue = text; Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle); UnityEngine.Object[] targets = base.targets; for (int i = 0; i < targets.Length; i++) { UnityEngine.Object @object = targets[i]; (@object as GameObject).tag = text; } } EditorGUI.EndProperty(); EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.layerFieldWidth; rect2 = new Rect(52f + EditorGUIUtility.fieldWidth + num2, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect2, GUIContent.none, this.m_Layer); EditorGUI.BeginChangeCheck(); int num4 = EditorGUI.LayerField(rect2, EditorGUIUtility.TempContent("Layer"), gameObject.layer); if (EditorGUI.EndChangeCheck()) { GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(num4) + " for all child objects as well?"); if (shouldIncludeChildren != GameObjectUtility.ShouldIncludeChildren.Cancel) { this.m_Layer.intValue = num4; this.SetLayer(num4, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren); } } EditorGUI.EndProperty(); if (this.m_HasInstance) { using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode)) { float num5 = (width - 52f - 5f) / 3f; Rect position2 = new Rect(52f + num5 * 0f, 44f + y, num5, 15f); Rect position3 = new Rect(52f + num5 * 1f, 44f + y, num5, 15f); Rect position4 = new Rect(52f + num5 * 2f, 44f + y, num5, 15f); Rect position5 = new Rect(52f, 44f + y, num5 * 3f, 15f); GUIContent gUIContent2 = (base.targets.Length <= 1) ? GameObjectInspector.s_styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_styles.goTypeLabelMultiple; if (gUIContent2 != null) { float x = GUI.skin.label.CalcSize(gUIContent2).x; if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; if (prefabType == PrefabType.MissingPrefabInstance) { GUI.Label(new Rect(52f, 44f + y, width - 52f - 5f, 18f), gUIContent2, EditorStyles.whiteLabel); } else { GUI.Label(new Rect(52f - x - 5f, 44f + y, width - 52f - 5f, 18f), gUIContent2, EditorStyles.whiteLabel); } GUI.contentColor = Color.white; } else { Rect position6 = new Rect(52f - x - 5f, 44f + y, x, 18f); GUI.Label(position6, gUIContent2); } } if (base.targets.Length > 1) { GUI.Label(position5, "Instance Management Disabled", GameObjectInspector.s_styles.instanceManagementInfo); } else { if (prefabType != PrefabType.MissingPrefabInstance && GUI.Button(position2, "Select", "MiniButtonLeft")) { Selection.activeObject = PrefabUtility.GetPrefabParent(this.target); EditorGUIUtility.PingObject(Selection.activeObject); } if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid")) { List <UnityEngine.Object> hierarchy = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(hierarchy, gameObject); Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(gameObject); Undo.RegisterCreatedObjectUndo(PrefabUtility.GetPrefabObject(gameObject), "Revert to prefab"); PrefabUtility.RevertPrefabInstance(gameObject); this.CalculatePrefabStatus(); List <UnityEngine.Object> list = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(list, gameObject); this.RegisterNewComponents(list, hierarchy); } using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode())) { if ((prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid")) { List <UnityEngine.Object> hierarchy2 = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(hierarchy2, gameObject); Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(gameObject); this.CalculatePrefabStatus(); List <UnityEngine.Object> list2 = new List <UnityEngine.Object>(); this.GetObjectListFromHierarchy(list2, gameObject); this.RegisterNewComponents(list2, hierarchy2); } if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GameObject gameObject2 = PrefabUtility.FindValidUploadPrefabInstanceRoot(gameObject); GUI.enabled = (gameObject2 != null && !AnimationMode.InAnimationMode()); if (GUI.Button(position4, "Apply", "MiniButtonRight")) { UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(gameObject2); string assetPath = AssetDatabase.GetAssetPath(prefabParent); bool flag2 = Provider.PromptAndCheckoutIfNeeded(new string[] { assetPath }, "The version control requires you to check out the prefab before applying changes."); if (flag2) { PrefabUtility.ReplacePrefab(gameObject2, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); EditorSceneManager.MarkSceneDirty(gameObject2.scene); GUIUtility.ExitGUI(); } } } } if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", "MiniButtonRight")) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target)); GUIUtility.ExitGUI(); } } } } } base.serializedObject.ApplyModifiedProperties(); return(true); }