示例#1
0
    public void Setup(BaseUnit unitData, Dictionary <ESkillKey, BaseUnitSkill> skills, string tag, GameObject uiResource, int unitNumber)
    {
        _unitData      = unitData;
        gameObject.tag = tag;
        _isAlly        = gameObject.CompareTag(GameConstants.Tags.UNIT_ALLY);

        _attackTime           = FightManager.SceneInstance.AttackInterval;// 1f / unitData.AttackSpeed;
        _cachedWaitForSeconds = new WaitForSeconds(_attackTime - _model.ShootPositionTimeOffset);

        _skills = skills != null ? skills : new Dictionary <ESkillKey, BaseUnitSkill>();

        if (_isAlly && UnitsConfig.Instance.IsHero(_unitData.Data.Key))
        {
            EventsAggregator.Units.AddListener <ESkillKey>(EUnitEvent.SkillUsage, UseSkill);
        }

        if (_ui == null)
        {
            _ui = (GameObject.Instantiate(uiResource) as GameObject).GetComponent <UnitUI>();
            _ui.transform.SetParent(transform, false);
            _ui.transform.localPosition = _healthBarPosition;
            _ui.transform.localRotation = Quaternion.Euler(GameConstants.CAMERA_ROTATION);
        }
        else
        {
            _ui.Reset();
        }

        if (unitData.DamageTaken > 0)
        {
            _ui.UpdateHealthBar(Mathf.Max(unitData.HealthPoints - unitData.DamageTaken, 0) / (unitData.HealthPoints * 1f));
        }

        if (_isStarted)
        {
            EventsAggregator.Units.Broadcast <BaseUnitBehaviour>(EUnitEvent.ReadyToFight, this);
        }
        //_unitPathfinder.UnitNumber = unitNumber;
    }
示例#2
0
 public void UpdateUI()
 {
     unitUI.UpdateHealthBar();
 }