コード例 #1
0
    public override void InitAbility(AbilitySystemComponent abilitySystem, AbilityEditorData abilityEditorData)
    {
        base.InitAbility(abilitySystem, abilityEditorData);
        abilityData.abilityType      = abilityEditorData.abilityType;
        abilityData.castPoint        = abilityEditorData.castPoint;
        abilityData.channelStartTime = abilityEditorData.channelStartTime;
        abilityData.channelInterval  = abilityEditorData.channelInterval;
        abilityData.channelEndTime   = abilityEditorData.channelEndTime;
        abilityData.targetType       = abilityEditorData.targetType;
        abilityData.totalTime        = abilityEditorData.totalTime;

        abilityData.spellRadius      = abilityEditorData.spellRadius;
        abilityData.spellRange       = abilityEditorData.spellRange;
        abilityData.spellOverlapType = abilityEditorData.spellOverlapType;
        if (abilityEditorData.Buff_CoolDown != null)
        {
            effect_CoolDown = AbilityManager.Instance.CreateAbility(AbilityTagManager.Instance.GetTagContainer(abilityEditorData.Buff_CoolDown.abilityTags[0]), abilitySystem) as AbilityBuff;
        }
        if (abilityEditorData.Buff_Cost != null)
        {
            effect_Cost = AbilityManager.Instance.CreateAbility(AbilityTagManager.Instance.GetTagContainer(abilityEditorData.Buff_Cost.abilityTags[0]), abilitySystem) as AbilityBuff;
        }
        InitTagList(ref passive_ListenerTags, abilityEditorData.passiveAbilityListenerTags);
        InitTagList(ref triggerTags, abilityEditorData.passiveAbilityTriggerTags);

        if (abilityData.abilityType == EAbilityType.EAT_PassiveAblity)
        {
            foreach (FAbilityTagContainer tag in passive_ListenerTags)
            {
                abilitySystem.RegisterEvent(tag, OnTriggerActivateAbility);
            }
        }
    }
コード例 #2
0
    static object GetTags(ref int tag_index, AbilityEditorData abilityEditorData, Type type)
    {
        object        res  = null;
        List <string> list = null;

        switch (tag_index)
        {
        case 0:
            list = abilityEditorData.otherTags_1;
            break;

        case 1:
            list = abilityEditorData.otherTags_2;
            break;

        case 2:
            list = abilityEditorData.otherTags_3;
            break;

        case 3:
            list = abilityEditorData.otherTags_4;
            break;

        default:
            break;
        }
        if (list != null)
        {
            if (type == typeof(FAbilityTagContainer))
            {
                if (list.Count > 0)
                {
                    res = AbilityTagManager.Instance.GetTagContainer(list[0]);
                }
            }
            else
            {
                List <FAbilityTagContainer> tags = new List <FAbilityTagContainer>();

                foreach (string tag in list)
                {
                    tags.Add(AbilityTagManager.Instance.GetTagContainer(tag));
                }
                res = tags;
            }
        }
        ++tag_index;
        return(res);
    }
コード例 #3
0
    void OnEnable()
    {
        ability       = (AbilityEditorData)target;
        obj           = new SerializedObject(target);
        AbilityScript = obj.FindProperty("AbilityScript");

        Buff_CoolDown        = obj.FindProperty("Buff_CoolDown");
        Buff_Cost            = obj.FindProperty("Buff_Cost");
        Buff_Modifiers       = obj.FindProperty("Buff_Modifiers");
        Buff_MotionModifiers = obj.FindProperty("Buff_MotionModifiers");

        if (ability.child_UnityDatas == null)
        {
            ability.child_UnityDatas = new List <UnityEngine.Object>();
        }
        if (ability.child_BaseDatas_Int == null)
        {
            ability.child_BaseDatas_Int = new List <int>();
        }
        if (ability.child_BaseDatas_Bool == null)
        {
            ability.child_BaseDatas_Bool = new List <bool>();
        }
        if (ability.child_BaseDatas_Float == null)
        {
            ability.child_BaseDatas_Float = new List <float>();
        }
        if (ability.child_BaseDatas_String == null)
        {
            ability.child_BaseDatas_String = new List <string>();
        }
        if (ability.Buff_Modifiers == null)
        {
            ability.Buff_Modifiers = new List <Editor_FModifierData>();
        }
        if (ability.Buff_MotionModifiers == null)
        {
            ability.Buff_MotionModifiers = new List <Editor_FMotionModifierData>();
        }
    }
コード例 #4
0
ファイル: AbilityBase.cs プロジェクト: Skierhou/AbilitySystem
    /// <summary>
    /// 初始化
    /// </summary>
    public virtual void InitAbility(AbilitySystemComponent abilitySystem, AbilityEditorData abilityEditorData)
    {
        this.abilitySystem = abilitySystem;

        abilityTags = AbilityTagManager.Instance.GetTagContainer(abilityEditorData.abilityTags[0]);
        InitTagList(ref cancelAbilitiesWithTags, abilityEditorData.cancelAbilitiesWithTags);
        InitTagList(ref blockAbilitiesWithTags, abilityEditorData.blockAbilitiesWithTags);
        InitTagList(ref activationOwnedTags, abilityEditorData.activationOwnedTags);
        InitTagList(ref sourceRequiredTags, abilityEditorData.sourceRequiredTags);
        InitTagList(ref sourceBlockedTags, abilityEditorData.sourceBlockedTags);
        InitTagList(ref targetRequiredTags, abilityEditorData.targetRequiredTags);
        InitTagList(ref targetBlockedTags, abilityEditorData.targetBlockedTags);

        Level                    = 0;
        MaxLevel                 = abilityEditorData.maxLevel;
        IsActive                 = false;
        IsImmediately            = abilityEditorData.bImmediately;
        IsCancelable             = abilityEditorData.bIsCancelable;
        IsBlockingOtherAbilities = abilityEditorData.bIsBlockingOtherAbilities;

        AbilityEditorData.ReadChildInfo(GetType(), abilityEditorData, this);
    }
コード例 #5
0
    public static void ReadChildInfo(Type type, AbilityEditorData abilityEditorData, object owner)
    {
        int int_index = 0, float_index = 0, string_index = 0, bool_index = 0, unity_index = 0, tag_index = 0;

        while (type != typeof(AbilityBase) && type != typeof(UnityEngine.Object) && type != typeof(System.Object))
        {
            FieldInfo[] tFieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
            if (tFieldInfos.Length > 0)
            {
                for (int i = 0; i < tFieldInfos.Length; i++)
                {
                    if (tFieldInfos[i].GetCustomAttribute(typeof(AbilityConfig)) == null)
                    {
                        continue;
                    }
                    object obj;
                    if (tFieldInfos[i].FieldType == typeof(int))
                    {
                        obj = abilityEditorData.child_BaseDatas_Int[int_index++];
                    }
                    else if (tFieldInfos[i].FieldType == typeof(byte))
                    {
                        obj = System.Convert.ChangeType(abilityEditorData.child_BaseDatas_Int[int_index++], tFieldInfos[i].FieldType);
                    }
                    else if (tFieldInfos[i].FieldType.IsEnum)
                    {
                        obj = Enum.GetValues(tFieldInfos[i].FieldType).GetValue(abilityEditorData.child_BaseDatas_Int[int_index++]);
                    }
                    else if (tFieldInfos[i].FieldType == typeof(bool))
                    {
                        obj = abilityEditorData.child_BaseDatas_Bool[bool_index++];
                    }
                    else if (tFieldInfos[i].FieldType == typeof(float) || tFieldInfos[i].FieldType == typeof(double))
                    {
                        obj = abilityEditorData.child_BaseDatas_Float[float_index++];
                    }
                    else if (tFieldInfos[i].FieldType == typeof(string))
                    {
                        obj = abilityEditorData.child_BaseDatas_String[string_index++];
                    }
                    else if (tFieldInfos[i].FieldType == typeof(char))
                    {
                        obj = abilityEditorData.child_BaseDatas_String[string_index++][0];
                    }
                    else if (type == typeof(FAbilityTagContainer) || type == typeof(List <FAbilityTagContainer>))
                    {
                        obj = GetTags(ref tag_index, abilityEditorData, type);
                    }
                    else
                    {
                        obj = unity_index < abilityEditorData.child_UnityDatas.Count ? abilityEditorData.child_UnityDatas[unity_index++] : null;
                    }
                    try
                    {
                        if (obj != null)
                        {
                            tFieldInfos[i].SetValue(owner, obj);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(obj + " Set Error!" + e);
                    }
                }
            }
            type = type.BaseType;
        }
    }
コード例 #6
0
    public override void OnInspectorGUI()
    {
        unity_index = 0; string_index = 0; int_index = 0; float_index = 0; bool_index = 0; tag_index = 0;
        // self ability tags
        EditorGUILayout.PropertyField(AbilityScript);
        MonoScript ms = (MonoScript)AbilityScript.objectReferenceValue;

        if (ms != null && IsExtendsType(ms.GetClass(), typeof(AbilityBase)))
        {
            ability.AbilityScript = ms;
        }

        if (ability.AbilityScript == null || !IsExtendsType(ability.AbilityScript.GetClass(), typeof(AbilityBase)))
        {
            EditorGUILayout.LabelField("Please reference a class what extend AbilityBase!");
            return;
        }
        ability.AbilityScript = (MonoScript)AbilityScript.objectReferenceValue;

        bool bIsBuff = IsExtendsType(ability.AbilityScript.GetClass(), typeof(AbilityBuff));

        CreateAbilityTag(ability.abilityTags, EEditor_AbilityTagType.EATT_AbilityTags, "AbilityTags");

        if (bIsBuff)
        {
            DrawBuffUI();
        }
        else
        {
            DrawAbilityUI();
        }
        if (Title("Is Open Block / Cannelable / Immediate :", 0))
        {
            ability.bImmediately              = (bool)CreateBaseData(typeof(bool), "Is Immediately", ability.bImmediately);
            ability.bIsCancelable             = (bool)CreateBaseData(typeof(bool), "Is Cancelable", ability.bIsCancelable);
            ability.bIsBlockingOtherAbilities = (bool)CreateBaseData(typeof(bool), "Is Blocking Other Abilities:", ability.bIsBlockingOtherAbilities);
        }
        if (Title("Other Tags :", 1))
        {
            CreateAbilityTag(ability.cancelAbilitiesWithTags, EEditor_AbilityTagType.EATT_CancelAbilitiesWithTags, "CancelAbilitiesWithTags");
            CreateAbilityTag(ability.blockAbilitiesWithTags, EEditor_AbilityTagType.EATT_BlockAbilitiesWithTags, "BlockAbilitiesWithTags");;
            CreateAbilityTag(ability.activationOwnedTags, EEditor_AbilityTagType.EATT_ActivationOwnedTags, "ActivationOwnedTags");
            CreateAbilityTag(ability.sourceRequiredTags, EEditor_AbilityTagType.EATT_SourceRequiredTags, "SourceRequiredTags");
            CreateAbilityTag(ability.sourceBlockedTags, EEditor_AbilityTagType.EATT_SourceBlockedTags, "SourceBlockedTags");
            CreateAbilityTag(ability.targetRequiredTags, EEditor_AbilityTagType.EATT_TargetRequiredTags, "TargetRequiredTags");
            CreateAbilityTag(ability.targetBlockedTags, EEditor_AbilityTagType.EATT_TargetBlockedTags, "TargetBlockedTags");
        }
        if (Title("Child Infos :", 2))
        {
            CreateScriptInfos(ability.AbilityScript.GetClass());
        }
        //Unity .Asset保存有bug 需要自己主动保存
        EditorGUILayout.Space(10);
        if (GUILayout.Button("保存", GUILayout.MaxWidth(100)))
        {
            AbilityEditorData data       = CreateInstance <AbilityEditorData>();
            FieldInfo[]       fieldInfos = data.GetType().GetFields();
            foreach (FieldInfo info in fieldInfos)
            {
                info.SetValue(data, info.GetValue(ability));
            }
            string path1 = "Assets/Resources/Ability/" + ability.name + ".asset";
            string path2 = "Assets/Resources/Ability/" + ability.name + "_.asset";

            //移动资源这种方式保存
            AssetDatabase.MoveAsset(path1, path2);
            AssetDatabase.MoveAsset(path2, path1);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }