GameObject utility functions.

 protected virtual bool ShouldToolGUIBeDisabled(out GUIContent disabledLabel)
 {
     disabledLabel = Handles.s_StaticLabel;
     return(!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));
 }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            if (NavMeshAgentInspector.s_Styles == null)
            {
                NavMeshAgentInspector.s_Styles = new NavMeshAgentInspector.Styles();
            }
            base.serializedObject.Update();
            EditorGUILayout.LabelField(NavMeshAgentInspector.s_Styles.m_AgentSizeHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Radius, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Height, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_BaseOffset, new GUILayoutOption[0]);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(NavMeshAgentInspector.s_Styles.m_AgentSteeringHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Speed, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_AngularSpeed, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Acceleration, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_StoppingDistance, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_AutoBraking, new GUILayoutOption[0]);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(NavMeshAgentInspector.s_Styles.m_AgentAvoidanceHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_ObstacleAvoidanceType, GUIContent.Temp("Quality"), new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_AvoidancePriority, GUIContent.Temp("Priority"), new GUILayoutOption[0]);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(NavMeshAgentInspector.s_Styles.m_AgentPathFindingHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_AutoTraverseOffMeshLink, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_AutoRepath, new GUILayoutOption[0]);
            string[] navMeshAreaNames = GameObjectUtility.GetNavMeshAreaNames();
            int      intValue         = this.m_WalkableMask.intValue;
            int      num = 0;

            for (int i = 0; i < navMeshAreaNames.Length; i++)
            {
                int navMeshAreaFromName = GameObjectUtility.GetNavMeshAreaFromName(navMeshAreaNames[i]);
                if ((1 << navMeshAreaFromName & intValue) > 0)
                {
                    num |= 1 << i;
                }
            }
            Rect rect = GUILayoutUtility.GetRect(EditorGUILayout.kLabelFloatMinW, EditorGUILayout.kLabelFloatMaxW, 16f, 16f, EditorStyles.layerMaskField);

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_WalkableMask.hasMultipleDifferentValues;
            int num2 = EditorGUI.MaskField(rect, "Area Mask", num, navMeshAreaNames, EditorStyles.layerMaskField);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                if (num2 == -1)
                {
                    this.m_WalkableMask.intValue = -1;
                }
                else
                {
                    int num3 = 0;
                    for (int j = 0; j < navMeshAreaNames.Length; j++)
                    {
                        if ((num2 >> j & 1) > 0)
                        {
                            num3 |= 1 << GameObjectUtility.GetNavMeshAreaFromName(navMeshAreaNames[j]);
                        }
                    }
                    this.m_WalkableMask.intValue = num3;
                }
            }
            base.serializedObject.ApplyModifiedProperties();
        }
        static bool GetNearestHitFromPhysicsScene(Ray ray, PhysicsScene physicsScene, int cullingMask, bool ignorePrefabInstance, ref RaycastHit raycastHit)
        {
            float maxDist = raycastHit.distance;
            int   numHits = physicsScene.Raycast(ray.origin, ray.direction, s_RaySnapHits, maxDist, cullingMask, QueryTriggerInteraction.Ignore);

            // We are not sure at this point if the hits returned from RaycastAll are sorted or not, so go through them all
            float nearestHitDist  = maxDist;
            int   nearestHitIndex = -1;

            if (ignoreRaySnapObjects != null)
            {
                for (int i = 0; i < numHits; i++)
                {
                    if (s_RaySnapHits[i].distance < nearestHitDist)
                    {
                        Transform tr = s_RaySnapHits[i].transform;
                        if (ignorePrefabInstance && GameObjectUtility.IsPrefabInstanceHiddenForInContextEditing(tr.gameObject))
                        {
                            continue;
                        }

                        bool ignore = false;
                        for (int j = 0; j < ignoreRaySnapObjects.Length; j++)
                        {
                            if (tr == ignoreRaySnapObjects[j])
                            {
                                ignore = true;
                                break;
                            }
                        }
                        if (ignore)
                        {
                            continue;
                        }

                        nearestHitDist  = s_RaySnapHits[i].distance;
                        nearestHitIndex = i;
                    }
                }
            }
            else
            {
                for (int i = 0; i < numHits; i++)
                {
                    if (s_RaySnapHits[i].distance < nearestHitDist)
                    {
                        nearestHitDist  = s_RaySnapHits[i].distance;
                        nearestHitIndex = i;
                    }
                }
            }

            if (nearestHitIndex >= 0)
            {
                raycastHit = s_RaySnapHits[nearestHitIndex];
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject go = target as GameObject;

            if (!PrefabUtility.IsPartOfPrefabAsset(go))
            {
                return;
            }

            var prefabAssetRoot = go.transform.root.gameObject;

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.DragUpdated:

                Scene destinationScene = sceneView.customScene.IsValid() ? sceneView.customScene : SceneManager.GetActiveScene();
                if (dragObject == null)
                {
                    dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                    dragObject.name      = go.name;
                }

                if (HandleUtility.ignoreRaySnapObjects == null)
                {
                    HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object hit = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(evt.mousePosition));

                if (hit != null)
                {
                    RaycastHit rh     = (RaycastHit)hit;
                    float      offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, rh.normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, rh.normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(rh.point + (rh.normal * offset));
                }
                else
                {
                    dragObject.transform.position = HandleUtility.GUIPointToWorldRay(evt.mousePosition).GetPoint(10);
                }

                // Use prefabs original z position when in 2D mode
                if (sceneView.in2DMode)
                {
                    Vector3 dragPosition = dragObject.transform.position;
                    dragPosition.z = prefabAssetRoot.transform.position.z;
                    dragObject.transform.position = dragPosition;
                }

                evt.Use();
                break;

            case EventType.DragPerform:

                var stage = StageNavigationManager.instance.currentItem;
                if (stage.isPrefabStage)
                {
                    var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.prefabAssetPath);
                    if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefabAssetThatIsAddedTo, go))
                    {
                        PrefabUtility.ShowCyclicNestingWarningDialog();
                        return;
                    }
                }

                Transform parent = sceneView.customParentForDraggedObjects;

                string uniqueName = GameObjectUtility.GetUniqueNameForSibling(parent, dragObject.name);
                if (parent != null)
                {
                    dragObject.transform.parent = parent;
                }
                dragObject.hideFlags = 0;
                Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                EditorUtility.SetDirty(dragObject);
                DragAndDrop.AcceptDrag();
                Selection.activeObject             = dragObject;
                HandleUtility.ignoreRaySnapObjects = null;
                if (SceneView.mouseOverWindow != null)
                {
                    SceneView.mouseOverWindow.Focus();
                }
                dragObject.name = uniqueName;
                dragObject      = null;
                evt.Use();
                break;

            case EventType.DragExited:
                if (dragObject)
                {
                    UnityObject.DestroyImmediate(dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    dragObject = null;
                    evt.Use();
                }
                break;
            }
        }
        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);
            EditorGUI.BeginDisabledGroup(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.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_Name.hasMultipleDifferentValues;
            string name = EditorGUI.DelayedTextField(new Rect(52f, 4f + y + 1f, width2, 16f), gameObject.name, null, EditorStyles.textField);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                UnityEngine.Object[] targets = base.targets;
                for (int i = 0; i < targets.Length; i++)
                {
                    UnityEngine.Object @object = targets[i];
                    ObjectNames.SetNameSmart(@object as GameObject, name);
                }
            }
            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[] targets2 = base.targets;
                for (int j = 0; j < targets2.Length; j++)
                {
                    UnityEngine.Object object2 = targets2[j];
                    (object2 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 && !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"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert to prefab");
                        PrefabUtility.ReconnectToLastPrefab(gameObject);
                        PrefabUtility.RevertPrefabInstance(gameObject);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo(gameObject, "Reconnect prefab");
                        GUIUtility.ExitGUI();
                    }
                    bool enabled2 = GUI.enabled;
                    GUI.enabled = (GUI.enabled && !AnimationMode.InAnimationMode());
                    if ((prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert Prefab Instance");
                        PrefabUtility.RevertPrefabInstance(gameObject);
                        this.CalculatePrefabStatus();
                        GUIUtility.ExitGUI();
                    }
                    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 checkout the prefab before applying changes.");
                            if (flag2)
                            {
                                PrefabUtility.ReplacePrefab(gameObject2, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                                this.CalculatePrefabStatus();
                                GUIUtility.ExitGUI();
                            }
                        }
                    }
                    GUI.enabled = enabled2;
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", "MiniButtonRight"))
                    {
                        AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target));
                        GUIUtility.ExitGUI();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            base.serializedObject.ApplyModifiedProperties();
            return(true);
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject gameObject = this.target as GameObject;
            PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);

            if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab)
            {
                return;
            }
            Event     current = Event.current;
            EventType type    = current.type;

            if (type != EventType.DragUpdated)
            {
                if (type != EventType.DragPerform)
                {
                    if (type == EventType.DragExited)
                    {
                        if (GameObjectInspector.dragObject)
                        {
                            UnityEngine.Object.DestroyImmediate(GameObjectInspector.dragObject, false);
                            HandleUtility.ignoreRaySnapObjects = null;
                            GameObjectInspector.dragObject     = null;
                            current.Use();
                        }
                    }
                }
                else
                {
                    string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, GameObjectInspector.dragObject.name);
                    GameObjectInspector.dragObject.hideFlags = HideFlags.None;
                    Undo.RegisterCreatedObjectUndo(GameObjectInspector.dragObject, "Place " + GameObjectInspector.dragObject.name);
                    EditorUtility.SetDirty(GameObjectInspector.dragObject);
                    DragAndDrop.AcceptDrag();
                    Selection.activeObject             = GameObjectInspector.dragObject;
                    HandleUtility.ignoreRaySnapObjects = null;
                    EditorWindow.mouseOverWindow.Focus();
                    GameObjectInspector.dragObject.name = uniqueNameForSibling;
                    GameObjectInspector.dragObject      = null;
                    current.Use();
                }
            }
            else
            {
                if (GameObjectInspector.dragObject == null)
                {
                    GameObjectInspector.dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(gameObject));
                    HandleUtility.ignoreRaySnapObjects       = GameObjectInspector.dragObject.GetComponentsInChildren <Transform>();
                    GameObjectInspector.dragObject.hideFlags = HideFlags.HideInHierarchy;
                    GameObjectInspector.dragObject.name      = gameObject.name;
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                if (obj != null)
                {
                    RaycastHit raycastHit = (RaycastHit)obj;
                    float      d          = 0f;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float num = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, raycastHit.normal);
                        if (num != float.PositiveInfinity)
                        {
                            d = Vector3.Dot(GameObjectInspector.dragObject.transform.position, raycastHit.normal) - num;
                        }
                    }
                    GameObjectInspector.dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(raycastHit.point + raycastHit.normal * d);
                }
                else
                {
                    GameObjectInspector.dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                }
                if (sceneView.in2DMode)
                {
                    Vector3 position = GameObjectInspector.dragObject.transform.position;
                    position.z = PrefabUtility.FindPrefabRoot(gameObject).transform.position.z;
                    GameObjectInspector.dragObject.transform.position = position;
                }
                current.Use();
            }
        }
Exemple #7
0
        static Vector3 DoPlanarHandle(
            int id,
            int planePrimaryAxis,
            Vector3 position,
            Vector3 offset,
            Quaternion rotation,
            float handleSize,
            float cameraLerp,
            Vector3 viewVectorDrawSpace,
            PositionHandleParam.Orientation orientation)
        {
            var positionOffset = offset;

            var axis1index      = planePrimaryAxis;
            var axis2index      = (axis1index + 1) % 3;
            var axisNormalIndex = (axis1index + 2) % 3;

            Color prevColor = Handles.color;

            bool isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            color = isStatic ? staticColor : GetColorByAxis(axisNormalIndex);
            color = Color.Lerp(color, Color.clear, cameraLerp);

            var updateOpacityFillColor = false;

            if (GUIUtility.hotControl == id)
            {
                color = selectedColor;
            }
            else if (HandleUtility.nearestControl == id && !Event.current.alt)
            {
                color = preselectionColor;
            }
            else
            {
                updateOpacityFillColor = true;
            }

            color = ToActiveColorSpace(color);


            // NOTE: The planar transform handles always face toward the camera so they won't
            // obscure each other (unlike the X, Y, and Z axis handles which always face in the
            // positive axis directions). Whenever the octant that the camera is in (relative to
            // to the transform tool) changes, we need to move the planar transform handle
            // positions to the correct octant.

            // Comments below assume axis1 is X and axis2 is Z to make it easier to visualize things.

            // Shift the planar transform handle in the positive direction by half its
            // handleSize so that it doesn't overlap in the center of the transform gizmo,
            // and also move the handle origin into the octant that the camera is in.
            // Don't update the actant while dragging to avoid too much distraction.
            if (!currentlyDragging)
            {
                switch (orientation)
                {
                case PositionHandleParam.Orientation.Camera:
                    // Offset the X position of the handle in negative direction if camera is in the -X octants; otherwise positive.
                    // Test against -0.01 instead of 0 to give a little bias to the positive quadrants. This looks better in axis views.
                    s_PlanarHandlesOctant[axis1index] = (viewVectorDrawSpace[axis1index] > 0.01f ? -1 : 1);
                    // Likewise with the other axis.
                    s_PlanarHandlesOctant[axis2index] = (viewVectorDrawSpace[axis2index] > 0.01f ? -1 : 1);
                    break;

                case PositionHandleParam.Orientation.Signed:
                    s_PlanarHandlesOctant[axis1index] = 1;
                    s_PlanarHandlesOctant[axis2index] = 1;
                    break;
                }
            }
            Vector3 handleOffset = s_PlanarHandlesOctant;

            // Zero out the offset along the normal axis.
            handleOffset[axisNormalIndex] = 0;
            positionOffset = rotation * Vector3.Scale(positionOffset, handleOffset);
            // Rotate and scale the offset
            handleOffset = rotation * (handleOffset * handleSize * 0.5f);

            // Calculate 3 axes
            Vector3 axis1      = Vector3.zero;
            Vector3 axis2      = Vector3.zero;
            Vector3 axisNormal = Vector3.zero;

            axis1[axis1index]           = 1;
            axis2[axis2index]           = 1;
            axisNormal[axisNormalIndex] = 1;
            axis1      = rotation * axis1;
            axis2      = rotation * axis2;
            axisNormal = rotation * axisNormal;

            // Draw the "filler" color for the handle
            verts[0] = position + positionOffset + handleOffset + (axis1 + axis2) * handleSize * 0.5f;
            verts[1] = position + positionOffset + handleOffset + (-axis1 + axis2) * handleSize * 0.5f;
            verts[2] = position + positionOffset + handleOffset + (-axis1 - axis2) * handleSize * 0.5f;
            verts[3] = position + positionOffset + handleOffset + (axis1 - axis2) * handleSize * 0.5f;
            Color faceColor = updateOpacityFillColor ? new Color(color.r, color.g, color.b, 0.1f) : color;

            faceColor = ToActiveColorSpace(faceColor);
            Handles.DrawSolidRectangleWithOutline(verts, faceColor, Color.clear);

            // And then render the handle itself (this is the colored outline)
            position = Slider2D(id,
                                position,
                                handleOffset + positionOffset,
                                axisNormal,
                                axis1, axis2,
                                handleSize * 0.5f,
                                RectangleHandleCap,
                                GridSnapping.active ? Vector2.zero : new Vector2(SnapSettings.move[axis1index], SnapSettings.move[axis2index]),
                                false);

            Handles.color = prevColor;

            return(position);
        }
Exemple #8
0
        static Vector3 DoPositionHandle_Internal(PositionHandleIds ids, Vector3 position, Quaternion rotation, PositionHandleParam param)
        {
            Color temp = color;

            bool isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            // Calculate the camera view vector in Handle draw space
            // this handle the case where the matrix is skewed
            var handlePosition       = matrix.MultiplyPoint3x4(position);
            var drawToWorldMatrix    = matrix * Matrix4x4.TRS(position, rotation, Vector3.one);
            var invDrawToWorldMatrix = drawToWorldMatrix.inverse;
            var viewVectorDrawSpace  = GetCameraViewFrom(handlePosition, invDrawToWorldMatrix);

            var size = HandleUtility.GetHandleSize(position);

            // Calculate per axis camera lerp
            for (var i = 0; i < 3; ++i)
            {
                s_DoPositionHandle_Internal_CameraViewLerp[i] = ids[i] == GUIUtility.hotControl ? 0 : GetCameraViewLerpForWorldAxis(viewVectorDrawSpace, GetAxisVector(i));
            }
            // Calculate per plane camera lerp (xy, yz, xz)
            for (var i = 0; i < 3; ++i)
            {
                s_DoPositionHandle_Internal_CameraViewLerp[3 + i] = Mathf.Max(s_DoPositionHandle_Internal_CameraViewLerp[i], s_DoPositionHandle_Internal_CameraViewLerp[(i + 1) % 3]);
            }

            var isHot       = ids.Has(GUIUtility.hotControl);
            var axisOffset  = param.axisOffset;
            var planeOffset = param.planeOffset;

            if (isHot)
            {
                axisOffset  = Vector3.zero;
                planeOffset = Vector3.zero;
            }

            // Draw plane handles (xy, yz, xz)
            var planeSize = isHot ? param.planeSize + param.planeOffset : param.planeSize;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(3 + i) || isHot && ids[3 + i] != GUIUtility.hotControl)
                {
                    continue;
                }

                var cameraLerp = isHot ? 0 : s_DoPositionHandle_Internal_CameraViewLerp[3 + i];
                if (cameraLerp <= kCameraViewThreshold)
                {
                    var offset = planeOffset * size;
                    offset[s_DoPositionHandle_Internal_PrevIndex[i]] = 0;
                    var planarSize = Mathf.Max(planeSize[i], planeSize[s_DoPositionHandle_Internal_NextIndex[i]]);
                    position = DoPlanarHandle(ids[3 + i], i, position, offset, rotation, size * planarSize, cameraLerp, viewVectorDrawSpace, param.planeOrientation);
                }
            }

            // Draw axis sliders
            // Draw last to have priority over the planes
            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                if (!currentlyDragging)
                {
                    switch (param.axesOrientation)
                    {
                    case PositionHandleParam.Orientation.Camera:
                        s_DoPositionHandle_AxisHandlesOctant[i] = viewVectorDrawSpace[i] > 0.01f ? -1 : 1;
                        break;

                    case PositionHandleParam.Orientation.Signed:
                        s_DoPositionHandle_AxisHandlesOctant[i] = 1;
                        break;
                    }
                }

                var isThisAxisHot = isHot && ids[i] == GUIUtility.hotControl;

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                GUI.SetNextControlName(s_DoPositionHandle_Internal_AxisNames[i]);

                // if we are hot here, the hot handle must be opaque
                var cameraLerp = isThisAxisHot ? 0 : s_DoPositionHandle_Internal_CameraViewLerp[i];

                if (cameraLerp <= kCameraViewThreshold)
                {
                    color = Color.Lerp(color, Color.clear, cameraLerp);
                    var axisVector = GetAxisVector(i);
                    var dir        = rotation * axisVector;
                    var offset     = dir * axisOffset[i] * size;

                    dir    *= s_DoPositionHandle_AxisHandlesOctant[i];
                    offset *= s_DoPositionHandle_AxisHandlesOctant[i];

                    if (isHot && !isThisAxisHot)
                    {
                        color = s_DisabledHandleColor;
                    }

                    // A plane with this axis is hot
                    if (isHot && (ids[s_DoPositionHandle_Internal_PrevPlaneIndex[i]] == GUIUtility.hotControl || ids[i + 3] == GUIUtility.hotControl))
                    {
                        color = selectedColor;
                    }

                    color = ToActiveColorSpace(color);

                    s_DoPositionHandle_ArrowCapConeOffset = isHot
                        ? rotation * Vector3.Scale(Vector3.Scale(axisVector, param.axisOffset), s_DoPositionHandle_AxisHandlesOctant)
                        : Vector3.zero;
                    position = Slider(ids[i], position, offset, dir, size * param.axisSize[i], DoPositionHandle_ArrowCap, GridSnapping.active ? 0f : SnapSettings.move[i]);
                }
            }

            VertexSnapping.HandleMouseMove(ids.xyz);
            if (param.ShouldShow(PositionHandleParam.Handle.XYZ) && (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color = ToActiveColorSpace(centerColor);
                GUI.SetNextControlName("FreeMoveAxis");
                position = FreeMoveHandle(ids.xyz, position, rotation, size * kFreeMoveHandleSizeFactor, GridSnapping.active ? Vector3.zero : SnapSettings.move, RectangleHandleCap);
            }

            color = temp;

            if (GridSnapping.active)
            {
                position = GridSnapping.Snap(position);
            }

            return(position);
        }
        internal static Quaternion DoRotationHandle(RotationHandleIds ids, Quaternion rotation, Vector3 position, RotationHandleParam param)
        {
            var evt        = Event.current;
            var camForward = Handles.inverseMatrix.MultiplyVector(Camera.current != null ? Camera.current.transform.forward : Vector3.forward);

            var size     = HandleUtility.GetHandleSize(position);
            var temp     = color;
            var isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            var isHot = ids.Has(GUIUtility.hotControl);

            // Draw freerotation first to give it the lowest priority
            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.XYZ) &&
                (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color    = centerColor;
                rotation = UnityEditorInternal.FreeRotate.Do(ids.xyz, rotation, position, size * param.xyzSize, param.displayXYZCircle);
            }

            var radiusOfAxesHandles = -1f;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                color = ToActiveColorSpace(color);
                var axisDir = GetAxisVector(i);

                var radius = size * param.axisSize[i];
                radiusOfAxesHandles = Mathf.Max(radius, radiusOfAxesHandles);

                rotation = UnityEditorInternal.Disc.Do(ids[i], rotation, position, rotation * axisDir, radius, true, EditorSnapSettings.rotate, param.enableRayDrag, true, k_RotationPieColor);
            }

            if (radiusOfAxesHandles > 0 && evt.type == EventType.Repaint)
            {
                Handles.color = new Color(0, 0, 0, 0.2f);
                Handles.DrawWireDisc(position, camForward, radiusOfAxesHandles);
            }

            if (isHot && evt.type == EventType.Repaint)
            {
                color = ToActiveColorSpace(s_DisabledHandleColor);
                Handles.DrawWireDisc(position, camForward, size * param.axisSize[0]);
            }

            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.CameraAxis) &&
                (isHot && ids.cameraAxis == GUIUtility.hotControl || !isHot))
            {
                color    = ToActiveColorSpace(centerColor);
                rotation = UnityEditorInternal.Disc.Do(ids.cameraAxis, rotation, position, camForward, size * param.cameraAxisSize, false, 0, param.enableRayDrag, true, k_RotationPieColor);
            }

            color = temp;
            return(rotation);
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject target = this.target as GameObject;

            switch (PrefabUtility.GetPrefabType(target))
            {
            case PrefabType.Prefab:
            case PrefabType.ModelPrefab:
            {
                Event     current = Event.current;
                EventType type    = current.type;
                if (type != EventType.DragUpdated)
                {
                    if (type == EventType.DragPerform)
                    {
                        string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, dragObject.name);
                        dragObject.hideFlags = HideFlags.None;
                        Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                        EditorUtility.SetDirty(dragObject);
                        DragAndDrop.AcceptDrag();
                        Selection.activeObject             = dragObject;
                        HandleUtility.ignoreRaySnapObjects = null;
                        EditorWindow.mouseOverWindow.Focus();
                        dragObject.name = uniqueNameForSibling;
                        dragObject      = null;
                        current.Use();
                        return;
                    }
                    if ((type == EventType.DragExited) && (dragObject != null))
                    {
                        Object.DestroyImmediate(dragObject, false);
                        HandleUtility.ignoreRaySnapObjects = null;
                        dragObject = null;
                        current.Use();
                    }
                }
                else
                {
                    if (dragObject == null)
                    {
                        dragObject = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(target));
                        HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                        dragObject.hideFlags = HideFlags.HideInHierarchy;
                        dragObject.name      = target.name;
                    }
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj3 = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj3 != null)
                    {
                        RaycastHit hit = (RaycastHit)obj3;
                        float      num = 0f;
                        if (Tools.pivotMode == PivotMode.Center)
                        {
                            float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, hit.normal);
                            if (num2 != float.PositiveInfinity)
                            {
                                num = Vector3.Dot(dragObject.transform.position, hit.normal) - num2;
                            }
                        }
                        dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(hit.point + ((Vector3)(hit.normal * num)));
                    }
                    else
                    {
                        dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                    }
                    if (sceneView.in2DMode)
                    {
                        Vector3 position = dragObject.transform.position;
                        position.z = PrefabUtility.FindPrefabRoot(target).transform.position.z;
                        dragObject.transform.position = position;
                    }
                    current.Use();
                }
                break;
            }
            }
        }
        internal bool DrawInspector(Rect contentRect)
        {
            int  num5;
            bool flag4;

            if (s_styles == null)
            {
                s_styles = new Styles();
            }
            base.serializedObject.Update();
            GameObject target = 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 goIcon = null;
            PrefabType none   = PrefabType.None;

            if (this.m_AllOfSamePrefabType)
            {
                none = PrefabUtility.GetPrefabType(target);
                switch (none)
                {
                case PrefabType.None:
                    goIcon = s_styles.goIcon;
                    break;

                case PrefabType.Prefab:
                case PrefabType.PrefabInstance:
                case PrefabType.DisconnectedPrefabInstance:
                    goIcon = s_styles.prefabIcon;
                    break;

                case PrefabType.ModelPrefab:
                case PrefabType.ModelPrefabInstance:
                case PrefabType.DisconnectedModelPrefabInstance:
                    goIcon = s_styles.modelIcon;
                    break;

                case PrefabType.MissingPrefabInstance:
                    goIcon = s_styles.prefabIcon;
                    break;
                }
            }
            else
            {
                goIcon = s_styles.typelessIcon;
            }
            EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, goIcon.image as Texture2D, this.m_Icon);
            EditorGUI.BeginDisabledGroup(none == PrefabType.ModelPrefab);
            EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none);
            float num3 = s_styles.staticFieldToggleWidth + 15f;
            float num4 = ((width - 52f) - num3) - 5f;

            EditorGUI.DelayedTextField(new Rect(52f, (4f + y) + 1f, num4, 16f), this.m_Name, GUIContent.none);
            Rect totalPosition = new Rect(width - num3, 4f + y, s_styles.staticFieldToggleWidth, 16f);

            EditorGUI.BeginProperty(totalPosition, GUIContent.none, this.m_StaticEditorFlags);
            EditorGUI.BeginChangeCheck();
            Rect position = totalPosition;

            EditorGUI.showMixedValue |= ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue);
            Event     current = Event.current;
            EventType type    = current.type;
            bool      flag2   = (current.type == EventType.MouseDown) && (current.button != 0);

            if (flag2)
            {
                current.type = EventType.Ignore;
            }
            bool flagValue = EditorGUI.ToggleLeft(position, "Static", target.isStatic);

            if (flag2)
            {
                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;
            EditorGUI.EnumMaskField(new Rect(totalPosition.x + s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(target), s_styles.staticDropdown, out num5, out flag4);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(base.targets, num5, flag4);
                base.serializedObject.SetIsDifferentCacheDirty();
            }
            float num6 = 4f;
            float num7 = 4f;

            EditorGUIUtility.fieldWidth = ((((width - num6) - 52f) - s_styles.layerFieldWidth) - num7) / 2f;
            string tag = null;

            try
            {
                tag = target.tag;
            }
            catch (Exception)
            {
                tag = "Undefined";
            }
            EditorGUIUtility.labelWidth = s_styles.tagFieldWidth;
            Rect rect3 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);

            EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Tag);
            EditorGUI.BeginChangeCheck();
            string str2 = EditorGUI.TagField(rect3, EditorGUIUtility.TempContent("Tag"), tag);

            if (EditorGUI.EndChangeCheck())
            {
                this.m_Tag.stringValue = str2;
                Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle);
                foreach (Object obj3 in base.targets)
                {
                    (obj3 as GameObject).tag = str2;
                }
            }
            EditorGUI.EndProperty();
            EditorGUIUtility.labelWidth = s_styles.layerFieldWidth;
            rect3 = new Rect((52f + EditorGUIUtility.fieldWidth) + num6, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);
            EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Layer);
            EditorGUI.BeginChangeCheck();
            int layer = EditorGUI.LayerField(rect3, EditorGUIUtility.TempContent("Layer"), target.layer);

            if (EditorGUI.EndChangeCheck())
            {
                GameObjectUtility.ShouldIncludeChildren children = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?");
                if (children != GameObjectUtility.ShouldIncludeChildren.Cancel)
                {
                    this.m_Layer.intValue = layer;
                    this.SetLayer(layer, children == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
                }
            }
            EditorGUI.EndProperty();
            if (!this.m_HasInstance || EditorApplication.isPlayingOrWillChangePlaymode)
            {
                goto Label_093F;
            }
            float      num10    = ((width - 52f) - 5f) / 3f;
            Rect       rect4    = new Rect(52f + (num10 * 0f), 44f + y, num10, 15f);
            Rect       rect5    = new Rect(52f + (num10 * 1f), 44f + y, num10, 15f);
            Rect       rect6    = new Rect(52f + (num10 * 2f), 44f + y, num10, 15f);
            Rect       rect7    = new Rect(52f, 44f + y, num10 * 3f, 15f);
            GUIContent content2 = (base.targets.Length <= 1) ? s_styles.goTypeLabel[(int)none] : s_styles.goTypeLabelMultiple;

            if (content2 != null)
            {
                float x = GUI.skin.label.CalcSize(content2).x;
                switch (none)
                {
                case PrefabType.DisconnectedModelPrefabInstance:
                case PrefabType.MissingPrefabInstance:
                case PrefabType.DisconnectedPrefabInstance:
                    GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                    if (none == PrefabType.MissingPrefabInstance)
                    {
                        GUI.Label(new Rect(52f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel);
                    }
                    else
                    {
                        GUI.Label(new Rect((52f - x) - 5f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel);
                    }
                    GUI.contentColor = Color.white;
                    goto Label_072D;
                }
                Rect rect8 = new Rect((52f - x) - 5f, 44f + y, x, 18f);
                GUI.Label(rect8, content2);
            }
Label_072D:
            if (base.targets.Length > 1)
            {
                GUI.Label(rect7, "Instance Management Disabled", s_styles.instanceManagementInfo);
            }
            else
            {
                if ((none != PrefabType.MissingPrefabInstance) && GUI.Button(rect4, "Select", "MiniButtonLeft"))
                {
                    Selection.activeObject = PrefabUtility.GetPrefabParent(this.target);
                    EditorGUIUtility.PingObject(Selection.activeObject);
                }
                if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid"))
                {
                    Undo.RegisterFullObjectHierarchyUndo(target, "Revert to prefab");
                    PrefabUtility.ReconnectToLastPrefab(target);
                    PrefabUtility.RevertPrefabInstance(target);
                    this.CalculatePrefabStatus();
                    Undo.RegisterCreatedObjectUndo(target, "Reconnect prefab");
                    GUIUtility.ExitGUI();
                }
                bool flag5 = GUI.enabled;
                GUI.enabled = GUI.enabled && !AnimationMode.InAnimationMode();
                if (((none == PrefabType.ModelPrefabInstance) || (none == PrefabType.PrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid"))
                {
                    Undo.RegisterFullObjectHierarchyUndo(target, "Revert Prefab Instance");
                    PrefabUtility.RevertPrefabInstance(target);
                    this.CalculatePrefabStatus();
                    Undo.RegisterCreatedObjectUndo(target, "Revert prefab");
                    GUIUtility.ExitGUI();
                }
                if ((none == PrefabType.PrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance))
                {
                    GameObject source = PrefabUtility.FindValidUploadPrefabInstanceRoot(target);
                    GUI.enabled = (source != null) && !AnimationMode.InAnimationMode();
                    if (GUI.Button(rect6, "Apply", "MiniButtonRight"))
                    {
                        Object   prefabParent = PrefabUtility.GetPrefabParent(source);
                        string   assetPath    = AssetDatabase.GetAssetPath(prefabParent);
                        string[] assets       = new string[] { assetPath };
                        if (Provider.PromptAndCheckoutIfNeeded(assets, "The version control requires you to check out the prefab before applying changes."))
                        {
                            PrefabUtility.ReplacePrefab(source, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                            this.CalculatePrefabStatus();
                            GUIUtility.ExitGUI();
                        }
                    }
                }
                GUI.enabled = flag5;
                if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.ModelPrefabInstance)) && GUI.Button(rect6, "Open", "MiniButtonRight"))
                {
                    AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target));
                    GUIUtility.ExitGUI();
                }
            }
Label_093F:
            EditorGUI.EndDisabledGroup();
            base.serializedObject.ApplyModifiedProperties();
            return(true);
        }