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); }
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); } }
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; } }
/// <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); } }
/// <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); } }
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); }
/// <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(); }
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); } } } }