예제 #1
0
    private void EffectsUpdate()
    {
        _effectService.Update(Time.deltaTime);

        foreach (var effect in _effectService.Effects.All)
        {
            if (!_effectSlots.ContainsKey(effect))
            {
                _effectSlots.Add(effect, Instantiate(EffectPrefab, _canvasTransform));
            }
        }

        var x     = -270f;
        var y     = -670f;
        var xStep = 95f;

        for (int i = 0; i < _effectSlots.Count; i++)
        {
            var effect     = _effectSlots.Keys.ElementAt(i);
            var gameObject = _effectSlots.Values.ElementAt(i);
            if (!_effectService.Effects.All.Contains(effect))
            {
                Destroy(gameObject);
                _effectSlots.Remove(effect);
                i--;
                continue;
            }

            var slot        = gameObject.GetComponent <InventorySlot>();
            var durationBar = gameObject.GetComponentInChildren <SimpleHealthBar>();

            gameObject.transform.localPosition = new Vector3(x, y);
            x += xStep;
            var sprite = _resourceManager.GetSprite(effect.ImageId);
            slot.SetMainSprite(sprite);
            durationBar.StringFormatValue = 0;
            durationBar.UpdateBar((float)effect.DurationLeft, (float)effect.Duration);
        }
    }