Пример #1
0
    // Update is called once per frame
    private void Update()
    {
        if (initialized) // check if safe to update
        {
            for (int i = 0; i < core.GetAbilities().Length; i++)
            {
                // update all abilities
                if (abilities[i] == null || core.GetIsDead())
                {
                    continue;
                }

                // skip ability instead of break because further abilities may not be destroyed
                if (visibleAbilities.Contains(abilities[i]))
                {
                }
                else //abilities[i].UpdateState();
                {
                    abilities[i].Tick();
                }
            }

            if (core.GetIsDead() || core.GetIsInteracting())
            {
                return;
            }

            if (InputManager.GetKeyDown(KeyName.ShowSkills))
            {
                SetCurrentVisible(AbilityTypes.Skills);
            }

            if (InputManager.GetKeyDown(KeyName.ShowSpawns))
            {
                SetCurrentVisible(AbilityTypes.Spawns);
            }

            if (InputManager.GetKeyDown(KeyName.ShowWeapons))
            {
                SetCurrentVisible(AbilityTypes.Weapons);
            }

            if (InputManager.GetKeyDown(KeyName.ShowPassives))
            {
                SetCurrentVisible(AbilityTypes.Passive);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Initialization of the ability handler that is tied to the player
    /// </summary>
    public void Initialize(PlayerCore player, Ability[] displayAbilities = null)
    {
        instance = this;
        core     = player;
        if (displayAbilities == null)
        {
            abilities = core.GetAbilities();                          // Get the core's ability array
        }
        else
        {
            abilities = displayAbilities;
        }
        displayAbs = displayAbilities;
        visibleAbilities.Clear();
        foreach (Ability ab in abilities)
        {
            switch (currentVisibles)
            {
            case AbilityTypes.Skills:
                if (ab as Ability && !(ab as SpawnDrone) && !(ab as WeaponAbility) && !(ab as PassiveAbility))
                {
                    visibleAbilities.Add(ab);
                }
                break;

            case AbilityTypes.Passive:
                if (ab as PassiveAbility)
                {
                    visibleAbilities.Add(ab);
                }
                break;

            case AbilityTypes.Spawns:
                if (ab as SpawnDrone)
                {
                    visibleAbilities.Add(ab);
                }
                break;

            case AbilityTypes.Weapons:
                if (ab as WeaponAbility)
                {
                    visibleAbilities.Add(ab);
                }
                break;
            }
        }

        keybindList = new string[10];
        for (int i = 0; i < 9; i++)
        {
            keybindList[i] = PlayerPrefs.GetString("AbilityHandler_abilityKeybind" + i, (i + 1) + "");
        }

        betterBGboxArray = new Dictionary <string, AbilityButtonScript>();

        tileSpacing = betterBGbox.GetComponent <Image>().sprite.bounds.size.x * 30; // Used to space out the abilities on the GUI

        for (int i = 0; i < visibleAbilities.Count; i++)
        { // iterate through to display all the abilities
            if (visibleAbilities[i] == null)
            {
                break;
            }

            // position them all, do not keep the world position
            var id  = (AbilityID)visibleAbilities[i].GetID();
            var key = id != AbilityID.SpawnDrone ? $"{(int)id}" : GetAHSpawnData((visibleAbilities[i] as SpawnDrone).spawnData.drone);

            if (!betterBGboxArray.ContainsKey(key))
            {
                Vector3 pos = new Vector3(GetAbilityPos(betterBGboxArray.Count), tileSpacing * 0.8F, this.transform.position.z); // find where to position the images
                betterBGboxArray.Add(key,
                                     Instantiate(betterBGbox, pos, Quaternion.identity).GetComponent <AbilityButtonScript>());
                betterBGboxArray[key].transform.SetParent(transform, false); // set parent (do not keep world position)
                betterBGboxArray[key].Init(visibleAbilities[i], i < 9 && currentVisibles != AbilityTypes.Passive ? keybindList[betterBGboxArray.Count - 1] + "" : null, core,
                                           KeyName.Ability0 + i);
            }
            else
            {
                betterBGboxArray[key].AddAbility(visibleAbilities[i]);
            }
        }

        var HUDbgrectTransform = HUDbg.GetComponent <RectTransform>();

        if (visibleAbilities.Count > 0)
        {
            var y = HUDbgrectTransform.anchoredPosition;
            y.x = 0.5f * tileSpacing - 1F * tileSpacing;
            HUDbgrectTransform.anchoredPosition = y;

            var x = HUDbgrectTransform.sizeDelta;
            x.x = GetAbilityPos(betterBGboxArray.Count - 1) + GetAbilityPos(0) - y.x;
            HUDbgrectTransform.sizeDelta = x;
        }
        else
        {
            HUDbgrectTransform.sizeDelta = new Vector2(0, HUDbgrectTransform.sizeDelta.y);
        }

        if (image)
        {
            Destroy(image.gameObject);
        }
        if (displayAbilities == null)
        {
            initialized = true;
        }
        // handler completely initialized, safe to update now
        // if display abilities were passed the handler must not update since it is merely representing
        // some abilities

        visibleAbilityOrder = player.cursave.abilityHotkeys;
        if (visibleAbilityOrder.skills == null)
        {
            visibleAbilityOrder = new AbilityHotkeyStruct()
            {
                skills  = new List <AbilityID>(),
                spawns  = new List <string>(),
                weapons = new List <AbilityID>(),
                passive = new List <AbilityID>()
            };
        }

        if (visibleAbilityOrder.GetList((int)currentVisibles) == null || visibleAbilityOrder.GetList((int)currentVisibles).Count == 0)
        {
            visibleAbilityOrder.GetList((int)currentVisibles).Clear();
            foreach (var i in instance.betterBGboxArray.Keys)
            {
                if (currentVisibles == AbilityTypes.Spawns)
                {
                    (visibleAbilityOrder.GetList((int)currentVisibles) as List <string>).Add(i);
                }
                else
                {
                    (visibleAbilityOrder.GetList((int)currentVisibles) as List <AbilityID>).Add((AbilityID)int.Parse(i));
                }
            }
        }
        else
        {
            Rearrange();
        }
    }