コード例 #1
0
    private void SetInfo(BuildingInfo info)
    {
        _currentInfo = info;
        if (_currentInfo == null)
        {
            return;
        }

        _title.text           = info.Cfg.BuildingName;
        _txtLevel.text        = Str.Format("UI_LEVEL", info.Level);
        _desc.text            = info.Cfg.BuildingDescription;
        _buildingImage.sprite = ResourceManager.Instance.GetBuildingIcon(info.ConfigID);

        // 如果建筑正在升级,不显示升级按钮
        _btnLevelUp.gameObject.SetActive(!_currentInfo.IsInBuilding());

        _maxContainValue.text = _currentInfo.GetMaxContainValue().ToString();
        _levelupTime.text     = Utils.GetCountDownString(Utils.GetSeconds(_currentInfo.CfgLevel.UpgradeTime));

        switch (_currentInfo.BuildingType)
        {
        case CityBuildingType.HOUSE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            _imageProduce.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            _imageProduce.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            _imageProduce.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;

        case CityBuildingType.MONEY_STORAGE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE_STORAGE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD_STORAGE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;
        }

        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo != null)
        {
            _produceValue.text = pbinfo.GetUnitProduceValue().ToString();

            if (pbinfo.IsProduceFull())
            {
                // 资源满了,提示升级建筑
                _txtFull.text = Str.Format("UI_MSG_RES_FULL", _currentInfo.GetContainerBuildingName(), _currentInfo.GetResName());
                _txtFull.gameObject.SetActive(true);
            }
            else
            {
                _txtFull.gameObject.SetActive(false);
            }

            _txtMaxContain.text = Str.Get("UI_CITY_BUILDING_MAX_CONTAIN");
            _txtProduceText.gameObject.SetActive(true);
        }
        else
        {
            _txtProduceText.gameObject.SetActive(false);
            _txtFull.gameObject.SetActive(false);
            _txtMaxContain.text = Str.Get("UI_CITY_BUILDING_CONTAIN");
        }
    }
コード例 #2
0
    private void SetInfo(BuildingInfo info)
    {
        _currentInfo = info;
        if (_currentInfo == null)
        {
            return;
        }

        _title.text           = _currentInfo.Cfg.BuildingName;// string.Format(Str.Get("UI_CITY_BUILDING_LEVELUP"), _currentInfo.Cfg.BuildingName, _currentInfo.Level + 1);
        _maxContainValue.text = _currentInfo.GetMaxContainValue().ToString();
        _txtLevel.text        = Str.Format("UI_LEVEL", info.Level);
        _desc.text            = _currentInfo.Cfg.BuildingDescription;
        _buildingImage.sprite = ResourceManager.Instance.GetBuildingIcon(info.ConfigID);

        if (info.BuildingType == CityBuildingType.TROOP)
        {
            // 如果是兵营的话 显示最大人口
            _maxContainText.text = Str.Get("UI_CITY_BUILDING_MAX_SPACE");
        }
        else
        {
            // 显示最大容量
            _maxContainText.text = Str.Get("UI_CITY_BUILDING_MAX_CONTAIN");
        }

        int maxContainAddValue = _currentInfo.GetNextMaxContainValue();

        if (maxContainAddValue > 0)
        {
            _maxContainAddValue.gameObject.SetActive(true);
            _maxContainAddValue.text = string.Format("(+{0})", maxContainAddValue);
        }
        else
        {
            _maxContainAddValue.gameObject.SetActive(false);
        }

        _levupTime.text = Utils.GetCountDownString(_currentInfo.GetLevelUpCD());

        int quickCost = _currentInfo.GetQuickLevelUpCost(false);

        _levupNowCost.text  = quickCost.ToString();
        _levupNowCost.color = UserManager.Instance.Gold < quickCost ? Color.red : Color.white;

        _levupStoneCost.text  = _currentInfo.CfgLevel.CostStone.ToString();
        _levupStoneCost.color = UserManager.Instance.Stone < _currentInfo.CfgLevel.CostStone ? Color.red : Color.white;
        _levupWoodCost.text   = _currentInfo.CfgLevel.CostWood.ToString();
        _levupWoodCost.color  = UserManager.Instance.Wood < _currentInfo.CfgLevel.CostWood ? Color.red : Color.white;

        switch (_currentInfo.BuildingType)
        {
        case CityBuildingType.HOUSE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            _produceImage.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            _produceImage.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            _produceImage.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;

        case CityBuildingType.MONEY_STORAGE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE_STORAGE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD_STORAGE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;

        case CityBuildingType.TROOP:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.SOLDIER);
            break;
        }
        _maxContainImage.SetNativeSize();
        _produceImage.SetNativeSize();

        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo != null)
        {
            // 资源生产建筑
            _productValue.text = pbinfo.GetUnitProduceValue().ToString();

            int produceAddValue = pbinfo.GetNextProduceValue();
            if (produceAddValue > 0)
            {
                _productAddValue.gameObject.SetActive(true);
                _productAddValue.text = string.Format("(+{0})", produceAddValue);
            }
            else
            {
                _productAddValue.gameObject.SetActive(false);
            }
        }
        else
        {
            _txtProductText.gameObject.SetActive(false);
            _levelUpText.transform.position = _txtProductText.transform.position;
        }
    }