Example #1
0
        /// <summary>
        /// Displays a button for setting all axes of motion on an array of targets.
        /// </summary>
        /// <param name="preference">Preference storing the motion type value.</param>
        /// <param name="label">Label for the control.</param>
        /// <param name="targets">An array of configurable joints.</param>
        /// <param name="applyMethod">Method to invoke if preference value is to be applied to all targets.</param>
        private void DisplayMultiJointMotionButton(
            EditorPreference <ConfigurableJointMotion, JointEditor> preference,
            GUIContent label,
            System.Action <ConfigurableJoint, ConfigurableJointMotion> applyMethod
            )
        {
            Rect controlPosition, buttonPosition;

            EditorGUIX.GetRectsForControlWithInlineButton(
                EditorGUILayout.GetControlRect(), out controlPosition, out buttonPosition, 40f, 80f
                );
            preference.CurrentValue =
                (ConfigurableJointMotion)EditorGUIX.DisplayField <System.Enum>(
                    controlPosition, label, preference.CurrentValue, EditorGUI.EnumPopup
                    );
            if (EditorGUIX.DisplayButton(buttonPosition, "Set All"))
            {
                Undo.RecordObjects(m_CachedTargets, string.Format("Set All {0} Motion", label.text));
                foreach (ConfigurableJoint j in m_CachedTargets)
                {
                    if (j == null)
                    {
                        continue;
                    }
                    applyMethod(j, preference.CurrentValue);
                }
                EditorUtilityX.SetDirty(m_CachedTargets);
            }
        }