private static ReorderableList CreateNewListUI(SerializedProperty switcherActionsProp)
        {
            return(new ReorderableList(switcherActionsProp.serializedObject, switcherActionsProp)
            {
                onAddDropdownCallback = (rect, list) => {
                    var menu = new GenericMenu();
                    foreach (var type in m_switchActionTypes)
                    {
                        menu.AddItem(new GUIContent(type.Name), false, OnMenuClicked,
                                     new KeyValuePair <Type, SerializedProperty>(type, switcherActionsProp));
                    }

                    menu.ShowAsContext();
                },
                elementHeightCallback = index => {
                    var elementPropAtIndex = switcherActionsProp.GetArrayElementAtIndex(index);
                    var switcher = elementPropAtIndex.GetPropertyObject() as ISwitcherAction;
                    var drawer = ActionDrawer.GetDrawer(switcher.GetType());
                    var foldProp = elementPropAtIndex.FindPropertyRelative("m_fold");
                    if (!foldProp.boolValue)
                    {
                        return UIEditorUtil.LINE_HEIGHT;
                    }

                    return drawer.GetEditorHeight(elementPropAtIndex) + UIEditorUtil.LINE_HEIGHT;
                },
                drawElementCallback = (rect, index, active, focused) => {
                    var elementPropAtIndex = switcherActionsProp.GetArrayElementAtIndex(index);
                    var switcher = elementPropAtIndex.GetPropertyObject() as ISwitcherAction;
                    var drawer = ActionDrawer.GetDrawer(switcher.GetType());
                    var foldProp = elementPropAtIndex.FindPropertyRelative("m_fold");
                    rect.height = EditorGUIUtility.singleLineHeight;
                    var foldRect = rect;
                    foldRect.x += 10;
                    var name = ObjectNames.NicifyVariableName(switcher.GetType().Name);
                    foldProp.boolValue = EditorGUI.Foldout(foldRect, foldProp.boolValue, name);
                    if (!foldProp.boolValue)
                    {
                        return;
                    }

                    rect.y += UIEditorUtil.LINE_HEIGHT;
                    EditorGUI.indentLevel += 1;
                    drawer.OnEditorGUI(rect, elementPropAtIndex);
                    EditorGUI.indentLevel -= 1;
                },
                drawHeaderCallback = rect => {
                    EditorGUI.LabelField(rect, "Action List");
                }
            });
        }
Esempio n. 2
0
    void CustomDrawer2(ref Combo pCombo, int pIndex)
    {
        Icon.Action tAction = pCombo.ActionsPowerUp[pIndex];

        BaseAction tBaseAction = null;

        if (tAction.ActionToRun == null)
        {
            tBaseAction = BaseAction.GetActionObject(tAction.Type);
        }
        else
        {
            tBaseAction = tAction.ActionToRun;
        }
        ActionDrawer.DrawTypeList(ref tBaseAction, tAction.m_Type);
    }
Esempio n. 3
0
    void CustomDrawer(ref Icon pIcon, int pIndex)
    {
        Icon.Action tAction = pIcon.Actions[pIndex];

        BaseAction tBaseAction = null;

        if (tAction.ActionToRun == null)
        {
            tBaseAction = BaseAction.GetActionObject(tAction.Type);
        }
        else
        {
            tBaseAction = tAction.ActionToRun;
        }
        ActionDrawer.DrawTypeList(ref tBaseAction, tAction.m_Type);
    }
Esempio n. 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, 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
                         ));
 }
Esempio n. 5
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));
 }
Esempio n. 6
0
 public TernaryConditionalDrawerInternal(Enabler @switch, ActionDrawer drawIfTrue, ActionDrawer drawIfFalse)
 {
     this.drawIfTrue  = drawIfTrue;
     this.drawIfFalse = drawIfFalse;
     m_Switch         = @switch;
 }
Esempio n. 7
0
 /// <summary>
 /// Conditioned drawer that will draw something depending of the return of the switch
 /// </summary>
 /// <param name="@switch">Chose witch drawing to use</param>
 /// <param name="drawIfTrue">This will be draw if the <see cref="@switch"/> is true</param>
 /// <param name="drawIfFalse">This will be draw if the <see cref="@switch"/> is false</param>
 /// <returns>A IDrawer object</returns>
 public static IDrawer TernaryConditional(Enabler @switch, ActionDrawer drawIfTrue, ActionDrawer drawIfFalse)
 => new TernaryConditionalDrawerInternal(@switch, drawIfTrue, drawIfFalse);
Esempio n. 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
                                ));
        }
Esempio n. 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));
 }