Exemple #1
0
    public ICooldownItem AddCooldown(float duration, Action onTick, Action onEnd, float elapsedTime = 0, float tickInterval = 1)
    {
        ICooldownItem item = new CooldownItem(GetUniqueId(), duration, onTick, onEnd, elapsedTime, tickInterval);

        AddCooldown(item);
        return(item);
    }
Exemple #2
0
    private MyState myState = MyState.Init;                             // Current state for this instance

    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        Debug.Assert(itemSource && cooldownMask && cooldownText && stackObject && stackText, "Wrong initial settings");
        myImage     = GetComponent <Image>();
        sourceImage = itemSource.GetComponent <Image>();
        Debug.Assert(myImage && sourceImage, "Wrong initial settings");
        cooldownSource = itemSource.GetComponent <CooldownItem>();
        stackSource    = itemSource.GetComponent <StackItem>();
        Update();
    }
    private void Awake()
    {
        var sprites = this.GetComponentsInDirectChildrens <UISprite>().OrderBy(c => c.gameObject.name).ToArray();

        _icons = new CooldownItem[sprites.Length];
        for (int i = 0; i < sprites.Length; i++)
        {
            _icons[i] = new CooldownItem(sprites[i]);
            sprites[i].gameObject.SetActive(false);
        }
    }
Exemple #4
0
    private bool inited = false;                                                                                                // Was internal state inited?

    /// <summary>
    /// Init this instance.
    /// </summary>
    public void Init()
    {
        if (inited == false)
        {
            // Set stack amount
            SetStack(stack);
            CooldownItem cooldownItem = GetComponent <CooldownItem>();
            if (cooldownItem != null)
            {
                // Init cooldown item
                cooldownItem.Init();
            }
            inited = true;
        }
    }
Exemple #5
0
    /// <summary>
    /// Uses the item.
    /// </summary>
    public void UseItem()
    {
        bool res = true;

        CooldownItem cooldown = GetComponent <CooldownItem>();

        if (cooldown != null && cooldown.timeLeft > 0f)
        {
            res = false;
        }
        // Use item if there is no active cooldown
        if (res == true)
        {
            // Notify application about item use
            SendMessageUpwards("OnItemUse", gameObject, SendMessageOptions.DontRequireReceiver);
        }
    }
Exemple #6
0
    /// <summary>
    /// Uses the item.
    /// </summary>
    public void UseItem()
    {
        bool res = true;

        CooldownItem cooldown = GetComponent <CooldownItem>();

        if (cooldown != null && cooldown.timeLeft > 0f)
        {
            res = false;
        }
        // Use item if there is no active cooldown
        if (res == true)
        {
            // Notify application about item use
            AccessUtility.SendMessageUpwards(transform, "OnItemUse", gameObject);
        }
    }
Exemple #7
0
    public bool TrackCooldown(string key, float time, CooldownItem.OnCooldownReadyEvent readyHandler)
    {
        if (!_cooldownPool.ContainsKey(key))
        {
            CooldownItem tracker = new CooldownItem(key);
            tracker.OnCooldownReadyTrigger = readyHandler;
            _cooldownPool.Add(key, tracker);
        }

        bool success = _cooldownPool[key].TryStartCounting(time);

        if (!success)
        {
            Debug.LogError(string.Format("fail to track cooldown of key {0}", key));
        }

        return(success);
    }
Exemple #8
0
    /// <summary>
    /// Rage coroutine.
    /// </summary>
    /// <returns>The coroutine.</returns>
    /// <param name="skillCooldown">Skill cooldown.</param>
    private IEnumerator RageCoroutine(CooldownItem skillCooldown)
    {
        // Add temporary attack bonus
        dummyParameters.attackBonus += 10;
        dummyParameters.UpdateParameters();
        // Start skill cooldown
        skillCooldown.StartCooldown();
        ClickItem clickItem = skillCooldown.GetComponent <ClickItem>();

        PlaySound(clickItem.audioClip);
        // Wait for cooldown end
        while (skillCooldown.timeLeft > 0f)
        {
            yield return(new WaitForEndOfFrame());
        }
        // Remove attack bonus
        dummyParameters.attackBonus -= 10;
        dummyParameters.UpdateParameters();
    }
Exemple #9
0
    public void UpdateOfTime(float currentTime)
    {
        // items.Keys.

        for (int i = itemsKey.Count - 1; i >= 0; i--)
        {
            int          id           = itemsKey[i];
            float        lastTickTime = lastTickTimes[id];
            CooldownItem cooldown     = (CooldownItem)items[id];

            float deltaTime = currentTime - lastTickTime;

            if (deltaTime >= cooldown.TickInterval)
            {
                cooldown.Tick(deltaTime);
                lastTickTimes[id] = currentTime;

                if (cooldown.ChackEnd())
                {
                    RemoveCooldown(cooldown);
                }
            }
        }
    }