예제 #1
0
        private List <PartGridElement> LoadParts(List <ReferencePart> parts, int row, Part equippedPart)
        {
            Vector2 elementSize            = _partGridElementPrefab.GetComponent <RectTransform>().sizeDelta;
            List <PartGridElement> pgeList = new List <PartGridElement>(parts.Count);

            for (int i = 0; i < parts.Count; ++i)
            {
                PartGridElement pge = Instantiate(_partGridElementPrefab, transform);
                pge.transform.localPosition = new Vector2(i * elementSize.x + i * _spacingBetweenElements.x, -row * elementSize.y - (row + 1) * _spacingBetweenElements.y);
                pge.Initialize(this, parts[i], row);

                if (_playerMoney >= parts[i].Cost)
                {
                    pge.Refresh(EOfferState.Available);
                }
                else
                {
                    pge.Refresh(EOfferState.Unavailable);
                }

                if (equippedPart != null)
                {
                    if (equippedPart.Id == parts[i].Id)
                    {
                        pge.Refresh(EOfferState.Bought);
                    }
                }

                pgeList.Add(pge);
            }

            return(pgeList);
        }
예제 #2
0
        public void BuyPart(PartGridElement element)
        {
            if (element.ReferencePart.Cost <= _playerMoney.Value)
            {
                foreach (var elem in _partGridElements[element.Row])
                {
                    if (elem.CurrentState == EOfferState.Bought)
                    {
                        if (_playerMoney >= elem.ReferencePart.Cost)
                        {
                            elem.Refresh(EOfferState.Available);
                        }
                        else
                        {
                            elem.Refresh(EOfferState.Unavailable);
                        }
                    }
                }

                element.Refresh(EOfferState.Bought);
                _updatePlayerData.Raise(new UpdatePlayerDataEA()
                {
                    MoneyChange = -element.ReferencePart.Cost
                });
                _changeEquipment.Raise(new ChangeEquipmentEA()
                {
                    PartsToEquip = new List <Part>()
                    {
                        element.ReferencePart.CreatePart(1f)
                    }
                });
                _buyPart.Play();

                for (int row = 0; row < _partGridElements.Count; ++row)
                {
                    foreach (var elem in _partGridElements[row])
                    {
                        if (elem.CurrentState == EOfferState.Bought)
                        {
                            continue;
                        }

                        if (_playerMoney >= elem.ReferencePart.Cost)
                        {
                            elem.Refresh(EOfferState.Available);
                        }
                        else
                        {
                            elem.Refresh(EOfferState.Unavailable);
                        }
                    }
                }
            }
        }