/// <summary>
    /// Draws and responds to a toggle box for a component type. Clears Special types, if set.
    /// </summary>
    private void DrawToggle(int poolIndex, KMComponentPool.ComponentTypeEnum typeToToggle)
    {
        KMMission       mission       = (KMMission)serializedObject.targetObject;
        KMComponentPool componentPool = mission.GeneratorSetting.ComponentPools[poolIndex];

        bool previousValue = componentPool.ComponentTypes.Contains(typeToToggle);

        if (EditorGUILayout.ToggleLeft(
                typeToToggle.ToString(),
                previousValue))
        {
            if (!componentPool.ComponentTypes.Contains(typeToToggle))
            {
                componentPool.ComponentTypes.Add(typeToToggle);
            }
        }
        else
        {
            componentPool.ComponentTypes.RemoveAll(x => x == typeToToggle);
        }

        //If we just toggled something, clear any special flags too
        bool currentValue = componentPool.ComponentTypes.Contains(typeToToggle);

        if (previousValue != currentValue)
        {
            componentPool.SpecialComponentType = KMComponentPool.SpecialComponentTypeEnum.None;
        }
    }
Ejemplo n.º 2
0
    private void drawToggle(SerializedProperty componentPool, KMComponentPool.ComponentTypeEnum componentType)
    {
        SerializedProperty componentTypes = componentPool.FindPropertyRelative("ComponentTypes");
        bool previousValue = false;

        for (int i = 0; i < componentTypes.arraySize; i++)
        {
            if (componentTypes.GetArrayElementAtIndex(i).intValue == (int)componentType)
            {
                previousValue = true;
                break;
            }
        }
        bool newValue = EditorGUILayout.ToggleLeft(componentType.ToString(), previousValue);

        if (newValue != previousValue)
        {
            if (previousValue)
            {
                for (int i = componentTypes.arraySize - 1; i >= 0; i--)
                {
                    if (componentTypes.GetArrayElementAtIndex(i).intValue == (int)componentType)
                    {
                        componentTypes.DeleteArrayElementAtIndex(i);
                    }
                }
            }
            else
            {
                componentTypes.InsertArrayElementAtIndex(componentTypes.arraySize);
                componentTypes.GetArrayElementAtIndex(componentTypes.arraySize - 1).intValue = (int)componentType;
            }
            componentPool.FindPropertyRelative("SpecialComponentType").intValue = (int)KMComponentPool.SpecialComponentTypeEnum.None;
        }
    }