Ejemplo n.º 1
0
        public void OnUsableItemsChanged(EventArgs args)
        {
            if (args is UsableItemsChangedEA cui)
            {
                foreach (var usableItem in cui.AddedUsableItems)
                {
                    ChosenUsableItem item = _content.FirstOrDefault(x => x.Item == usableItem.Item);
                    if (item != null)
                    {
                        item.UpdateElement(item.Amount + usableItem.Amount);
                        if (item.Amount > 0)
                        {
                            item.gameObject.SetActive(true);
                            UpdateLayout();
                            if (_content.FindAll(x => x.gameObject.activeSelf == true).Count == 1)
                            {
                                MoveViewRequest(item.transform.localPosition);
                            }
                        }
                    }
                    else
                    {
                        Log.Instance.WriteException(new UsableItemNotFoundException());
                    }
                }

                foreach (var usableItem in cui.RemovedUsableItems)
                {
                    ChosenUsableItem item = _content.FirstOrDefault(x => x.Item == usableItem.Item);
                    if (item != null)
                    {
                        item.UpdateElement(item.Amount - usableItem.Amount);
                        if (item.Amount <= 0)
                        {
                            item.gameObject.SetActive(false);
                            UpdateLayout();
                            if (_content.FindAll(x => x.gameObject.activeSelf == true).Count > 0)
                            {
                                MoveViewRequest(_content.First(x => x.gameObject.activeSelf == true).transform.localPosition);
                            }
                        }
                    }
                    else
                    {
                        Log.Instance.WriteException(new UsableItemNotFoundException());
                    }
                }
            }
            else
            {
                Log.Instance.WriteException(new InvalidEventArgsException());
            }
        }
Ejemplo n.º 2
0
        private void Awake()
        {
            _itemWidth = _chosenUsableItemPrefab.GetComponent <RectTransform>().sizeDelta.x;

            foreach (var usableItem in _usableItemList)
            {
                ChosenUsableItem cui = Instantiate(_chosenUsableItemPrefab, transform);
                cui.gameObject.SetActive(false);
                cui.Initialize(usableItem, 0);
                _content.Add(cui);
            }
            UpdateLayout();
        }
Ejemplo n.º 3
0
 public void OnChooseUsableItem(EventArgs args)
 {
     if (args is ChooseUsableItemEA cui)
     {
         ChosenUsableItem item = _content.FirstOrDefault(x => x.Item == cui.Item);
         if (item != null)
         {
             if (item.gameObject.activeSelf == true)
             {
                 MoveViewRequest(item.transform.localPosition);
             }
         }
     }
     else
     {
         Log.Instance.WriteException(new InvalidEventArgsException());
     }
 }