コード例 #1
0
        // This one is private as we do not want to have unhandled advanced switch. Change it if necessary.
        static IDrawer FoldoutGroup <TEnum, TState>(GUIContent title, TEnum mask, ExpandedState <TEnum, TState> state, FoldoutOption options, Enabler showAdditionalProperties, SwitchEnabler switchAdditionalProperties, params ActionDrawer[] contentDrawers)
            where TEnum : struct, IConvertible
        {
            return(Group((data, owner) =>
            {
                bool isBoxed = (options & FoldoutOption.Boxed) != 0;
                bool isIndented = (options & FoldoutOption.Indent) != 0;
                bool isSubFoldout = (options & FoldoutOption.SubFoldout) != 0;
                bool noSpaceAtEnd = (options & FoldoutOption.NoSpaceAtEnd) != 0;
                bool expended = state[mask];
                bool newExpended = expended;

                if (isSubFoldout)
                {
                    newExpended = CoreEditorUtils.DrawSubHeaderFoldout(title, expended, isBoxed);
                }
                else
                {
                    CoreEditorUtils.DrawSplitter(isBoxed);
                    newExpended = CoreEditorUtils.DrawHeaderFoldout(title,
                                                                    expended,
                                                                    isBoxed,
                                                                    showAdditionalProperties == null ? (Func <bool>)null : () => showAdditionalProperties(data, owner),
                                                                    switchAdditionalProperties == null ? (Action)null : () => switchAdditionalProperties(data, owner),
                                                                    GetHelpURL <TEnum>(mask));
                }
                if (newExpended ^ expended)
                {
                    state[mask] = newExpended;
                }
                if (newExpended)
                {
                    if (isIndented)
                    {
                        ++EditorGUI.indentLevel;
                    }
                    for (var i = 0; i < contentDrawers.Length; i++)
                    {
                        contentDrawers[i](data, owner);
                    }
                    if (isIndented)
                    {
                        --EditorGUI.indentLevel;
                    }
                    if (!noSpaceAtEnd)
                    {
                        EditorGUILayout.Space();
                    }
                }
            }));
        }
コード例 #2
0
            public FoldoutGroupDrawerInternal(GUIContent title, TEnum mask, ExpandedState <TEnum, TState> state,
                                              Enabler enabler, SwitchEnabler switchEnabler, FoldoutOption options = FoldoutOption.None, params ActionDrawer[] actionDrawers)
            {
                m_IsBoxed      = (options & FoldoutOption.Boxed) != 0;
                m_IsIndented   = (options & FoldoutOption.Indent) != 0;
                m_IsSubFoldout = (options & FoldoutOption.SubFoldout) != 0;
                m_NoSpaceAtEnd = (options & FoldoutOption.NoSpaceAtEnd) != 0;

                m_ActionDrawers = actionDrawers;
                m_Title         = title;
                m_State         = state;
                m_Mask          = mask;

                var helpUrlAttribute = (HelpURLAttribute)mask
                                       .GetType()
                                       .GetCustomAttributes(typeof(HelpURLAttribute), false)
                                       .FirstOrDefault();

                m_HelpUrl = helpUrlAttribute == null ? string.Empty : $"{helpUrlAttribute.URL}#{mask}";

                m_Enabler       = enabler;
                m_SwitchEnabler = switchEnabler;
            }
コード例 #3
0
 /// <summary> Helper to draw a foldout with an advanced switch on it. </summary>
 /// <typeparam name="TEnum">Type of the mask used</typeparam>
 /// <typeparam name="TState">Type of the persistent state</typeparam>
 /// <param name="foldoutTitle">Title wanted for this foldout header</param>
 /// <param name="foldoutMask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="foldoutState">The ExpandedState describing the component</param>
 /// <param name="isAdvanced"> Delegate allowing to check if advanced mode is active. </param>
 /// <param name="switchAdvanced"> Delegate to know what to do when advance is switched. </param>
 /// <param name="normalContent"> The content of the foldout header always visible if expended. </param>
 /// <param name="advancedContent"> The content of the foldout header only visible if advanced mode is active and if foldout is expended. </param>
 /// <param name="options">Drawing options</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer AdvancedFoldoutGroup <TEnum, TState>(GUIContent foldoutTitle, TEnum foldoutMask, ExpandedState <TEnum, TState> foldoutState, Enabler isAdvanced, SwitchEnabler switchAdvanced, ActionDrawer normalContent, ActionDrawer advancedContent, FoldoutOption options = FoldoutOption.Indent)
     where TEnum : struct, IConvertible
 {
     return(FoldoutGroup(foldoutTitle, foldoutMask, foldoutState, options, isAdvanced, switchAdvanced,
                         normalContent,
                         Conditional((serialized, owner) => isAdvanced(serialized, owner) && foldoutState[foldoutMask], advancedContent).Draw
                         ));
 }
コード例 #4
0
 /// <summary> Helper to draw a foldout with an advanced switch on it. </summary>
 /// <typeparam name="TEnum">Type of the mask used</typeparam>
 /// <typeparam name="TState">Type of the persistent state</typeparam>
 /// <param name="foldoutTitle">Title wanted for this foldout header</param>
 /// <param name="foldoutMask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="foldoutState">The ExpandedState describing the component</param>
 /// <param name="isAdvanced"> Delegate allowing to check if advanced mode is active. </param>
 /// <param name="switchAdvanced"> Delegate to know what to do when advance is switched. </param>
 /// <param name="normalContent"> The content of the foldout header always visible if expended. </param>
 /// <param name="advancedContent"> The content of the foldout header only visible if advanced mode is active and if foldout is expended. </param>
 /// <param name="options">Drawing options</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer AdvancedFoldoutGroup <TEnum, TState>(GUIContent foldoutTitle, TEnum foldoutMask, ExpandedState <TEnum, TState> foldoutState, Enabler isAdvanced, SwitchEnabler switchAdvanced, IDrawer normalContent, ActionDrawer advancedContent, FoldoutOption options = FoldoutOption.Indent)
     where TEnum : struct, IConvertible
 {
     return(AdvancedFoldoutGroup(foldoutTitle, foldoutMask, foldoutState, isAdvanced, switchAdvanced, normalContent.Draw, advancedContent, options));
 }
コード例 #5
0
 /// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
 /// <typeparam name="TEnum">Type of the mask used</typeparam>
 /// <typeparam name="TState">Type of the persistent state</typeparam>
 /// <param name="title">Title wanted for this foldout header</param>
 /// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="state">The ExpandedState describing the component</param>
 /// <param name="options">Drawing options</param>
 /// <param name="contentDrawers">The content of the foldout header</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer FoldoutGroup <TEnum, TState>(GUIContent title, TEnum mask, ExpandedState <TEnum, TState> state, FoldoutOption options, params ActionDrawer[] contentDrawers)
     where TEnum : struct, IConvertible
 {
     return(FoldoutGroup(title, mask, state, options, null, null, contentDrawers));
 }
コード例 #6
0
 /// <summary>
 /// Create an IDrawer foldout header using an ExpandedState.
 /// The default option is Indent in this version.
 /// </summary>
 /// <typeparam name="TEnum">Type of the mask used</typeparam>
 /// <typeparam name="TState">Type of the persistent state</typeparam>
 /// <param name="title">Title wanted for this foldout header</param>
 /// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="state">The ExpandedState describing the component</param>
 /// <param name="contentDrawers">The content of the foldout header</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer FoldoutGroup <TEnum, TState>(GUIContent title, TEnum mask, ExpandedState <TEnum, TState> state, params IDrawer[] contentDrawers)
     where TEnum : struct, IConvertible
 {
     return(FoldoutGroup(title, mask, state, contentDrawers.Draw));
 }
コード例 #7
0
 /// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
 /// <typeparam name="TEnum">Type of the mask used</typeparam>
 /// <typeparam name="TState">Type of the persistent state</typeparam>
 /// <param name="title">Title wanted for this foldout header</param>
 /// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="state">The ExpandedState describing the component</param>
 /// <param name="options">Drawing options</param>
 /// <param name="contentDrawers">The content of the foldout header</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer FoldoutGroup <TEnum, TState>(string title, TEnum mask, ExpandedState <TEnum, TState> state, FoldoutOption options, params ActionDrawer[] contentDrawers)
     where TEnum : struct, IConvertible
 {
     return(FoldoutGroup(EditorGUIUtility.TrTextContent(title), mask, state, options, contentDrawers));
 }
コード例 #8
0
        /// <summary>
        /// Helper to draw a foldout with additional properties.
        /// </summary>
        /// <typeparam name="TEnum">Type of the foldout mask used.</typeparam>
        /// <typeparam name="TState">Type of the persistent foldout state.</typeparam>
        /// <typeparam name="TAPEnum">Type of the additional properties mask used.</typeparam>
        /// <typeparam name="TAPState">Type of the persistent additional properties state.</typeparam>
        /// <param name="foldoutTitle">Title wanted for this foldout header</param>
        /// <param name="foldoutMask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
        /// <param name="foldoutState">The ExpandedState describing the component</param>
        /// <param name="additionalPropertiesMask">Bit mask (enum) used to define the boolean saving the state in AdditionalPropertiesState</param>
        /// <param name="additionalPropertiesState">The AdditionalPropertiesState describing the component</param>
        /// <param name="normalContent"> The content of the foldout header always visible if expended. </param>
        /// <param name="additionalContent">The content of the foldout header only visible if additional properties are shown and if foldout is expanded.</param>
        /// <param name="options">Drawing options</param>
        /// <returns>A IDrawer object</returns>
        public static IDrawer AdditionalPropertiesFoldoutGroup <TEnum, TState, TAPEnum, TAPState>(GUIContent foldoutTitle, TEnum foldoutMask, ExpandedState <TEnum, TState> foldoutState,
                                                                                                  TAPEnum additionalPropertiesMask, AdditionalPropertiesState <TAPEnum, TAPState> additionalPropertiesState, ActionDrawer normalContent, ActionDrawer additionalContent, FoldoutOption options = FoldoutOption.Indent)
            where TEnum : struct, IConvertible
            where TAPEnum : struct, IConvertible
        {
            bool Enabler(TData data, Editor owner)
            {
                return(additionalPropertiesState[additionalPropertiesMask]);
            }

            void SwitchEnabler(TData data, Editor owner)
            {
                additionalPropertiesState[additionalPropertiesMask] = !additionalPropertiesState[additionalPropertiesMask];
            }

            return(FoldoutGroup(foldoutTitle, foldoutMask, foldoutState, options, Enabler, SwitchEnabler,
                                normalContent,
                                ConditionalWithAdditionalProperties((serialized, owner) => additionalPropertiesState[additionalPropertiesMask] && foldoutState[foldoutMask], additionalPropertiesState.GetAnimation(additionalPropertiesMask), additionalContent).Draw
                                ));
        }
コード例 #9
0
 /// <summary>
 /// Helper to draw a foldout with additional properties.
 /// </summary>
 /// <typeparam name="TEnum">Type of the foldout mask used.</typeparam>
 /// <typeparam name="TState">Type of the persistent foldout state.</typeparam>
 /// <typeparam name="TAPEnum">Type of the additional properties mask used.</typeparam>
 /// <typeparam name="TAPState">Type of the persistent additional properties state.</typeparam>
 /// <param name="foldoutTitle">Title wanted for this foldout header</param>
 /// <param name="foldoutMask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="foldoutState">The ExpandedState describing the component</param>
 /// <param name="additionalPropertiesMask">Bit mask (enum) used to define the boolean saving the state in AdditionalPropertiesState</param>
 /// <param name="additionalPropertiesState">The AdditionalPropertiesState describing the component</param>
 /// <param name="normalContent"> The content of the foldout header always visible if expended. </param>
 /// <param name="additionalContent">The content of the foldout header only visible if additional properties are shown and if foldout is expanded.</param>
 /// <param name="options">Drawing options</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer AdditionalPropertiesFoldoutGroup <TEnum, TState, TAPEnum, TAPState>(GUIContent foldoutTitle, TEnum foldoutMask, ExpandedState <TEnum, TState> foldoutState,
                                                                                           TAPEnum additionalPropertiesMask, AdditionalPropertiesState <TAPEnum, TAPState> additionalPropertiesState, IDrawer normalContent, ActionDrawer additionalContent, FoldoutOption options = FoldoutOption.Indent)
     where TEnum : struct, IConvertible
     where TAPEnum : struct, IConvertible
 {
     return(AdditionalPropertiesFoldoutGroup(foldoutTitle, foldoutMask, foldoutState, additionalPropertiesMask, additionalPropertiesState, normalContent.Draw, additionalContent, options));
 }
コード例 #10
0
 // This one is private as we do not want to have unhandled advanced switch. Change it if necessary.
 static IDrawer FoldoutGroup <TEnum, TState>(GUIContent title, TEnum mask, ExpandedState <TEnum, TState> state, FoldoutOption options, Enabler showAdditionalProperties, SwitchEnabler switchAdditionalProperties, params ActionDrawer[] contentDrawers)
     where TEnum : struct, IConvertible
 {
     return(new FoldoutGroupDrawerInternal <TEnum, TState>(title, mask, state, showAdditionalProperties, switchAdditionalProperties, options, contentDrawers));
 }