Ejemplo n.º 1
0
    //private void SetupAvailableUnits() {
    //    float availableSoldierImageWidth = _availableSoldierInfo.Button.image.rectTransform.rect.width;

    //    EUnitKey[] units = Global.Instance.Player.City.AvailableUnits.ToArray();
    //    _availableSoldiers = new BaseSoldierData[units.Length];
    //    for (int i = 0; i < units.Length; i++) {
    //        _availableSoldiers[i] = UnitsConfig.Instance.GetSoldierData(units[i]);
    //    }

    //    _availableSoldiersInfo = new UIBattleSetupUnitInfo[_availableSoldiers.Length];
    //    _availableSoldiersInfo[0] = _availableSoldierInfo;
    //    for (int i = 0; i < _availableSoldiers.Length; i++) {
    //        if (i > 0) {
    //            _availableSoldiersInfo[i] = (GameObject.Instantiate(_availableSoldierInfo.gameObject) as GameObject).GetComponent<UIBattleSetupUnitInfo>();
    //            _availableSoldiersInfo[i].transform.SetParent(_availableSoldierInfo.transform.parent, false);
    //            _availableSoldiersInfo[i].gameObject.GetComponent<RectTransform>().anchoredPosition = _availableSoldierInfo.gameObject.GetComponent<RectTransform>().anchoredPosition + new Vector2(i * (availableSoldierImageWidth + _offsetImageAvailableSoldiersX), 0f);
    //        }
    //        int iTmp = i;	//some spike: without this array.Length is passed to listener
    //        _availableSoldiersInfo[i].Button.onClick.AddListener(() => { HireSoldier(iTmp); });
    //        _availableSoldiersInfo[i].LblLeadershipCost.text = _availableSoldiers[i].LeadershipCost.ToString();

    //        Image soldierIcon = _availableSoldiersInfo[i].Button.image;
    //        Sprite enemyIconResource = UIResourcesManager.Instance.GetResource<Sprite>(GameConstants.Paths.GetUnitIconResourcePath(_availableSoldiers[i].IconName));
    //        if (enemyIconResource != null)
    //        {
    //            soldierIcon.sprite = enemyIconResource;
    //        }
    //    }
    //}

    void SetupCurrentHero()
    {
        BaseHeroData heroData           = Global.Instance.Player.Heroes.Current.Data;
        Sprite       heroIconBGResource = UIResourcesManager.Instance.GetResource <Sprite>(GameConstants.Paths.GetUnitBGIconResourcePath(heroData.IconName));

        if (heroIconBGResource != null)
        {
            _imgHeroBG.sprite  = heroIconBGResource;
            _imgHeroBG.enabled = true;
        }
        else
        {
            _imgHeroBG.enabled = false;
        }
        Sprite heroIconFGResource = UIResourcesManager.Instance.GetResource <Sprite>(GameConstants.Paths.GetUnitIconResourcePath(heroData.IconName));

        if (heroIconFGResource != null)
        {
            _imgHeroFG.sprite  = heroIconFGResource;
            _imgHeroFG.enabled = true;
        }
        else
        {
            _imgHeroFG.enabled = false;
        }
        _txtHeroName.text = heroData.PrefabName;
        _slotManager.SetHeroTemplate();

        //MultiImageButton multiButton = _imgCurrrentSoldier.GetComponent<MultiImageButton>()
        //_imgCurrrentSoldier.enabled = false;
    }
Ejemplo n.º 2
0
 public void OnDestroy()
 {
     if (_heroData != null)
     {
         UIResourcesManager.Instance.FreeResource(GameConstants.Paths.GetUnitIconResourcePath(_heroData.IconName));
     }
     _heroData = null;
 }
Ejemplo n.º 3
0
	public BaseHero(BaseHeroData data, int experience) : base(data) {
		_data = data;
		AddExperience(experience);

		RecalculateParamsInternal();

		EventsAggregator.Fight.AddListener<BaseUnit>(EFightEvent.AllyDeath, OnAllyDeath);
		EventsAggregator.Fight.AddListener<BaseUnit>(EFightEvent.EnemyDeath, OnEnemyDeath);
	}
Ejemplo n.º 4
0
    public BaseHero(BaseHeroData data, int experience) : base(data)
    {
        _data = data;
        AddExperience(experience);

        RecalculateParamsInternal();

        EventsAggregator.Fight.AddListener <BaseUnit>(EFightEvent.AllyDeath, OnAllyDeath);
        EventsAggregator.Fight.AddListener <BaseUnit>(EFightEvent.EnemyDeath, OnEnemyDeath);
    }
Ejemplo n.º 5
0
    public void Update()
    {
        if (_unitKey == EUnitKey.Idle || _heroData != null)
            return;

        _heroData = UnitsConfig.Instance.GetHeroData(_unitKey);
        string bgPath = _heroData != null ? GameConstants.Paths.GetUnitBGIconResourcePath(_heroData.IconName) 
            : GameConstants.Paths.GetUnitBGIconResourcePath(_unitKey);
        _imgBG.sprite = UIResourcesManager.Instance.GetResource<Sprite>(bgPath);

        string iconPath = _heroData != null ? GameConstants.Paths.GetUnitIconResourcePath(_heroData.IconName) 
            : GameConstants.Paths.GetUnitIconResourcePath(_unitKey);
        _imgUnit.sprite = UIResourcesManager.Instance.GetResource<Sprite>(iconPath);
    }
Ejemplo n.º 6
0
    public void Update()
    {
        if (_unitKey == EUnitKey.Idle || _heroData != null)
        {
            return;
        }

        _heroData = UnitsConfig.Instance.GetHeroData(_unitKey);
        string bgPath = _heroData != null?GameConstants.Paths.GetUnitBGIconResourcePath(_heroData.IconName)
                            : GameConstants.Paths.GetUnitBGIconResourcePath(_unitKey);

        _imgBG.sprite = UIResourcesManager.Instance.GetResource <Sprite>(bgPath);

        string iconPath = _heroData != null?GameConstants.Paths.GetUnitIconResourcePath(_heroData.IconName)
                              : GameConstants.Paths.GetUnitIconResourcePath(_unitKey);

        _imgUnit.sprite = UIResourcesManager.Instance.GetResource <Sprite>(iconPath);
    }
Ejemplo n.º 7
0
    protected override Dictionary <EUnitEqupmentSlot, EItemType[]> CreateSlotsData()
    {
        BaseHeroData heroData = base._data as BaseHeroData;
        Dictionary <EUnitEqupmentSlot, EItemType[]> slotsData = new Dictionary <EUnitEqupmentSlot, EItemType[]>();
        ArrayRO <EUnitEqupmentSlot> availableSlots            = UnitsConfig.Instance.GetUnitEquipmentSlots(this);

        for (int i = 0; i < availableSlots.Length; i++)
        {
            slotsData.Add(availableSlots[i], new EItemType[0]);
            for (int j = 0; j < heroData.AvailableItemTypes.Length; j++)
            {
                if (heroData.AvailableItemTypes[j].SlotKey == availableSlots[i])
                {
                    slotsData[availableSlots[i]] = heroData.AvailableItemTypes[j].AvailableItemTypes.DataCopy;
                    break;
                }
            }
        }
        return(slotsData);
    }
Ejemplo n.º 8
0
    public void SetHeroTemplate()
    {
        UIUnitSlot   firstUISlot = null;
        BaseHeroData heroData    = Global.Instance.Player.Heroes.Current.Data;

        for (int i = 0; i < heroData.SlotTemplate.Length; i++)
        {
            UnitSlot slot = heroData.SlotTemplate[i];
            if (slot != null)
            {
                UIUnitSlot uiSlot = GetUIUnitSlot(slot.Place);
                if (uiSlot != null)
                {
                    BaseSoldierData soldierData = UnitsConfig.Instance.GetSoldierData(slot.Unit);
                    uiSlot.SetUnitData(soldierData);
                    if (firstUISlot == null)
                    {
                        uiSlot.SelectSlot(true);
                        firstUISlot = uiSlot;
                    }
                }
            }
        }
    }
Ejemplo n.º 9
0
 public void OnDestroy()
 {
     if (_heroData != null)
         UIResourcesManager.Instance.FreeResource(GameConstants.Paths.GetUnitIconResourcePath(_heroData.IconName));
     _heroData = null;
 }