public static void MatchTargetsFieldGUI(SerializedProperty property)
        {
            const float ToggleWidth = 20;
            int         value       = 0;

            MatchTargetFields enumValue = (MatchTargetFields)property.intValue;

            EditorGUI.BeginChangeCheck();
            Rect rect     = EditorGUILayout.GetControlRect(false, kLineHeight * 2);
            Rect itemRect = new Rect(rect.x, rect.y, rect.width, kLineHeight);

            EditorGUI.BeginProperty(rect, Styles.MatchTargetFieldsTitle, property);
            float minWidth = 0, maxWidth = 0;

            EditorStyles.label.CalcMinMaxWidth(Styles.XTitle, out minWidth, out maxWidth);
            float width = minWidth + ToggleWidth;

            GUILayout.BeginHorizontal();
            Rect r         = EditorGUI.PrefixLabel(itemRect, Styles.PositionTitle);
            int  oldIndent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            r.width = width;
            value  |= EditorGUI.ToggleLeft(r, Styles.XTitle, enumValue.HasAny(MatchTargetFields.PositionX)) ? (int)MatchTargetFields.PositionX : 0;
            r.x    += width;
            value  |= EditorGUI.ToggleLeft(r, Styles.YTitle, enumValue.HasAny(MatchTargetFields.PositionY)) ? (int)MatchTargetFields.PositionY : 0;
            r.x    += width;
            value  |= EditorGUI.ToggleLeft(r, Styles.ZTitle, enumValue.HasAny(MatchTargetFields.PositionZ)) ? (int)MatchTargetFields.PositionZ : 0;
            EditorGUI.indentLevel = oldIndent;
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            itemRect.y           += kLineHeight;
            r                     = EditorGUI.PrefixLabel(itemRect, Styles.RotationTitle);
            EditorGUI.indentLevel = 0;
            r.width               = width;
            value                |= EditorGUI.ToggleLeft(r, Styles.XTitle, enumValue.HasAny(MatchTargetFields.RotationX)) ? (int)MatchTargetFields.RotationX : 0;
            r.x                  += width;
            value                |= EditorGUI.ToggleLeft(r, Styles.YTitle, enumValue.HasAny(MatchTargetFields.RotationY)) ? (int)MatchTargetFields.RotationY : 0;
            r.x                  += width;
            value                |= EditorGUI.ToggleLeft(r, Styles.ZTitle, enumValue.HasAny(MatchTargetFields.RotationZ)) ? (int)MatchTargetFields.RotationZ : 0;
            EditorGUI.indentLevel = oldIndent;
            GUILayout.EndHorizontal();

            EditorGUI.EndProperty();
            if (EditorGUI.EndChangeCheck())
            {
                property.intValue = value;
            }
        }
        private static void WriteMatchFields(AnimationPlayableAsset asset, TimelineAnimationUtilities.RigidTransform result, MatchTargetFields fields)
        {
            Vector3 position = asset.position;

            position.x     = ((!fields.HasAny(MatchTargetFields.PositionX)) ? position.x : result.position.x);
            position.y     = ((!fields.HasAny(MatchTargetFields.PositionY)) ? position.y : result.position.y);
            position.z     = ((!fields.HasAny(MatchTargetFields.PositionZ)) ? position.z : result.position.z);
            asset.position = position;
            if (fields.HasAny(MatchTargetFieldConstants.Rotation))
            {
                Vector3 eulerAngles  = asset.rotation.get_eulerAngles();
                Vector3 eulerAngles2 = result.rotation.get_eulerAngles();
                eulerAngles.x  = ((!fields.HasAny(MatchTargetFields.RotationX)) ? eulerAngles.x : eulerAngles2.x);
                eulerAngles.y  = ((!fields.HasAny(MatchTargetFields.RotationY)) ? eulerAngles.y : eulerAngles2.y);
                eulerAngles.z  = ((!fields.HasAny(MatchTargetFields.RotationZ)) ? eulerAngles.z : eulerAngles2.z);
                asset.rotation = Quaternion.Euler(eulerAngles);
            }
        }
        static void WriteMatchFields(AnimationPlayableAsset asset, RigidTransform result, MatchTargetFields fields)
        {
            Vector3 position = asset.position;

            position.x = fields.HasAny(MatchTargetFields.PositionX) ? result.position.x : position.x;
            position.y = fields.HasAny(MatchTargetFields.PositionY) ? result.position.y : position.y;
            position.z = fields.HasAny(MatchTargetFields.PositionZ) ? result.position.z : position.z;

            asset.position = position;

            // check first to avoid unnecessary conversion errors
            if (fields.HasAny(MatchTargetFieldConstants.Rotation))
            {
                Vector3 eulers       = asset.eulerAngles;
                Vector3 resultEulers = result.rotation.eulerAngles;

                eulers.x = fields.HasAny(MatchTargetFields.RotationX) ? resultEulers.x : eulers.x;
                eulers.y = fields.HasAny(MatchTargetFields.RotationY) ? resultEulers.y : eulers.y;
                eulers.z = fields.HasAny(MatchTargetFields.RotationZ) ? resultEulers.z : eulers.z;

                asset.eulerAngles = AnimationUtility.GetClosestEuler(Quaternion.Euler(eulers), asset.eulerAngles, RotationOrder.OrderZXY);
            }
        }
示例#4
0
        public static void MatchTargetsField(SerializedProperty property, SerializedProperty alternate, SerializedProperty disableOptions, bool showHelp = false)
        {
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            property.set_isExpanded(EditorGUILayout.Foldout(property.get_isExpanded(), AnimationTrackInspector.Styles.MatchTargetFieldsTitle));
            GUILayout.EndHorizontal();
            int num = 0;

            if (property.get_isExpanded())
            {
                if (showHelp)
                {
                    string text = string.Format(AnimationTrackInspector.Styles.MatchTargetsFieldHelp.get_text(), AnimationTrackInspector.Styles.DisableOptionsTitle.get_text());
                    EditorGUILayout.HelpBox(text, 1);
                }
                EditorGUI.set_indentLevel(EditorGUI.get_indentLevel() + 1);
                bool flag = false;
                if (alternate != null)
                {
                    EditorGUILayout.PropertyField(disableOptions, AnimationTrackInspector.Styles.DisableOptionsTitle, new GUILayoutOption[0]);
                    flag = !disableOptions.get_boolValue();
                    if (flag)
                    {
                        property = alternate;
                    }
                }
                using (new EditorGUI.DisabledScope(flag))
                {
                    MatchTargetFields intValue = (MatchTargetFields)property.get_intValue();
                    EditorGUI.BeginChangeCheck();
                    Rect controlRect = EditorGUILayout.GetControlRect(false, 32f, new GUILayoutOption[0]);
                    Rect rect        = new Rect(controlRect.get_x(), controlRect.get_y(), controlRect.get_width(), 16f);
                    EditorGUI.BeginProperty(controlRect, AnimationTrackInspector.Styles.MatchTargetFieldsTitle, property);
                    float num2 = 0f;
                    float num3 = 0f;
                    EditorStyles.get_label().CalcMinMaxWidth(AnimationTrackInspector.Styles.XTitle, ref num2, ref num3);
                    float num4 = num2 + 20f;
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    Rect rect2       = EditorGUI.PrefixLabel(rect, AnimationTrackInspector.Styles.PositionTitle);
                    int  indentLevel = EditorGUI.get_indentLevel();
                    EditorGUI.set_indentLevel(0);
                    rect2.set_width(num4);
                    num |= ((!EditorGUI.ToggleLeft(rect2, AnimationTrackInspector.Styles.XTitle, intValue.HasAny(MatchTargetFields.PositionX))) ? 0 : 1);
                    rect2.set_x(rect2.get_x() + num4);
                    num |= ((!EditorGUI.ToggleLeft(rect2, AnimationTrackInspector.Styles.YTitle, intValue.HasAny(MatchTargetFields.PositionY))) ? 0 : 2);
                    rect2.set_x(rect2.get_x() + num4);
                    num |= ((!EditorGUI.ToggleLeft(rect2, AnimationTrackInspector.Styles.ZTitle, intValue.HasAny(MatchTargetFields.PositionZ))) ? 0 : 4);
                    EditorGUI.set_indentLevel(indentLevel);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    rect.set_y(rect.get_y() + 16f);
                    rect2 = EditorGUI.PrefixLabel(rect, AnimationTrackInspector.Styles.RotationTitle);
                    EditorGUI.set_indentLevel(0);
                    rect2.set_width(num4);
                    num |= ((!EditorGUI.ToggleLeft(rect2, AnimationTrackInspector.Styles.XTitle, intValue.HasAny(MatchTargetFields.RotationX))) ? 0 : 8);
                    rect2.set_x(rect2.get_x() + num4);
                    num |= ((!EditorGUI.ToggleLeft(rect2, AnimationTrackInspector.Styles.YTitle, intValue.HasAny(MatchTargetFields.RotationY))) ? 0 : 16);
                    rect2.set_x(rect2.get_x() + num4);
                    num |= ((!EditorGUI.ToggleLeft(rect2, AnimationTrackInspector.Styles.ZTitle, intValue.HasAny(MatchTargetFields.RotationZ))) ? 0 : 32);
                    EditorGUI.set_indentLevel(indentLevel);
                    GUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        property.set_intValue(num);
                    }
                    EditorGUI.EndProperty();
                }
                EditorGUI.set_indentLevel(EditorGUI.get_indentLevel() - 1);
            }
        }