AnimationMode is used by the AnimationWindow to store properties modified by the AnimationClip playback.

        internal bool DrawInspector(Rect contentRect)
        {
            int  num6;
            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.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_Name.hasMultipleDifferentValues;
            string name = EditorGUI.DelayedTextField(new Rect(52f, (4f + y) + 1f, num4, 16f), target.name, null, EditorStyles.textField);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                foreach (UnityEngine.Object obj3 in base.targets)
                {
                    ObjectNames.SetNameSmart(obj3 as GameObject, name);
                }
            }
            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 num6, out flag4);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(base.targets, num6, flag4);
                base.serializedObject.SetIsDifferentCacheDirty();
            }
            float num7 = 4f;
            float num8 = 4f;

            EditorGUIUtility.fieldWidth = ((((width - num7) - 52f) - s_styles.layerFieldWidth) - num8) / 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 str3 = EditorGUI.TagField(rect3, EditorGUIUtility.TempContent("Tag"), tag);

            if (EditorGUI.EndChangeCheck())
            {
                this.m_Tag.stringValue = str3;
                Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle);
                foreach (UnityEngine.Object obj4 in base.targets)
                {
                    (obj4 as GameObject).tag = str3;
                }
            }
            EditorGUI.EndProperty();
            EditorGUIUtility.labelWidth = s_styles.layerFieldWidth;
            rect3 = new Rect((52f + EditorGUIUtility.fieldWidth) + num7, 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_0992;
            }
            float      num11    = ((width - 52f) - 5f) / 3f;
            Rect       rect4    = new Rect(52f + (num11 * 0f), 44f + y, num11, 15f);
            Rect       rect5    = new Rect(52f + (num11 * 1f), 44f + y, num11, 15f);
            Rect       rect6    = new Rect(52f + (num11 * 2f), 44f + y, num11, 15f);
            Rect       rect7    = new Rect(52f, 44f + y, num11 * 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_078B;
                }
                Rect rect8 = new Rect((52f - x) - 5f, 44f + y, x, 18f);
                GUI.Label(rect8, content2);
            }
Label_078B:
            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();
                    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"))
                    {
                        UnityEngine.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_0992:
            EditorGUI.EndDisabledGroup();
            base.serializedObject.ApplyModifiedProperties();
            return(true);
        }
        public void RotationField(bool disabled)
        {
            Transform transform0   = targets[0] as Transform;
            Vector3   eulerAngles0 = transform0.GetLocalEulerAngles(transform0.rotationOrder);

            int  differentRotationMask  = 0b000;
            bool differentRotationOrder = false;

            for (int i = 1; i < targets.Length; i++)
            {
                Transform otherTransform = (targets[i] as Transform);
                if (differentRotationMask != 0b111)
                {
                    Vector3 otherLocalEuler = otherTransform.GetLocalEulerAngles(otherTransform.rotationOrder);
                    for (int j = 0; j < 3; j++)
                    {
                        if (otherLocalEuler[j] != eulerAngles0[j])
                        {
                            differentRotationMask |= 1 << j;
                        }
                    }
                }

                differentRotationOrder |= otherTransform.rotationOrder != transform0.rotationOrder;
            }

            Rect       r     = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
            GUIContent label = EditorGUI.BeginProperty(r, rotationContent, m_Rotation);

            m_EulerFloats[0].doubleVal = eulerAngles0.x;
            m_EulerFloats[1].doubleVal = eulerAngles0.y;
            m_EulerFloats[2].doubleVal = eulerAngles0.z;

            int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, r);

            if (AnimationMode.InAnimationMode() && transform0.rotationOrder != RotationOrder.OrderZXY)
            {
                string rotationLabel = differentRotationOrder ? "Mixed" : transform0.rotationOrder.ToString().Substring(RotationOrder.OrderXYZ.ToString().Length - 3);
                label.text = label.text + " (" + rotationLabel + ")";
            }

            // Using manual 3 float fields here instead of MultiFloatField or Vector3Field
            // since we want to query expression validity of each individually, and
            // so that the label and the fields can be disabled separately, similar to
            // regular property fields. Also want to avoid superfluous label, which
            // creates a focus target even when there's no content (Case 953241).
            r        = EditorGUI.MultiFieldPrefixLabel(r, id, label, 3);
            r.height = EditorGUIUtility.singleLineHeight;
            int eulerChangedMask = 0;

            using (new EditorGUI.DisabledScope(disabled))
            {
                var   eCount = m_EulerFloats.Length;
                float w      = (r.width - (eCount - 1) * EditorGUI.kSpacingSubLabel) / eCount;
                Rect  nr     = new Rect(r)
                {
                    width = w
                };
                var prevWidth  = EditorGUIUtility.labelWidth;
                var prevIndent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;
                for (int i = 0; i < m_EulerFloats.Length; i++)
                {
                    EditorGUIUtility.labelWidth = EditorGUI.GetLabelWidth(s_XYZLabels[i]);
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.showMixedValue = (differentRotationMask & (1 << i)) != 0;
                    EditorGUI.FloatField(nr, s_XYZLabels[i], ref m_EulerFloats[i]);
                    if (EditorGUI.EndChangeCheck() && m_EulerFloats[i].hasResult)
                    {
                        eulerChangedMask |= 1 << i;
                    }
                    nr.x += w + EditorGUI.kSpacingSubLabel;
                }
                EditorGUIUtility.labelWidth = prevWidth;
                EditorGUI.indentLevel       = prevIndent;
            }

            if (eulerChangedMask != 0)
            {
                eulerAngles0 = new Vector3(
                    MathUtils.ClampToFloat(m_EulerFloats[0].doubleVal),
                    MathUtils.ClampToFloat(m_EulerFloats[1].doubleVal),
                    MathUtils.ClampToFloat(m_EulerFloats[2].doubleVal));
                Undo.RecordObjects(targets, "Inspector");  // Generic undo title as remove duplicates will discard the name.
                Undo.SetCurrentGroupName(string.Format("Set Rotation"));
                for (var idx = 0; idx < targets.Length; ++idx)
                {
                    var tr = targets[idx] as Transform;
                    if (tr == null)
                    {
                        continue;
                    }
                    var trEuler = tr.GetLocalEulerAngles(tr.rotationOrder);
                    // if we have any per-object expressions just entered, we need to evaluate
                    // it for each object with their own individual input value
                    for (int c = 0; c < 3; ++c)
                    {
                        if ((eulerChangedMask & (1 << c)) != 0)
                        {
                            if (m_EulerFloats[c].expression != null)
                            {
                                double trEulerComp = eulerAngles0[c];
                                if (m_EulerFloats[c].expression.Evaluate(ref trEulerComp, idx, targets.Length))
                                {
                                    trEuler[c] = MathUtils.ClampToFloat(trEulerComp);
                                }
                            }
                            else
                            {
                                trEuler[c] = MathUtils.ClampToFloat(eulerAngles0[c]);
                            }
                        }
                    }
                    tr.SetLocalEulerAngles(trEuler, tr.rotationOrder);
                    if (tr.parent != null)
                    {
                        tr.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent.
                    }
                }
                m_Rotation.serializedObject.SetIsDifferentCacheDirty();
            }

            EditorGUI.showMixedValue = false;

            if (differentRotationOrder)
            {
                EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning);
            }

            EditorGUI.EndProperty();
        }
Beispiel #3
0
        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.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 && !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();
                        Undo.RegisterCreatedObjectUndo(gameObject, "Revert prefab");
                        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 check out 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 RotationField(bool disabled)
        {
            Transform transform        = this.targets[0] as Transform;
            Vector3   localEulerAngles = transform.GetLocalEulerAngles(transform.rotationOrder);

            if (this.m_OldEulerAngles.x != localEulerAngles.x || this.m_OldEulerAngles.y != localEulerAngles.y || this.m_OldEulerAngles.z != localEulerAngles.z || this.m_OldRotationOrder != transform.rotationOrder)
            {
                this.m_EulerAngles      = transform.GetLocalEulerAngles(transform.rotationOrder);
                this.m_OldRotationOrder = transform.rotationOrder;
            }
            bool flag  = false;
            bool flag2 = false;

            for (int i = 1; i < this.targets.Length; i++)
            {
                Transform transform2        = this.targets[i] as Transform;
                Vector3   localEulerAngles2 = transform2.GetLocalEulerAngles(transform2.rotationOrder);
                flag  |= (localEulerAngles2.x != localEulerAngles.x || localEulerAngles2.y != localEulerAngles.y || localEulerAngles2.z != localEulerAngles.z);
                flag2 |= (transform2.rotationOrder != transform.rotationOrder);
            }
            Rect       rect       = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (float)((!EditorGUIUtility.wideMode) ? 2 : 1), new GUILayoutOption[0]);
            GUIContent gUIContent = EditorGUI.BeginProperty(rect, this.rotationContent, this.m_Rotation);

            EditorGUI.showMixedValue = flag;
            EditorGUI.BeginChangeCheck();
            int    controlID = GUIUtility.GetControlID(TransformRotationGUI.s_FoldoutHash, EditorGUIUtility.native, rect);
            string text      = string.Empty;

            if (AnimationMode.InAnimationMode() && transform.rotationOrder != RotationOrder.OrderZXY)
            {
                if (flag2)
                {
                    text = "Mixed";
                }
                else
                {
                    text = transform.rotationOrder.ToString();
                    text = text.Substring(text.Length - 3);
                }
                gUIContent.text = gUIContent.text + " (" + text + ")";
            }
            rect        = EditorGUI.MultiFieldPrefixLabel(rect, controlID, gUIContent, 3);
            rect.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.DisabledScope(disabled))
            {
                this.m_EulerAngles = EditorGUI.Vector3Field(rect, GUIContent.none, this.m_EulerAngles);
            }
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObjects(this.targets, "Inspector");
                UnityEngine.Object[] array = this.targets;
                for (int j = 0; j < array.Length; j++)
                {
                    Transform transform3 = (Transform)array[j];
                    transform3.SetLocalEulerAngles(this.m_EulerAngles, transform3.rotationOrder);
                    if (transform3.parent != null)
                    {
                        transform3.SendTransformChangedScale();
                    }
                }
                this.m_Rotation.serializedObject.SetIsDifferentCacheDirty();
            }
            EditorGUI.showMixedValue = false;
            if (flag2)
            {
                EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning);
            }
            EditorGUI.EndProperty();
        }
Beispiel #5
0
 public static void AddPropertyModification(EditorCurveBinding binding, PropertyModification modification, bool keepPrefabOverride)
 {
     AnimationMode.AddPropertyModification_Injected(ref binding, modification, keepPrefabOverride);
 }
Beispiel #6
0
 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]))
                         {
                             this.RevertAndCheckForNewComponents(go);
                         }
                     }
                     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();
         }
     }
 }
Beispiel #7
0
        private void BakeMesh()
        {
            if (bakeObject == null)
            {
                return;
            }

            if (animationClip == null)
            {
                return;
            }

            // There is a bug in AnimationMode.SampleAnimationClip which crashes
            // Unity if there is no valid controller attached
            Animator animator = bakeObject.GetComponent <Animator>();

            if (animator != null && animator.runtimeAnimatorController == null)
            {
                return;
            }

            //Collect information about gameObject
            List <MeshFilter>          tmpFilters       = bakeObject.GetComponentsInChildren <MeshFilter>().ToList();
            List <SkinnedMeshRenderer> tmpMeshRenderers = new List <SkinnedMeshRenderer>();

            for (int i = 0; i < tmpFilters.Count; i++)
            {
                MeshFilter          filter       = tmpFilters[i];
                SkinnedMeshRenderer meshRenderer = filter.GetComponent <SkinnedMeshRenderer>();

                if (meshRenderer != null)
                {
                    tmpFilters.RemoveAt(i);
                    tmpMeshRenderers.Add(meshRenderer);
                    i--;
                }
            }

            filters   = tmpFilters.ToArray();
            renderers = tmpMeshRenderers.ToArray();

            Mesh firstFrame = new Mesh();

            EditorUtility.DisplayProgressBar("Mesh Animation Baker", "Baking", 0f);

            //Now bake
            AnimationMode.StartAnimationMode();
            AnimationMode.BeginSampling();

            for (int frame = 0; frame < frameCount; frame++)
            {
                EditorUtility.DisplayProgressBar("Mesh Animation Baker", "Baking mesh animations", 1f * frame / frameCount);

                AnimationMode.SampleAnimationClip(bakeObject, animationClip, frame / frameRate);
                Mesh bakedMesh = CombineMeshes(bakeObject);

                if (!bufferReady)
                {
                    buffer.Expand(VertType.VNT, bakedMesh.vertexCount, frameCount);
                    frameStride = buffer.vertexSize * buffer.vertexCount;
                    bufferReady = true;
                }

                for (int i = 0; i < bakedMesh.vertexCount; i++)
                {
                    int vertStart       = i * buffer.vertexSize;
                    int globalVertStart = frameStride * frame + vertStart;
                    buffer.data[globalVertStart]     = bakedMesh.vertices[i].x;
                    buffer.data[globalVertStart + 1] = bakedMesh.vertices[i].y;
                    buffer.data[globalVertStart + 2] = bakedMesh.vertices[i].z;

                    buffer.data[globalVertStart + 3] = bakedMesh.normals[i].x;
                    buffer.data[globalVertStart + 4] = bakedMesh.normals[i].y;
                    buffer.data[globalVertStart + 5] = bakedMesh.normals[i].z;

                    buffer.data[globalVertStart + 6] = bakedMesh.tangents[i].x;
                    buffer.data[globalVertStart + 7] = bakedMesh.tangents[i].y;
                    buffer.data[globalVertStart + 8] = bakedMesh.tangents[i].z;
                }

                if (frame == 0)
                {
                    firstFrame = bakedMesh;
                }
            }

            string filePath = Path.Combine(Application.dataPath, vertaPath);

            FileInfo fileInfo = new FileInfo(filePath);

            if (!Directory.Exists(fileInfo.Directory.FullName))
            {
                Directory.CreateDirectory(fileInfo.Directory.FullName);
            }

            filePath += $"/{modelName}.verta";

            buffer.SaveToFile(filePath);

            filePath = Path.Combine("Assets", meshDataPath);

            fileInfo = new FileInfo(filePath);
            if (!Directory.Exists(fileInfo.Directory.FullName))
            {
                Directory.CreateDirectory(fileInfo.Directory.FullName);
            }

            filePath += $"/{modelName}.asset";

            byte[] bytes = MeshDataAssetEditor.saveMeshToMeshAsset(firstFrame);

            MeshDataAsset asset = new MeshDataAsset();

            asset.bytes = bytes;

            AssetDatabase.CreateAsset(asset, filePath);

            EditorUtility.ClearProgressBar();

            AnimationMode.EndSampling();
            AnimationMode.StopAnimationMode();
        }
 public static void StartAnimationMode(Object[] objects)
 {
     Debug.LogWarning("AnimationUtility.StartAnimationMode is deprecated. Use AnimationMode.StartAnimationMode with the new APIs. The objects passed to this function will no longer be reverted automatically. See AnimationMode.AddPropertyModification");
     AnimationMode.StartAnimationMode();
 }
Beispiel #9
0
 public static void AddPropertyModification(EditorCurveBinding binding, PropertyModification modification, bool keepPrefabOverride)
 {
     AnimationMode.INTERNAL_CALL_AddPropertyModification(ref binding, modification, keepPrefabOverride);
 }
Beispiel #10
0
        public void RotationField(bool disabled)
        {
            Transform t          = targets[0] as Transform;
            Vector3   localEuler = t.GetLocalEulerAngles(t.rotationOrder);

            if (
                m_OldEulerAngles.x != localEuler.x ||
                m_OldEulerAngles.y != localEuler.y ||
                m_OldEulerAngles.z != localEuler.z ||
                m_OldRotationOrder != t.rotationOrder
                )
            {
                m_EulerAngles      = t.GetLocalEulerAngles(t.rotationOrder);
                m_OldRotationOrder = t.rotationOrder;
            }
            bool differentRotation      = false;
            bool differentRotationOrder = false;

            for (int i = 1; i < targets.Length; i++)
            {
                Transform otherTransform  = (targets[i] as Transform);
                Vector3   otherLocalEuler = otherTransform.GetLocalEulerAngles(otherTransform.rotationOrder);
                differentRotation |= (otherLocalEuler.x != localEuler.x ||
                                      otherLocalEuler.y != localEuler.y ||
                                      otherLocalEuler.z != localEuler.z);

                differentRotationOrder |= otherTransform.rotationOrder != t.rotationOrder;
            }

            Rect       r     = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
            GUIContent label = EditorGUI.BeginProperty(r, rotationContent, m_Rotation);

            EditorGUI.showMixedValue = differentRotation;

            EditorGUI.BeginChangeCheck();

            int    id            = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, r);
            string rotationLabel = "";

            if (AnimationMode.InAnimationMode() && t.rotationOrder != RotationOrder.OrderZXY)
            {
                if (differentRotationOrder)
                {
                    rotationLabel = "Mixed";
                }
                else
                {
                    rotationLabel = (t.rotationOrder).ToString();
                    rotationLabel = rotationLabel.Substring(rotationLabel.Length - 3);
                }

                label.text = label.text + " (" + rotationLabel + ")";
            }

            r        = EditorGUI.MultiFieldPrefixLabel(r, id, label, 3);
            r.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.DisabledScope(disabled))
            {
                m_EulerAngles = EditorGUI.Vector3Field(r, GUIContent.none, m_EulerAngles);
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObjects(targets, "Inspector");  // Generic undo title to be consistent with Position and Scale changes.
                foreach (Transform tr in targets)
                {
                    tr.SetLocalEulerAngles(m_EulerAngles, tr.rotationOrder);
                    if (tr.parent != null)
                    {
                        tr.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent.
                    }
                }
                m_Rotation.serializedObject.SetIsDifferentCacheDirty();
            }

            EditorGUI.showMixedValue = false;

            if (differentRotationOrder)
            {
                EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning);
            }

            EditorGUI.EndProperty();
        }
Beispiel #11
0
 public static void StartAnimationMode()
 {
     AnimationMode.StartAnimationMode(AnimationMode.DummyDriver());
 }
Beispiel #12
0
 internal static bool InAnimationMode(UnityEngine.Object driver)
 {
     return(AnimationMode.Internal_InAnimationMode(driver));
 }
Beispiel #13
0
 public static bool InAnimationMode()
 {
     return(AnimationMode.Internal_InAnimationModeNoDriver());
 }
        private void DoPrefabButtons(PrefabType prefabType, GameObject go)
        {
            // @TODO: If/when we support multi-editing of prefab/model instances,
            // handle it here. Only show prefab bar if all are same type?
            if (!m_HasInstance)
            {
                return;
            }

            using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode))
            {
                EditorGUILayout.BeginHorizontal();

                // Prefab information
                GUIContent prefixLabel = targets.Length > 1 ? s_Styles.goTypeLabelMultiple : s_Styles.goTypeLabel[(int)prefabType];

                if (prefixLabel != null)
                {
                    EditorGUILayout.BeginHorizontal(GUILayout.Width(kIconSize + 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(prefixLabel, EditorStyles.whiteLabel, GUILayout.ExpandWidth(false));
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUILayout.Label(prefixLabel, GUILayout.ExpandWidth(false));
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (targets.Length > 1)
                {
                    GUILayout.Label("Instance Management Disabled", s_Styles.instanceManagementInfo);
                }
                else
                {
                    // Select prefab
                    if (prefabType != PrefabType.MissingPrefabInstance)
                    {
                        if (GUILayout.Button("Select", "MiniButtonLeft"))
                        {
                            Selection.activeObject = PrefabUtility.GetCorrespondingObjectFromSource(target);
                            EditorGUIUtility.PingObject(Selection.activeObject);
                        }
                    }

                    using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode()))
                    {
                        if (prefabType != PrefabType.MissingPrefabInstance)
                        {
                            // Revert this gameobject and components to prefab
                            if (GUILayout.Button("Revert", "MiniButtonMid"))
                            {
                                PrefabUtility.RevertPrefabInstanceWithUndo(go);

                                // case931300 - The selected gameobject might get destroyed by RevertPrefabInstance
                                if (go != null)
                                {
                                    CalculatePrefabStatus();
                                }

                                // This is necessary because Revert can potentially destroy game objects and components
                                // In that case the Editor classes would be destroyed but still be invoked. (case 837113)
                                GUIUtility.ExitGUI();
                            }

                            // Apply to prefab
                            if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                            {
                                GameObject rootUploadGameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go);

                                GUI.enabled = rootUploadGameObject != null && !AnimationMode.InAnimationMode();

                                if (GUILayout.Button("Apply", "MiniButtonRight"))
                                {
                                    UnityObject correspondingAssetObject = PrefabUtility.GetCorrespondingObjectFromSource(rootUploadGameObject);
                                    string      prefabAssetPath = AssetDatabase.GetAssetPath(correspondingAssetObject);
                                    bool        isRootFolder, isReadonly;
                                    bool        validPath = AssetDatabase.GetAssetFolderInfo(prefabAssetPath, out isRootFolder, out isReadonly);

                                    if (validPath && isReadonly)
                                    {
                                        string prefabName = FileUtil.GetLastPathNameComponent(FileUtil.GetPathWithoutExtension(prefabAssetPath));
                                        EditorUtility.DisplayDialog("Cannot apply changes", string.Format("Original prefab \"{0}\" is immutable.", prefabName), "Close");
                                    }
                                    else
                                    {
                                        bool editablePrefab = Provider.PromptAndCheckoutIfNeeded(
                                            new string[] { prefabAssetPath },
                                            "The version control requires you to check out the prefab before applying changes.");

                                        if (editablePrefab)
                                        {
                                            PrefabUtility.ReplacePrefabWithUndo(rootUploadGameObject);

                                            CalculatePrefabStatus();

                                            // This is necessary because ReplacePrefab can potentially destroy game objects and components
                                            // In that case the Editor classes would be destroyed but still be invoked. (case 468434)
                                            GUIUtility.ExitGUI();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Edit model prefab
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance)
                    {
                        if (GUILayout.Button("Open", "MiniButtonRight"))
                        {
                            AssetDatabase.OpenAsset(PrefabUtility.GetCorrespondingObjectFromSource(target));
                            GUIUtility.ExitGUI();
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }
Beispiel #15
0
        public void RotationField(bool disabled)
        {
            Transform t          = targets[0] as Transform;
            Vector3   localEuler = t.GetLocalEulerAngles(t.rotationOrder);

            if (
                m_OldEulerAngles.x != localEuler.x ||
                m_OldEulerAngles.y != localEuler.y ||
                m_OldEulerAngles.z != localEuler.z ||
                m_OldRotationOrder != t.rotationOrder
                )
            {
                m_EulerAngles      = t.GetLocalEulerAngles(t.rotationOrder);
                m_OldRotationOrder = t.rotationOrder;
            }

            var  targetRotationOrder    = t.rotationOrder;
            bool differentRotation      = false;
            bool differentRotationOrder = false;

            for (int i = 1; i < targets.Length; i++)
            {
                Transform otherTransform = (targets[i] as Transform);
                if (!differentRotation)
                {
                    Vector3 otherLocalEuler = otherTransform.GetLocalEulerAngles(otherTransform.rotationOrder);
                    differentRotation = (otherLocalEuler.x != localEuler.x || otherLocalEuler.y != localEuler.y || otherLocalEuler.z != localEuler.z);
                }

                differentRotationOrder |= otherTransform.rotationOrder != targetRotationOrder;
            }

            Rect       r     = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
            GUIContent label = EditorGUI.BeginProperty(r, rotationContent, m_Rotation);

            m_EulerFloats[0] = m_EulerAngles.x;
            m_EulerFloats[1] = m_EulerAngles.y;
            m_EulerFloats[2] = m_EulerAngles.z;

            EditorGUI.showMixedValue = differentRotation;

            EditorGUI.BeginChangeCheck();

            int    id            = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, r);
            string rotationLabel = "";

            if (AnimationMode.InAnimationMode() && t.rotationOrder != RotationOrder.OrderZXY)
            {
                if (differentRotationOrder)
                {
                    rotationLabel = "Mixed";
                }
                else
                {
                    rotationLabel = (t.rotationOrder).ToString();
                    rotationLabel = rotationLabel.Substring(rotationLabel.Length - 3);
                }

                label.text = label.text + " (" + rotationLabel + ")";
            }

            // Using MultiFieldPrefixLabel/MultiFloatField here instead of Vector3Field
            // so that the label and the float fields can be disabled separately,
            // similar to other property-driven controls
            // Using MultiFloatField instead of Vector3Field to avoid superfluous label
            // (which creates a focus target even when there's no content (Case 953241))
            r        = EditorGUI.MultiFieldPrefixLabel(r, id, label, 3);
            r.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.DisabledScope(disabled))
                EditorGUI.MultiFloatField(r, s_XYZLabels, m_EulerFloats);

            if (EditorGUI.EndChangeCheck())
            {
                m_EulerAngles = new Vector3(m_EulerFloats[0], m_EulerFloats[1], m_EulerFloats[2]);
                Undo.RecordObjects(targets, "Inspector");  // Generic undo title to be consistent with Position and Scale changes.
                foreach (Transform tr in targets)
                {
                    tr.SetLocalEulerAngles(m_EulerAngles, tr.rotationOrder);
                    if (tr.parent != null)
                    {
                        tr.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent.
                    }
                }
                m_Rotation.serializedObject.SetIsDifferentCacheDirty();
            }

            EditorGUI.showMixedValue = false;

            if (differentRotationOrder)
            {
                EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning);
            }

            EditorGUI.EndProperty();
        }
 static public bool InAnimationMode()
 {
     return(AnimationMode.InAnimationMode());
 }
        internal bool DrawInspector(Rect contentRect)
        {
            if (GameObjectInspector.s_styles == null)
            {
                GameObjectInspector.s_styles = new GameObjectInspector.Styles();
            }
            this.serializedObject.Update();
            GameObject target1 = this.target as GameObject;

            EditorGUIUtility.labelWidth = 52f;
            bool enabled1 = GUI.enabled;

            GUI.enabled = true;
            GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig);
            GUI.enabled = enabled1;
            float      width1     = contentRect.width;
            float      y          = contentRect.y;
            GUIContent guiContent = (GUIContent)null;
            PrefabType prefabType = PrefabType.None;

            if (this.m_AllOfSamePrefabType)
            {
                prefabType = PrefabUtility.GetPrefabType((UnityEngine.Object)target1);
                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), this.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 num1   = GameObjectInspector.s_styles.staticFieldToggleWidth + 15f;
            float width2 = (float)((double)width1 - 52.0 - (double)num1 - 5.0);

            EditorGUI.DelayedTextField(new Rect(52f, (float)(4.0 + (double)y + 1.0), width2, 16f), this.m_Name, GUIContent.none);
            Rect totalPosition = new Rect(width1 - num1, 4f + y, GameObjectInspector.s_styles.staticFieldToggleWidth, 16f);

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

            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(position1, "Static", target1.isStatic);

            if (flag)
            {
                current.type = type;
            }
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(this.targets, -1, flagValue);
                this.serializedObject.SetIsDifferentCacheDirty();
            }
            EditorGUI.EndProperty();
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues;
            int  changedFlags;
            bool changedToValue;

            EditorGUI.EnumMaskField(new Rect(totalPosition.x + GameObjectInspector.s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), (Enum)GameObjectUtility.GetStaticEditorFlags(target1), GameObjectInspector.s_styles.staticDropdown, out changedFlags, out changedToValue);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(this.targets, changedFlags, changedToValue);
                this.serializedObject.SetIsDifferentCacheDirty();
            }
            float num2 = 4f;
            float num3 = 4f;

            EditorGUIUtility.fieldWidth = (float)(((double)width1 - (double)num2 - 52.0 - (double)GameObjectInspector.s_styles.layerFieldWidth - (double)num3) / 2.0);
            string tag;

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

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

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

            if (EditorGUI.EndChangeCheck())
            {
                GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(this.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?");
                if (shouldIncludeChildren != GameObjectUtility.ShouldIncludeChildren.Cancel)
                {
                    this.m_Layer.intValue = layer;
                    this.SetLayer(layer, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
                }
            }
            EditorGUI.EndProperty();
            if (this.m_HasInstance && !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                float      width3    = (float)(((double)width1 - 52.0 - 5.0) / 3.0);
                Rect       position2 = new Rect((float)(52.0 + (double)width3 * 0.0), 44f + y, width3, 15f);
                Rect       position3 = new Rect((float)(52.0 + (double)width3 * 1.0), 44f + y, width3, 15f);
                Rect       position4 = new Rect((float)(52.0 + (double)width3 * 2.0), 44f + y, width3, 15f);
                Rect       position5 = new Rect(52f, 44f + y, width3 * 3f, 15f);
                GUIContent content   = this.targets.Length <= 1 ? GameObjectInspector.s_styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_styles.goTypeLabelMultiple;
                if (content != null)
                {
                    float x = GUI.skin.label.CalcSize(content).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, (float)((double)width1 - 52.0 - 5.0), 18f), content, EditorStyles.whiteLabel);
                        }
                        else
                        {
                            GUI.Label(new Rect((float)(52.0 - (double)x - 5.0), 44f + y, (float)((double)width1 - 52.0 - 5.0), 18f), content, EditorStyles.whiteLabel);
                        }
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUI.Label(new Rect((float)(52.0 - (double)x - 5.0), 44f + y, x, 18f), content);
                    }
                }
                if (this.targets.Length > 1)
                {
                    GUI.Label(position5, "Instance Management Disabled", GameObjectInspector.s_styles.instanceManagementInfo);
                }
                else
                {
                    if (prefabType != PrefabType.MissingPrefabInstance && GUI.Button(position2, "Select", (GUIStyle)"MiniButtonLeft"))
                    {
                        Selection.activeObject = PrefabUtility.GetPrefabParent(this.target);
                        EditorGUIUtility.PingObject(Selection.activeObject);
                    }
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) && GUI.Button(position3, "Revert", (GUIStyle)"MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo((UnityEngine.Object)target1, "Revert to prefab");
                        PrefabUtility.ReconnectToLastPrefab(target1);
                        PrefabUtility.RevertPrefabInstance(target1);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)target1, "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", (GUIStyle)"MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo((UnityEngine.Object)target1, "Revert Prefab Instance");
                        PrefabUtility.RevertPrefabInstance(target1);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)target1, "Revert prefab");
                        GUIUtility.ExitGUI();
                    }
                    if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GameObject prefabInstanceRoot = PrefabUtility.FindValidUploadPrefabInstanceRoot(target1);
                        GUI.enabled = (UnityEngine.Object)prefabInstanceRoot != (UnityEngine.Object)null && !AnimationMode.InAnimationMode();
                        if (GUI.Button(position4, "Apply", (GUIStyle)"MiniButtonRight"))
                        {
                            UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent((UnityEngine.Object)prefabInstanceRoot);
                            if (Provider.PromptAndCheckoutIfNeeded(new string[1] {
                                AssetDatabase.GetAssetPath(prefabParent)
                            }, "The version control requires you to check out the prefab before applying changes."))
                            {
                                PrefabUtility.ReplacePrefab(prefabInstanceRoot, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                                this.CalculatePrefabStatus();
                                EditorSceneManager.MarkSceneDirty(prefabInstanceRoot.scene);
                                GUIUtility.ExitGUI();
                            }
                        }
                    }
                    GUI.enabled = enabled2;
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", (GUIStyle)"MiniButtonRight"))
                    {
                        AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target));
                        GUIUtility.ExitGUI();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            this.serializedObject.ApplyModifiedProperties();
            return(true);
        }
 public static void StopAnimationMode()
 {
     AnimationMode.StopAnimationMode();
 }
Beispiel #19
0
 internal static void AddCandidate(EditorCurveBinding binding, PropertyModification modification, bool keepPrefabOverride)
 {
     AnimationMode.AddCandidate_Injected(ref binding, modification, keepPrefabOverride);
 }