Example #1
0
        public static IEnumerator GetInventory(
            Client client,
            GameSession session,
            string inventoryNamespaceName,
            string inventoryName,
            GetInventoryEvent onGetInventory,
            ErrorEvent onError
            )
        {
            EzInventory inventory;
            {
                AsyncResult <EzGetInventoryResult> result = null;
                yield return(client.Inventory.GetInventory(
                                 r => { result = r; },
                                 session,
                                 inventoryNamespaceName,
                                 inventoryName
                                 ));

                if (result.Error != null)
                {
                    onError.Invoke(
                        result.Error
                        );
                    yield break;
                }

                inventory = result.Result.Item;
            }
            var    itemSets = new List <EzItemSet>();
            string nextPageToken;

            do
            {
                AsyncResult <EzListItemsResult> result = null;
                yield return(client.Inventory.ListItems(
                                 r => { result = r; },
                                 session,
                                 inventoryNamespaceName,
                                 inventoryName
                                 ));

                if (result.Error != null)
                {
                    onError.Invoke(
                        result.Error
                        );
                    yield break;
                }

                itemSets.AddRange(result.Result.Items);
                nextPageToken = result.Result.NextPageToken;
            } while (nextPageToken != null);

            onGetInventory.Invoke(inventory, itemSets);
        }
Example #2
0
        public IEnumerator Run(
            Client client,
            GameSession session,
            string inventoryNamespaceName,
            EzInventoryModel inventoryModel,
            List <EzItemModel> itemModels,
            GetInventoryEvent onGetInventory,
            AcquireEvent onAcquire,
            ConsumeEvent onConsume,
            ErrorEvent onError
            )
        {
            if (_watching)
            {
                throw new InvalidOperationException("already started");
            }

            _watching = true;

            _client  = client;
            _session = session;

            _inventoryNamespaceName = inventoryNamespaceName;
            _inventoryModel         = inventoryModel;
            _itemModels             = itemModels;

            _onGetInventory = onGetInventory;
            _onAcquire      = onAcquire;
            _onConsume      = onConsume;
            _onError        = onError;

            onAcquire.AddListener(AcquireAction);
            onConsume.AddListener(ConsumeAction);

            yield return(Refresh());
        }