Beispiel #1
0
    public void OnVirtualGoodList(string transactionID, List <object> virtualGoods)
    {
        if (transactionID == null)
        {
            Debug.Log("OnVirtualGoodList - transaction ID: <undefined>");
            return;
        }

        Debug.Log("OnVirtualGoodList - transaction ID: " + transactionID);

        m_transactionID = transactionID;

        if (virtualGoods == null)
        {
            Debug.Log("OnVirtualGoodList - virtual good: <undefined_list>");
            return;
        }

        m_consumedVirtualGoodIDs.Clear();

        if (virtualGoods.Count == 0)
        {
            Debug.Log("OnVirtualGoodList - virtual good: <empty_list>");
            return;
        }

        string virtualGoodsString = FuelSDKCommon.Serialize(virtualGoods);

        if (virtualGoodsString == null)
        {
            Debug.Log("OnVirtualGoodList - unable to serialize the virtual good list");
            return;
        }

        Debug.Log("OnVirtualGoodList - virtual goods: " + virtualGoodsString);

        bool consumed = true;

        foreach (object virtualGoodObject in virtualGoods)
        {
            Dictionary <string, object> virtualGood = virtualGoodObject as Dictionary <string, object>;

            if (virtualGood == null)
            {
                Debug.Log("OnVirtualGoodList - invalid virtual good data type: " + virtualGoodObject.GetType().Name);
                consumed = false;
                break;
            }

            object goodIDObject = virtualGood["goodId"];

            if (goodIDObject == null)
            {
                Debug.Log("OnVirtualGoodList - missing expected virtual good ID");
                consumed = false;
                break;
            }

            if (!(goodIDObject is string))
            {
                Debug.Log("OnVirtualGoodList - invalid virtual good ID data type: " + goodIDObject.GetType().Name);
                consumed = false;
                break;
            }

            string goodID = (string)goodIDObject;

            // based on the virtual good ID, update the player
            // inventory with the received virtual good

            m_consumedVirtualGoodIDs.Add(goodID);
        }

        if (!consumed)
        {
            foreach (string goodID in m_consumedVirtualGoodIDs)
            {
                // revert the currently awarded virtual goods for
                // this transaction from the player inventory
                Debug.Log("OnVirtualGoodList - reverting consumed virtual good ID: " + goodID);
            }

            m_consumedVirtualGoodIDs.Clear();
        }

        FuelSDK.AcknowledgeVirtualGoods(transactionID, consumed);
    }