private void CreateCurrentCardAbilitiesList()
 {
     currentCardAbilitiesList = EditorUtils.SetupReorderableList("Abilities", currentCard.abilities, ref currentCardAbility, (rect, x) =>
     {
         EditorGUI.LabelField(new Rect(rect.x, rect.y, 200, EditorGUIUtility.singleLineHeight), x.name);
     },
                                                                 (x) =>
     {
         currentCardAbility = x;
         currentPlayerTargetConditionsList = null;
         currentPlayerTarget             = null;
         currentPlayerTargetCondition    = null;
         currentCardTargetConditionsList = null;
         currentCardTarget          = null;
         currentCardTargetCondition = null;
         if (currentCardAbility is ActivatedAbility)
         {
             CreateCurrentEffectCostsList();
         }
     },
                                                                 () =>
     {
         var menu = new GenericMenu();
         menu.AddItem(new GUIContent("Triggered ability"), false, CreateCardAbilityCallback, 0);
         menu.AddItem(new GUIContent("Activated ability"), false, CreateCardAbilityCallback, 1);
         menu.ShowAsContext();
     },
                                                                 (x) =>
     {
         currentCardAbility = null;
         currentPlayerTargetConditionsList = null;
         currentPlayerTarget             = null;
         currentPlayerTargetCondition    = null;
         currentCardTargetConditionsList = null;
         currentCardTarget          = null;
         currentCardTargetCondition = null;
     });
 }
        private void DrawEffect(ref Effect effect, ref Target target)
        {
            var effectTypeId = 0;

            if (effect != null)
            {
                var effectCopy = effect;
                effectTypeId = effectTypes.FindIndex(x => x == effectCopy.GetType());
            }

            var prevEffectTypeId = effectTypeId;

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Effect");
            effectTypeId = EditorGUILayout.Popup(prevEffectTypeId, effectTypeNames.ToArray(), GUILayout.MaxWidth(EditorConfig.RegularComboBoxWidth));
            GUILayout.EndHorizontal();

            if (effect == null || effectTypeId != prevEffectTypeId)
            {
                var type = effectTypes[effectTypeId];
                effect = Activator.CreateInstance(type) as Effect;
            }

            var fields = effect.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public).OrderBy(x => ((OrderAttribute)x.GetCustomAttributes(typeof(OrderAttribute), false)[0]).Order).ToArray();

            for (var i = 0; i < fields.Length; i++)
            {
                var attribute = Attribute.GetCustomAttribute(fields[i], typeof(FieldAttribute)) as FieldAttribute;
                if (attribute != null)
                {
                    GUILayout.BeginHorizontal();
                    attribute.Draw(gameConfig, effect, ref fields[i]);
                    GUILayout.EndHorizontal();
                }
            }

            if (effect != null)
            {
                var targetAttributes = effectTypes[effectTypeId].GetCustomAttributes(typeof(System.Attribute), true);
                if (targetAttributes != null && targetAttributes.Length > 0)
                {
                    List <Type>   targetTypes;
                    List <string> targetTypeNames;
                    if (targetAttributes[0] is PlayerTargetAttribute)
                    {
                        targetTypes     = humanTargetTypes;
                        targetTypeNames = humanTargetTypeNames;
                    }
                    else
                    {
                        targetTypes     = cardTargetTypes;
                        targetTypeNames = cardTargetTypeNames;
                    }

                    var targetTypeId = 0;
                    if (target != null)
                    {
                        var targetCopy = target;
                        targetTypeId = targetTypes.FindIndex(x => x == targetCopy.GetType());
                    }

                    var prevTargetTypeId = targetTypeId;

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Target");
                    targetTypeId = EditorGUILayout.Popup(prevTargetTypeId, targetTypeNames.ToArray(), GUILayout.MaxWidth(EditorConfig.RegularComboBoxWidth));
                    GUILayout.EndHorizontal();

                    if (target == null || targetTypeId != prevTargetTypeId)
                    {
                        var type = targetTypes[targetTypeId];
                        target = Activator.CreateInstance(type) as Target;
                    }

                    fields = target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
                    for (var i = 0; i < fields.Length; i++)
                    {
                        var attribute = Attribute.GetCustomAttribute(fields[i], typeof(FieldAttribute)) as FieldAttribute;
                        if (attribute != null)
                        {
                            GUILayout.BeginHorizontal();
                            attribute.Draw(gameConfig, target, ref fields[i]);
                            GUILayout.EndHorizontal();
                        }
                    }

                    if (target != null)
                    {
                        if (target is PlayerTargetBase && currentPlayerTargetConditionsList == null)
                        {
                            currentPlayerTarget = target as PlayerTargetBase;
                            CreateCurrentPlayerTargetConditionsList();
                        }
                        else if (target is CardTargetBase && currentCardTargetConditionsList == null)
                        {
                            currentCardTarget = target as CardTargetBase;
                            CreateCurrentCardTargetConditionsList();
                        }
                    }

                    if (currentPlayerTarget != null)
                    {
                        GUILayout.BeginHorizontal();

                        GUILayout.BeginVertical(GUILayout.MaxWidth(250));
                        if (currentPlayerTargetConditionsList != null)
                        {
                            currentPlayerTargetConditionsList.DoLayoutList();
                        }
                        GUILayout.EndVertical();

                        if (currentPlayerTargetCondition != null)
                        {
                            DrawTargetCondition(currentPlayerTargetCondition);
                        }

                        GUILayout.EndHorizontal();
                    }
                    else if (currentCardTarget != null)
                    {
                        GUILayout.BeginHorizontal();

                        GUILayout.BeginVertical(GUILayout.MaxWidth(250));
                        if (currentCardTargetConditionsList != null)
                        {
                            currentCardTargetConditionsList.DoLayoutList();
                        }
                        GUILayout.EndVertical();

                        if (currentCardTargetCondition != null)
                        {
                            DrawTargetCondition(currentCardTargetCondition);
                        }

                        GUILayout.EndHorizontal();
                    }
                }
            }
        }