Exemplo n.º 1
0
 //============================
 // Undo
 //============================
 public static void RecordObject(UnityObject target, string name)
 {
     if (target.IsNull())
     {
         return;
     }
     UnityUndo.RecordObject(target, name);
 }
Exemplo n.º 2
0
 public static void RegisterUndo(UnityObject[] targets, string name)
 {
                 #if UNITY_3_0 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
     UnityUndo.RegisterUndo(targets, name);
                 #else
     UnityUndo.RecordObjects(targets, name);
                 #endif
 }
Exemplo n.º 3
0
 public static void RecordObjects(UnityObject[] targets, string name)
 {
     if (targets.IsNull())
     {
         return;
     }
     UnityUndo.RecordObjects(targets, name);
 }
Exemplo n.º 4
0
 public static void RegisterSceneUndo(UnityObject target, string name)
 {
                 #if UNITY_3_0 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
     UnityUndo.RegisterSceneUndo(name);
                 #else
     UnityUndo.RegisterCompleteObjectUndo(target, name);
                 #endif
 }
Exemplo n.º 5
0
        public static SerializedPropertyTreeView.Column[] CreateEmissivesColumns(out string[] propNames)
        {
            SerializedPropertyTreeView.Column[] expr_07 = new SerializedPropertyTreeView.Column[4];
            int arg_9B_1 = 0;

            SerializedPropertyTreeView.Column column = new SerializedPropertyTreeView.Column();
            column.headerContent         = LightTableColumns.Styles.SelectObjects;
            column.headerTextAlignment   = TextAlignment.Left;
            column.sortedAscending       = true;
            column.sortingArrowAlignment = TextAlignment.Center;
            column.width                 = 20f;
            column.minWidth              = 20f;
            column.maxWidth              = 20f;
            column.autoResize            = false;
            column.allowToggleVisibility = true;
            column.propertyName          = "m_LightmapFlags";
            column.dependencyIndices     = null;
            column.compareDelegate       = null;
            column.drawDelegate          = delegate(Rect r, SerializedProperty prop, SerializedProperty[] dep)
            {
                if (GUI.Button(r, LightTableColumns.Styles.SelectObjectsButton, "label"))
                {
                    SearchableEditorWindow.SearchForReferencesToInstanceID(prop.serializedObject.targetObject.GetInstanceID());
                }
            };
            expr_07[arg_9B_1] = column;
            expr_07[1]        = new SerializedPropertyTreeView.Column
            {
                headerContent         = LightTableColumns.Styles.Name,
                headerTextAlignment   = TextAlignment.Left,
                sortedAscending       = true,
                sortingArrowAlignment = TextAlignment.Center,
                width                 = 200f,
                minWidth              = 100f,
                autoResize            = false,
                allowToggleVisibility = true,
                propertyName          = null,
                dependencyIndices     = null,
                compareDelegate       = SerializedPropertyTreeView.DefaultDelegates.s_CompareName,
                drawDelegate          = SerializedPropertyTreeView.DefaultDelegates.s_DrawName,
                filter                = new SerializedPropertyFilters.Name()
            };
            int arg_1A6_1 = 2;

            column = new SerializedPropertyTreeView.Column();
            column.headerContent         = LightTableColumns.Styles.GlobalIllumination;
            column.headerTextAlignment   = TextAlignment.Left;
            column.sortedAscending       = true;
            column.sortingArrowAlignment = TextAlignment.Center;
            column.width                 = 120f;
            column.minWidth              = 70f;
            column.autoResize            = false;
            column.allowToggleVisibility = true;
            column.propertyName          = "m_LightmapFlags";
            column.dependencyIndices     = null;
            column.compareDelegate       = SerializedPropertyTreeView.DefaultDelegates.s_CompareInt;
            column.drawDelegate          = delegate(Rect r, SerializedProperty prop, SerializedProperty[] dep)
            {
                if (prop.serializedObject.targetObject.GetType().Equals(typeof(Material)))
                {
                    using (new EditorGUI.DisabledScope(!LightTableColumns.IsEditable(prop.serializedObject.targetObject)))
                    {
                        MaterialGlobalIlluminationFlags materialGlobalIlluminationFlags = ((prop.intValue & 2) == 0) ? MaterialGlobalIlluminationFlags.RealtimeEmissive : MaterialGlobalIlluminationFlags.BakedEmissive;
                        int[] optionValues = new int[]
                        {
                            1,
                            2
                        };
                        EditorGUI.BeginChangeCheck();
                        materialGlobalIlluminationFlags = (MaterialGlobalIlluminationFlags)EditorGUI.IntPopup(r, (int)materialGlobalIlluminationFlags, LightTableColumns.Styles.LightmapEmissiveStrings, optionValues);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Material material = (Material)prop.serializedObject.targetObject;
                            Undo.RecordObjects(new Material[]
                            {
                                material
                            }, "Modify GI Settings of " + material.name);
                            material.globalIlluminationFlags = materialGlobalIlluminationFlags;
                            prop.serializedObject.Update();
                        }
                    }
                }
            };
            expr_07[arg_1A6_1] = column;
            int arg_26F_1 = 3;

            column = new SerializedPropertyTreeView.Column();
            column.headerContent         = LightTableColumns.Styles.Color;
            column.headerTextAlignment   = TextAlignment.Left;
            column.sortedAscending       = true;
            column.sortingArrowAlignment = TextAlignment.Center;
            column.width                 = 70f;
            column.minWidth              = 40f;
            column.autoResize            = false;
            column.allowToggleVisibility = true;
            column.propertyName          = "m_Shader";
            column.dependencyIndices     = null;
            column.compareDelegate       = delegate(SerializedProperty lhs, SerializedProperty rhs)
            {
                float num;
                float num2;
                float num3;
                Color.RGBToHSV(((Material)lhs.serializedObject.targetObject).GetColor("_EmissionColor"), out num, out num2, out num3);
                float num4;
                float num5;
                float value;
                Color.RGBToHSV(((Material)rhs.serializedObject.targetObject).GetColor("_EmissionColor"), out num4, out num5, out value);
                return(num3.CompareTo(value));
            };
            column.drawDelegate = delegate(Rect r, SerializedProperty prop, SerializedProperty[] dep)
            {
                if (prop.serializedObject.targetObject.GetType().Equals(typeof(Material)))
                {
                    using (new EditorGUI.DisabledScope(!LightTableColumns.IsEditable(prop.serializedObject.targetObject)))
                    {
                        Material material = (Material)prop.serializedObject.targetObject;
                        Color    color    = material.GetColor("_EmissionColor");
                        EditorGUI.BeginChangeCheck();
                        Color value = EditorGUI.ColorField(r, GUIContent.Temp(""), color, true, false, true);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(new Material[]
                            {
                                material
                            }, "Modify Emission Color of " + material.name);
                            material.SetColor("_EmissionColor", value);
                        }
                    }
                }
            };
            column.copyDelegate = delegate(SerializedProperty target, SerializedProperty source)
            {
                Material material  = (Material)source.serializedObject.targetObject;
                Color    color     = material.GetColor("_EmissionColor");
                Material material2 = (Material)target.serializedObject.targetObject;
                material2.SetColor("_EmissionColor", color);
            };
            expr_07[arg_26F_1] = column;
            SerializedPropertyTreeView.Column[] columns = expr_07;
            return(LightTableColumns.FinalizeColumns(columns, out propNames));
        }
Exemplo n.º 6
0
 private static void SetParent(Transform go, Transform parent)
 {
     Undo.SetTransformParent(go, parent, kCutAndPaste);
     go.SetAsLastSibling();
 }
        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   vector2    = transform2.GetLocalEulerAngles(transform2.rotationOrder);
                flag  |= ((vector2.x != localEulerAngles.x) || (vector2.y != localEulerAngles.y)) || !(vector2.z == localEulerAngles.z);
                flag2 |= transform2.rotationOrder != transform.rotationOrder;
            }
            Rect       totalPosition = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (!EditorGUIUtility.wideMode ? ((float)2) : ((float)1)), new GUILayoutOption[0]);
            GUIContent label         = EditorGUI.BeginProperty(totalPosition, this.rotationContent, this.m_Rotation);

            EditorGUI.showMixedValue = flag;
            EditorGUI.BeginChangeCheck();
            int    id  = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, totalPosition);
            string str = "";

            if (UnityEditor.AnimationMode.InAnimationMode() && (transform.rotationOrder != RotationOrder.OrderZXY))
            {
                if (flag2)
                {
                    str = "Mixed";
                }
                else
                {
                    str = transform.rotationOrder.ToString();
                    str = str.Substring(str.Length - 3);
                }
                label.text = label.text + " (" + str + ")";
            }
            totalPosition        = EditorGUI.MultiFieldPrefixLabel(totalPosition, id, label, 3);
            totalPosition.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.DisabledScope(disabled))
            {
                this.m_EulerAngles = EditorGUI.Vector3Field(totalPosition, GUIContent.none, this.m_EulerAngles);
            }
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObjects(this.targets, "Inspector");
                foreach (Transform transform3 in this.targets)
                {
                    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();
        }
Exemplo n.º 8
0
 public static void PasteToStateMachineFromPasteboard(AnimatorStateMachine sm, AnimatorController controller, int layerIndex, Vector3 position)
 {
     Undo.RegisterCompleteObjectUndo(sm, "Paste to StateMachine");
     PasteToStateMachineFromPasteboardInternal(sm, controller, layerIndex, position);
 }
Exemplo n.º 9
0
 public static void PasteToStateMachineTransitionParametersFromPasteboard(UnityEngine.Object transition, AnimatorController controller, bool conditions, bool parameters)
 {
     Undo.RegisterCompleteObjectUndo(transition, "Paste to Transition");
     PasteToStateMachineTransitionParametersFromPasteboardInternal(transition, controller, conditions, parameters);
 }
        private void CollisionPlanesSceneGUI()
        {
            if (m_ScenePlanes.Count == 0)
            {
                return;
            }

            Event evt = Event.current;

            Color origCol = Handles.color;
            Color col     = new Color(1, 1, 1, 0.5F);

            for (int i = 0; i < m_ScenePlanes.Count; ++i)
            {
                if (m_ScenePlanes[i] == null)
                {
                    continue;
                }

                Transform  transform          = m_ScenePlanes[i];
                Vector3    position           = transform.position;
                Quaternion rotation           = transform.rotation;
                Vector3    right              = rotation * Vector3.right;
                Vector3    up                 = rotation * Vector3.up;
                Vector3    forward            = rotation * Vector3.forward;
                bool       isPlayingAndStatic = EditorApplication.isPlaying && transform.gameObject.isStatic;
                if (editingPlanes)
                {
                    if (Object.ReferenceEquals(s_SelectedTransform, transform))
                    {
                        EditorGUI.BeginChangeCheck();
                        var newPosition = transform.position;
                        var newRotation = transform.rotation;

                        using (new EditorGUI.DisabledScope(isPlayingAndStatic))
                        {
                            if (isPlayingAndStatic)
                            {
                                Handles.ShowStaticLabel(position);
                            }
                            if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove)
                            {
                                newPosition = Handles.PositionHandle(position, rotation);
                            }
                            else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate)
                            {
                                newRotation = Handles.RotationHandle(rotation, position);
                            }
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(transform, "Modified Collision Plane Transform");
                            transform.position = newPosition;
                            transform.rotation = newRotation;
                            ParticleSystemEditorUtils.PerformCompleteResimulation();
                        }
                    }
                    else
                    {
                        float handleSize = HandleUtility.GetHandleSize(position) * 0.6f;

                        EventType oldEventType = evt.type;

                        // we want ignored mouse up events to check for dragging off of scene view
                        if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp)
                        {
                            oldEventType = evt.rawType;
                        }

                        Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.RectangleHandleCap);

                        // Detect selected plane (similar to TreeEditor)
                        if (oldEventType == EventType.MouseDown && evt.type == EventType.Used)
                        {
                            s_SelectedTransform   = transform;
                            oldEventType          = EventType.Used;
                            GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514)
                        }
                    }
                }

                Handles.color = col;
                Color color = Handles.s_ColliderHandleColor * 0.9f;
                if (isPlayingAndStatic)
                {
                    color.a *= 0.2f;
                }

                if (m_PlaneVisualizationType == PlaneVizType.Grid)
                {
                    DrawGrid(position, right, forward, up, color);
                }
                else
                {
                    DrawSolidPlane(position, rotation, color, Color.yellow);
                }
            }

            Handles.color = origCol;
        }
Exemplo n.º 11
0
 void SetAsStartupSnapshot(AudioMixerSnapshotController snapshot)
 {
     Undo.RecordObject(m_Controller, "Set start snapshot");
     m_Controller.startSnapshot = snapshot;
 }
Exemplo n.º 12
0
        public override void OnSelectionInspectorGUI()
        {
            BoundsInt selection = GridSelection.position;
            Tilemap   tilemap   = GridSelection.target.GetComponent <Tilemap>();

            int cellCount = selection.size.x * selection.size.y * selection.size.z;

            if (tilemap != null && cellCount > 0)
            {
                base.OnSelectionInspectorGUI();
                GUILayout.Space(10f);

                if (m_SelectionTiles == null || m_SelectionTiles.Length != cellCount)
                {
                    m_SelectionTiles         = new TileBase[cellCount];
                    m_SelectionColors        = new Color[cellCount];
                    m_SelectionMatrices      = new Matrix4x4[cellCount];
                    m_SelectionFlagsArray    = new TileFlags[cellCount];
                    m_SelectionSprites       = new Sprite[cellCount];
                    m_SelectionColliderTypes = new Tile.ColliderType[cellCount];
                }

                int index = 0;
                foreach (var p in selection.allPositionsWithin)
                {
                    m_SelectionTiles[index]         = tilemap.GetTile(p);
                    m_SelectionColors[index]        = tilemap.GetColor(p);
                    m_SelectionMatrices[index]      = tilemap.GetTransformMatrix(p);
                    m_SelectionFlagsArray[index]    = tilemap.GetTileFlags(p);
                    m_SelectionSprites[index]       = tilemap.GetSprite(p);
                    m_SelectionColliderTypes[index] = tilemap.GetColliderType(p);
                    index++;
                }

                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = m_SelectionTiles.Any(tile => tile != m_SelectionTiles.First());
                var      position = new Vector3Int(selection.xMin, selection.yMin, selection.zMin);
                TileBase newTile  = EditorGUILayout.ObjectField(Styles.tileLabel, tilemap.GetTile(position), typeof(TileBase), false) as TileBase;
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(tilemap, "Edit Tilemap");
                    foreach (var p in selection.allPositionsWithin)
                    {
                        tilemap.SetTile(p, newTile);
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = m_SelectionSprites.Any(sprite => sprite != m_SelectionSprites.First());
                    EditorGUILayout.ObjectField(Styles.spriteLabel, m_SelectionSprites[0], typeof(Sprite), false, GUILayout.Height(EditorGUI.kSingleLineHeight));
                }

                bool colorFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockColor) == (m_SelectionFlagsArray.First() & TileFlags.LockColor));
                using (new EditorGUI.DisabledScope(!colorFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0))
                {
                    EditorGUI.showMixedValue = m_SelectionColors.Any(color => color != m_SelectionColors.First());
                    EditorGUI.BeginChangeCheck();
                    Color newColor = EditorGUILayout.ColorField(Styles.colorLabel, m_SelectionColors[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(tilemap, "Edit Tilemap");
                        foreach (var p in selection.allPositionsWithin)
                        {
                            tilemap.SetColor(p, newColor);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = m_SelectionColliderTypes.Any(colliderType => colliderType != m_SelectionColliderTypes.First());
                    EditorGUILayout.EnumPopup(Styles.colliderTypeLabel, m_SelectionColliderTypes[0]);
                }

                bool transformFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockTransform) == (m_SelectionFlagsArray.First() & TileFlags.LockTransform));
                using (new EditorGUI.DisabledScope(!transformFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0))
                {
                    EditorGUI.showMixedValue = m_SelectionMatrices.Any(matrix => matrix != m_SelectionMatrices.First());
                    EditorGUI.BeginChangeCheck();
                    Matrix4x4 newTransformMatrix = TileEditor.TransformMatrixOnGUI(m_SelectionMatrices[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(tilemap, "Edit Tilemap");
                        foreach (var p in selection.allPositionsWithin)
                        {
                            tilemap.SetTransformMatrix(p, newTransformMatrix);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = !colorFlagsAllEqual;
                    EditorGUILayout.Toggle(Styles.lockColorLabel, (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0);
                    EditorGUI.showMixedValue = !transformFlagsAllEqual;
                    EditorGUILayout.Toggle(Styles.lockTransformLabel, (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0);
                }

                EditorGUI.showMixedValue = false;
            }
        }
Exemplo n.º 13
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);

            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();
        }
Exemplo n.º 14
0
        protected void PropertiesGUI()
        {
            bool flag = false;

            this.HeaderGUI(string.Empty, "Additional Settings");
            GUILayout.BeginVertical(styles.box, new GUILayoutOption[0]);
            this.m_ArmTwistFactor = EditorGUI.Slider(GetSettingsRect(), styles.armTwist, this.m_ArmTwistFactor, 0f, 1f);
            if (this.m_ArmTwistProperty.floatValue != this.m_ArmTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Upper arm twist");
                this.m_ArmTwistProperty.floatValue = this.m_ArmTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.UpperArmTwist, this.m_ArmTwistFactor);
                flag = true;
            }
            this.m_ForeArmTwistFactor = EditorGUI.Slider(GetSettingsRect(), styles.foreArmTwist, this.m_ForeArmTwistFactor, 0f, 1f);
            if (this.m_ForeArmTwistProperty.floatValue != this.m_ForeArmTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Lower arm twist");
                this.m_ForeArmTwistProperty.floatValue = this.m_ForeArmTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.LowerArmTwist, this.m_ForeArmTwistFactor);
                flag = true;
            }
            this.m_UpperLegTwistFactor = EditorGUI.Slider(GetSettingsRect(), styles.upperLegTwist, this.m_UpperLegTwistFactor, 0f, 1f);
            if (this.m_UpperLegTwistProperty.floatValue != this.m_UpperLegTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Upper leg twist");
                this.m_UpperLegTwistProperty.floatValue = this.m_UpperLegTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.UpperLegTwist, this.m_UpperLegTwistFactor);
                flag = true;
            }
            this.m_LegTwistFactor = EditorGUI.Slider(GetSettingsRect(), styles.legTwist, this.m_LegTwistFactor, 0f, 1f);
            if (this.m_LegTwistProperty.floatValue != this.m_LegTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Lower leg twist");
                this.m_LegTwistProperty.floatValue = this.m_LegTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.LowerLegTwist, this.m_LegTwistFactor);
                flag = true;
            }
            this.m_ArmStretchFactor = EditorGUI.Slider(GetSettingsRect(), styles.armStretch, this.m_ArmStretchFactor, 0f, 1f);
            if (this.m_ArmStretchProperty.floatValue != this.m_ArmStretchFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Arm stretch");
                this.m_ArmStretchProperty.floatValue = this.m_ArmStretchFactor;
                this.UpdateAvatarParameter(HumanParameter.ArmStretch, this.m_ArmStretchFactor);
                flag = true;
            }
            this.m_LegStretchFactor = EditorGUI.Slider(GetSettingsRect(), styles.legStretch, this.m_LegStretchFactor, 0f, 1f);
            if (this.m_LegStretchProperty.floatValue != this.m_LegStretchFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Leg stretch");
                this.m_LegStretchProperty.floatValue = this.m_LegStretchFactor;
                this.UpdateAvatarParameter(HumanParameter.LegStretch, this.m_LegStretchFactor);
                flag = true;
            }
            this.m_FeetSpacingFactor = EditorGUI.Slider(GetSettingsRect(), styles.feetSpacing, this.m_FeetSpacingFactor, 0f, 1f);
            if (this.m_FeetSpacingProperty.floatValue != this.m_FeetSpacingFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Feet spacing");
                this.m_FeetSpacingProperty.floatValue = this.m_FeetSpacingFactor;
                this.UpdateAvatarParameter(HumanParameter.FeetSpacing, this.m_FeetSpacingFactor);
                flag = true;
            }
            this.m_HasTranslationDoF = EditorGUI.Toggle(GetSettingsRect(), styles.hasTranslationDoF, this.m_HasTranslationDoF);
            if (this.m_HasTranslationDoFProperty.boolValue != this.m_HasTranslationDoF)
            {
                Undo.RegisterCompleteObjectUndo(this, "Translation DoF");
                this.m_HasTranslationDoFProperty.boolValue = this.m_HasTranslationDoF;
            }
            GUILayout.EndVertical();
            if (flag)
            {
                this.WritePose();
            }
        }
Exemplo n.º 15
0
        protected void MuscleGUI()
        {
            bool flag = false;

            this.HeaderGUI("Preview", "Per-Muscle Settings");
            GUILayout.BeginVertical(styles.box, new GUILayoutOption[0]);
            for (int i = 0; i < this.m_MuscleBodyGroupToggle.Length; i++)
            {
                Rect settingsRect = GetSettingsRect(GUILayoutUtility.GetRect((float)10f, (float)16f));
                this.m_MuscleBodyGroupToggle[i] = GUI.Toggle(settingsRect, this.m_MuscleBodyGroupToggle[i], styles.muscleBodyGroup[i], EditorStyles.foldout);
                if (this.m_MuscleBodyGroupToggle[i])
                {
                    for (int j = 0; j < this.m_Muscles[i].Length; j++)
                    {
                        int index = this.m_Muscles[i][j];
                        if (((index != -1) && (this.m_MuscleMin[index] != null)) && (this.m_MuscleMax[index] != null))
                        {
                            bool flag2          = this.m_MuscleToggle[index];
                            Rect wholeWidthRect = GUILayoutUtility.GetRect(10f, !flag2 ? 16f : 32f);
                            settingsRect               = GetSettingsRect(wholeWidthRect);
                            settingsRect.xMin         += 15f;
                            settingsRect.height        = 16f;
                            this.m_MuscleToggle[index] = GUI.Toggle(settingsRect, this.m_MuscleToggle[index], this.m_MuscleName[index], EditorStyles.foldout);
                            float num5 = PreviewSlider(wholeWidthRect, this.m_MuscleValue[index]);
                            if (this.m_MuscleValue[index] != num5)
                            {
                                Undo.RegisterCompleteObjectUndo(this, "Muscle preview");
                                this.m_FocusedMuscle      = index;
                                this.m_MuscleValue[index] = num5;
                                flag |= base.gameObject != null;
                            }
                            if (flag2)
                            {
                                bool flag3 = false;
                                settingsRect.xMin += 15f;
                                settingsRect.y    += 16f;
                                Rect position = settingsRect;
                                if (settingsRect.width > 160f)
                                {
                                    Rect rect4 = settingsRect;
                                    rect4.width = 38f;
                                    EditorGUI.BeginChangeCheck();
                                    this.m_MuscleMinEdit[index] = EditorGUI.FloatField(rect4, this.m_MuscleMinEdit[index]);
                                    flag3  |= EditorGUI.EndChangeCheck();
                                    rect4.x = settingsRect.xMax - 38f;
                                    EditorGUI.BeginChangeCheck();
                                    this.m_MuscleMaxEdit[index] = EditorGUI.FloatField(rect4, this.m_MuscleMaxEdit[index]);
                                    flag3         |= EditorGUI.EndChangeCheck();
                                    position.xMin += 43f;
                                    position.xMax -= 43f;
                                }
                                EditorGUI.BeginChangeCheck();
                                EditorGUI.MinMaxSlider(position, ref this.m_MuscleMinEdit[index], ref this.m_MuscleMaxEdit[index], -180f, 180f);
                                if (flag3 | EditorGUI.EndChangeCheck())
                                {
                                    this.m_MuscleMinEdit[index] = Mathf.Clamp(this.m_MuscleMinEdit[index], -180f, 0f);
                                    this.m_MuscleMaxEdit[index] = Mathf.Clamp(this.m_MuscleMaxEdit[index], 0f, 180f);
                                    flag |= this.UpdateMuscle(index, this.m_MuscleMinEdit[index], this.m_MuscleMaxEdit[index]);
                                }
                            }
                        }
                    }
                }
            }
            GUILayout.EndVertical();
            if (flag)
            {
                this.WritePose();
            }
        }
        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)
                {
                    if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene))
                    {
                        dragObject      = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                        dragObject.name = go.name;
                    }
                    else
                    {
                        // Instatiate as regular GameObject in Play Mode so runtime logic
                        // won't run into restrictions on restructuring Prefab instances.
                        dragObject = Instantiate(prefabAssetRoot);
                        SceneManager.MoveGameObjectToScene(dragObject, destinationScene);
                    }
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                }

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

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Vector3 point, normal;

                if (HandleUtility.PlaceObject(evt.mousePosition, out point, out normal))
                {
                    float offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(point + (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.currentStage;
                if (stage is PrefabStage)
                {
                    var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.assetPath);
                    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();
                }
                if (!Application.IsPlaying(dragObject))
                {
                    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;
            }
        }
Exemplo n.º 17
0
        public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, Object[] objectReferences, string[] paths, ShowFileDialogDelegate saveFileDialog)
        {
            if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited)
            {
                return;
            }

            // Return if any of the dragged objects are null, e.g. a MonoBehaviour without a managed instance
            if (objectReferences.Any(obj => obj == null))
            {
                return;
            }

            // Regardless of EditorBehaviorMode or SceneView mode we don't handle if texture is dragged over a GO with renderer
            if (objectReferences.Length == 1 && objectReferences[0] as UnityTexture2D != null)
            {
                GameObject go = HandleUtility.PickGameObject(evt.mousePosition, true);
                if (go != null)
                {
                    var renderer = go.GetComponent <Renderer>();
                    if (renderer != null && !(renderer is SpriteRenderer))
                    {
                        // There is an object where the cursor is
                        // and we are dragging a texture. Most likely user wants to
                        // assign texture to the GO
                        // Case 730444: Proceed only if the go has a renderer
                        CleanUp(true);
                        return;
                    }
                }
            }

            switch (evt.type)
            {
            case (EventType.DragUpdated):
                DragType newDragType = evt.alt ? DragType.CreateMultiple : DragType.SpriteAnimation;

                if (s_DragType != newDragType || s_SceneDragObjects == null)               // Either this is first time we are here OR evt.alt changed during drag
                {
                    if (!ExistingAssets(objectReferences) && PathsAreValidTextures(paths)) // External drag with images that are not in the project
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        s_SceneDragObjects     = new List <Object>();
                        s_DragType             = newDragType;
                    }
                    else     // Internal drag with assets from project
                    {
                        List <Sprite> assets = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);

                        if (assets.Count == 0)
                        {
                            return;
                        }

                        if (s_DragType != DragType.NotInitialized)     // evt.alt changed during drag, so we need to cleanup and start over
                        {
                            CleanUp(true);
                        }

                        s_DragType = newDragType;
                        CreateSceneDragObjects(assets, sceneView);
                        IgnoreForRaycasts(s_SceneDragObjects);
                    }
                }

                PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                evt.Use();
                break;

            case (EventType.DragPerform):
                List <Sprite> sprites = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);

                if (sprites.Count > 0 && s_SceneDragObjects != null)
                {
                    // Store current undoIndex to undo all operations done if any part of sprite creation fails
                    int undoIndex = Undo.GetCurrentGroup();

                    // For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets
                    if (s_SceneDragObjects.Count == 0)
                    {
                        CreateSceneDragObjects(sprites, sceneView);
                        PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);
                    }

                    foreach (GameObject dragGO in s_SceneDragObjects)
                    {
                        dragGO.hideFlags = HideFlags.None;

                        // When in e.g Prefab Mode ensure to reparent dragged objects under the prefab root
                        if (sceneView.customParentForDraggedObjects != null)
                        {
                            dragGO.transform.SetParent(sceneView.customParentForDraggedObjects, true);
                        }

                        Undo.RegisterCreatedObjectUndo(dragGO, "Create Sprite");
                        EditorUtility.SetDirty(dragGO);
                    }

                    bool createGameObject = true;
                    if (s_DragType == DragType.SpriteAnimation && sprites.Count > 1)
                    {
                        createGameObject = AddAnimationToGO((GameObject)s_SceneDragObjects[0], sprites.ToArray(), saveFileDialog);
                    }

                    if (createGameObject)
                    {
                        Selection.objects = s_SceneDragObjects.ToArray();
                    }
                    else
                    {
                        // Revert all Create Sprite actions if animation failed to be created or was cancelled
                        Undo.RevertAllDownToGroup(undoIndex);
                    }
                    CleanUp(!createGameObject);
                    evt.Use();
                }
                break;

            case EventType.DragExited:
                if (s_SceneDragObjects != null)
                {
                    CleanUp(true);
                    evt.Use();
                }
                break;
            }
        }
Exemplo n.º 18
0
        public override void OnInspectorGUI()
        {
            bool     flag     = base.targets.Length > 1;
            Animator animator = base.target as Animator;

            base.serializedObject.UpdateIfDirtyOrScript();
            this.UpdateShowOptions();
            EditorGUI.BeginChangeCheck();
            RuntimeAnimatorController runtimeAnimatorController = EditorGUILayout.ObjectField("Controller", animator.runtimeAnimatorController, typeof(RuntimeAnimatorController), false, new GUILayoutOption[0]) as RuntimeAnimatorController;

            if (EditorGUI.EndChangeCheck())
            {
                UnityEngine.Object[] targets = base.targets;
                for (int i = 0; i < targets.Length; i++)
                {
                    Animator animator2 = (Animator)targets[i];
                    Undo.RecordObject(animator2, "Changed AnimatorController");
                    animator2.runtimeAnimatorController = runtimeAnimatorController;
                }
                AnimationWindowUtility.ControllerChanged();
            }
            EditorGUILayout.PropertyField(this.m_Avatar, new GUILayoutOption[0]);
            if (animator.supportsOnAnimatorMove && !flag)
            {
                EditorGUILayout.LabelField("Apply Root Motion", "Handled by Script", new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.PropertyField(this.m_ApplyRootMotion, AnimatorInspector.styles.applyRootMotion, new GUILayoutOption[0]);
                if (Event.current.type == EventType.Layout)
                {
                    this.m_IsRootPositionOrRotationControlledByCurves = animator.isRootPositionOrRotationControlledByCurves;
                }
                if (!this.m_ApplyRootMotion.boolValue && this.m_IsRootPositionOrRotationControlledByCurves)
                {
                    EditorGUILayout.HelpBox("Root position or rotation are controlled by curves", MessageType.Info, true);
                }
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_UpdateMode, AnimatorInspector.styles.updateMode, new GUILayoutOption[0]);
            bool flag2 = EditorGUI.EndChangeCheck();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_CullingMode, AnimatorInspector.styles.cullingMode, new GUILayoutOption[0]);
            bool flag3 = EditorGUI.EndChangeCheck();

            if (!flag)
            {
                EditorGUILayout.HelpBox(animator.GetStats(), MessageType.Info, true);
            }
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowWarningMessage.faded))
            {
                EditorGUILayout.HelpBox(this.WarningMessage, MessageType.Warning, true);
            }
            EditorGUILayout.EndFadeGroup();
            base.serializedObject.ApplyModifiedProperties();
            UnityEngine.Object[] targets2 = base.targets;
            for (int j = 0; j < targets2.Length; j++)
            {
                Animator animator3 = (Animator)targets2[j];
                if (flag3)
                {
                    animator3.OnCullingModeChanged();
                }
                if (flag2)
                {
                    animator3.OnUpdateModeChanged();
                }
            }
        }
Exemplo n.º 19
0
 public static void RegisterCreatedObjectUndo(UnityObject target, string name)
 {
     UnityUndo.RegisterCreatedObjectUndo(target, name);
 }
Exemplo n.º 20
0
        internal void Show(UnityEngine.Object obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List <int> allowedInstanceIDs)
        {
            this.m_AllowSceneObjects = allowSceneObjects;
            this.m_IsShowingAssets   = true;
            this.m_AllowedIDs        = allowedInstanceIDs;
            string text = "";

            if (property != null)
            {
                text = property.objectReferenceTypeString;
                obj  = property.objectReferenceValue;
                this.m_ObjectBeingEdited = property.serializedObject.targetObject;
                if (this.m_ObjectBeingEdited != null && EditorUtility.IsPersistent(this.m_ObjectBeingEdited))
                {
                    this.m_AllowSceneObjects = false;
                }
            }
            else if (requiredType != null)
            {
                text = requiredType.Name;
            }
            if (this.m_AllowSceneObjects)
            {
                if (obj != null)
                {
                    if (typeof(Component).IsAssignableFrom(obj.GetType()))
                    {
                        obj = ((Component)obj).gameObject;
                    }
                    this.m_IsShowingAssets = (EditorUtility.IsPersistent(obj) || ObjectSelector.GuessIfUserIsLookingForAnAsset(text, false));
                }
                else
                {
                    this.m_IsShowingAssets = ObjectSelector.GuessIfUserIsLookingForAnAsset(text, true);
                }
            }
            else
            {
                this.m_IsShowingAssets = true;
            }
            this.m_DelegateView      = GUIView.current;
            this.m_RequiredType      = text;
            this.m_SearchFilter      = "";
            this.m_OriginalSelection = obj;
            this.m_ModalUndoGroup    = Undo.GetCurrentGroup();
            ContainerWindow.SetFreezeDisplay(true);
            base.ShowWithMode(ShowMode.AuxWindow);
            base.titleContent = new GUIContent("Select " + text);
            Rect position = this.m_Parent.window.position;

            position.width  = EditorPrefs.GetFloat("ObjectSelectorWidth", 200f);
            position.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390f);
            base.position   = position;
            base.minSize    = new Vector2(200f, 335f);
            base.maxSize    = new Vector2(10000f, 10000f);
            this.SetupPreview();
            base.Focus();
            ContainerWindow.SetFreezeDisplay(false);
            this.m_FocusSearchFilter = true;
            this.m_Parent.AddToAuxWindowList();
            int num = (!(obj != null)) ? 0 : obj.GetInstanceID();

            if (property != null && property.hasMultipleDifferentValues)
            {
                num = 0;
            }
            if (ObjectSelector.ShouldTreeViewBeUsed(text))
            {
                this.m_ObjectTreeWithSearch.Init(base.position, this, new UnityAction <ObjectTreeForSelector.TreeSelectorData>(this.CreateAndSetTreeView), new UnityAction <TreeViewItem>(this.TreeViewSelection), new UnityAction(this.ItemWasDoubleClicked), num, 0);
            }
            else
            {
                this.InitIfNeeded();
                this.m_ListArea.InitSelection(new int[]
                {
                    num
                });
                if (num != 0)
                {
                    this.m_ListArea.Frame(num, true, false);
                }
            }
        }
Exemplo n.º 21
0
        private void DoTimeline()
        {
            if (!m_ValidTransition)
            {
                return;
            }
            // get local durations
            float srcStateDuration   = (m_LeftStateTimeB - m_LeftStateTimeA) / (m_LeftStateWeightB - m_LeftStateWeightA);
            float dstStateDuration   = (m_RightStateTimeB - m_RightStateTimeA) / (m_RightStateWeightB - m_RightStateWeightA);
            float transitionDuration = m_Transition.duration * (m_RefTransition.hasFixedDuration ? 1.0f : srcStateDuration);

            // Set the timeline values
            m_Timeline.SrcStartTime = 0f;
            m_Timeline.SrcStopTime  = srcStateDuration;
            m_Timeline.SrcName      = m_RefSrcState.name;
            m_Timeline.HasExitTime  = m_RefTransition.hasExitTime;

            m_Timeline.srcLoop = m_SrcMotion ? m_SrcMotion.isLooping : false;
            m_Timeline.dstLoop = m_DstMotion ? m_DstMotion.isLooping : false;

            m_Timeline.TransitionStartTime = m_RefTransition.exitTime * srcStateDuration;
            m_Timeline.TransitionStopTime  = m_Timeline.TransitionStartTime + transitionDuration;

            m_Timeline.Time = m_AvatarPreview.timeControl.currentTime;

            m_Timeline.DstStartTime = m_Timeline.TransitionStartTime - m_RefTransition.offset * dstStateDuration;
            m_Timeline.DstStopTime  = m_Timeline.DstStartTime + dstStateDuration;

            m_Timeline.SampleStopTime = m_AvatarPreview.timeControl.stopTime;

            if (m_Timeline.TransitionStopTime == Mathf.Infinity)
            {
                m_Timeline.TransitionStopTime = Mathf.Min(m_Timeline.DstStopTime, m_Timeline.SrcStopTime);
            }


            m_Timeline.DstName = m_RefDstState.name;

            m_Timeline.SrcPivotList = m_SrcPivotList;
            m_Timeline.DstPivotList = m_DstPivotList;

            // Do the timeline
            Rect previewRect = EditorGUILayout.GetControlRect(false, 150, EditorStyles.label);

            EditorGUI.BeginChangeCheck();

            bool changedData = m_Timeline.DoTimeline(previewRect);

            if (EditorGUI.EndChangeCheck())
            {
                if (changedData)
                {
                    Undo.RegisterCompleteObjectUndo(m_RefTransition, "Edit Transition");
                    m_RefTransition.exitTime = m_Timeline.TransitionStartTime / m_Timeline.SrcDuration;
                    m_RefTransition.duration = m_Timeline.TransitionDuration / (m_RefTransition.hasFixedDuration ? 1.0f : m_Timeline.SrcDuration);
                    m_RefTransition.offset   = (m_Timeline.TransitionStartTime - m_Timeline.DstStartTime) / m_Timeline.DstDuration;
                }

                m_AvatarPreview.timeControl.nextCurrentTime = Mathf.Clamp(m_Timeline.Time, 0, m_AvatarPreview.timeControl.stopTime);
            }
        }
Exemplo n.º 22
0
        internal void Show(UnityObject obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List <int> allowedInstanceIDs, Action <UnityObject> onObjectSelectorClosed, Action <UnityObject> onObjectSelectedUpdated)
        {
            m_ObjectSelectorReceiver = null;
            m_AllowSceneObjects      = allowSceneObjects;
            m_IsShowingAssets        = true;
            m_AllowedIDs             = allowedInstanceIDs;

            m_OnObjectSelectorClosed  = onObjectSelectorClosed;
            m_OnObjectSelectorUpdated = onObjectSelectedUpdated;

            if (property != null)
            {
                if (requiredType == null)
                {
                    ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType);
                    // case 951876: built-in types do not actually have reflectable fields, so their object types must be extracted from the type string
                    // this works because built-in types will only ever have serialized references to other built-in types, which this window's filter expects as unqualified names
                    if (requiredType == null)
                    {
                        m_RequiredType = s_MatchPPtrTypeName.Match(property.type).Groups[1].Value;
                    }
                }

                obj = property.objectReferenceValue;
                m_ObjectBeingEdited = property.serializedObject.targetObject;

                // Do not allow to show scene objects if the object being edited is persistent
                if (m_ObjectBeingEdited != null && EditorUtility.IsPersistent(m_ObjectBeingEdited))
                {
                    m_AllowSceneObjects = false;
                }
            }

            // Set which tab should be visible at startup
            if (m_AllowSceneObjects)
            {
                if (obj != null)
                {
                    if (typeof(Component).IsAssignableFrom(obj.GetType()))
                    {
                        obj = ((Component)obj).gameObject;
                    }
                    // Set the right tab visible (so we can see our selection)
                    m_IsShowingAssets = EditorUtility.IsPersistent(obj);
                }
                else
                {
                    m_IsShowingAssets = (requiredType != typeof(GameObject) && !typeof(Component).IsAssignableFrom(requiredType));
                }
            }
            else
            {
                m_IsShowingAssets = true;
            }

            // Set member variables
            m_DelegateView = GUIView.current;
            // type filter requires unqualified names for built-in types, but will prioritize them over user types, so ensure user types are namespace-qualified
            if (requiredType != null)
            {
                m_RequiredType = typeof(ScriptableObject).IsAssignableFrom(requiredType) || typeof(MonoBehaviour).IsAssignableFrom(requiredType) ? requiredType.FullName : requiredType.Name;
            }
            m_SearchFilter      = "";
            m_OriginalSelection = obj;
            m_ModalUndoGroup    = Undo.GetCurrentGroup();

            // Freeze to prevent flicker on OSX.
            // Screen will be updated again when calling
            // SetFreezeDisplay(false) further down.
            ContainerWindow.SetFreezeDisplay(true);

            ShowWithMode(ShowMode.AuxWindow);
            titleContent = EditorGUIUtility.TrTextContent("Select " + (requiredType == null ? m_RequiredType : requiredType.Name));

            // Deal with window size
            Rect p = m_Parent.window.position;

            p.width  = EditorPrefs.GetFloat("ObjectSelectorWidth", 200);
            p.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390);
            position = p;
            minSize  = new Vector2(kMinWidth, kMinTopSize + kPreviewExpandedAreaHeight + 2 * kPreviewMargin);
            maxSize  = new Vector2(10000, 10000);
            SetupPreview();

            // Focus
            Focus();
            ContainerWindow.SetFreezeDisplay(false);

            m_FocusSearchFilter = true;

            // Add after unfreezing display because AuxWindowManager.cpp assumes that aux windows are added after we get 'got/lost'- focus calls.
            m_Parent.AddToAuxWindowList();

            // Initial selection
            int initialSelection = obj != null?obj.GetInstanceID() : 0;

            if (property != null && property.hasMultipleDifferentValues)
            {
                initialSelection = 0; // don't select anything on multi selection
            }
            if (ShouldTreeViewBeUsed(requiredType))
            {
                m_ObjectTreeWithSearch.Init(position, this, CreateAndSetTreeView, TreeViewSelection, ItemWasDoubleClicked, initialSelection, 0);
            }
            else
            {
                // To frame the selected item we need to wait to initialize the search until our window has been setup
                InitIfNeeded();
                m_ListArea.InitSelection(new[] { initialSelection });
                if (initialSelection != 0)
                {
                    m_ListArea.Frame(initialSelection, true, false);
                }
            }
        }