Пример #1
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;
            }
Пример #2
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
                         ));
 }
Пример #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, IDrawer normalContent, ActionDrawer advancedContent, FoldoutOption options = FoldoutOption.Indent)
     where TEnum : struct, IConvertible
 {
     return(AdvancedFoldoutGroup(foldoutTitle, foldoutMask, foldoutState, isAdvanced, switchAdvanced, normalContent.Draw, advancedContent, options));
 }
Пример #4
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 isAdvanced, SwitchEnabler switchAdvanced, 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,
                                                                isAdvanced == null ? (Func <bool>)null : () => isAdvanced(data, owner),
                                                                switchAdvanced == null ? (Action)null : () => switchAdvanced(data, owner));
         }
         else
         {
             CoreEditorUtils.DrawSplitter(isBoxed);
             newExpended = CoreEditorUtils.DrawHeaderFoldout(title, expended, isBoxed,
                                                             isAdvanced == null ? (Func <bool>)null : () => isAdvanced(data, owner),
                                                             switchAdvanced == null ? (Action)null : () => switchAdvanced(data, owner));
         }
         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();
             }
         }
     }));
 }
Пример #5
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));
 }