65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Viveport;
|
|
|
|
public class ViveportDemo_MainThreadDispatcher : MonoBehaviour
|
|
{
|
|
private class ThisCallbackWillNotWorkFine : IAPurchase.IAPurchaseListener
|
|
{
|
|
public override void OnSuccess(string pchCurrencyName)
|
|
{
|
|
myApiResultText.text = string.Format("The Currency is: {0}", pchCurrencyName);
|
|
}
|
|
}
|
|
|
|
private class ThisCallbackWillWorkFine_01 : IAPurchase.IAPurchaseListener
|
|
{
|
|
public override void OnSuccess(string pchCurrencyName)
|
|
{
|
|
Action action = delegate
|
|
{
|
|
myApiResultText.text = string.Format("The Currency is: {0}", pchCurrencyName);
|
|
};
|
|
MainThreadDispatcher.Instance().Enqueue(action);
|
|
}
|
|
}
|
|
|
|
private class ThisCallbackWillWorkFine_02 : IAPurchase.IAPurchaseListener
|
|
{
|
|
public override void OnSuccess(string pchCurrencyName)
|
|
{
|
|
MainThreadDispatcher.Instance().Enqueue(ShowResult(pchCurrencyName));
|
|
}
|
|
|
|
private IEnumerator ShowResult(string pchCurrencyName)
|
|
{
|
|
myApiResultText.text = string.Format("The Currency is: {0}", pchCurrencyName);
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public Text uiText;
|
|
|
|
private static Text myApiResultText;
|
|
|
|
private static readonly string appId = "Your APP ID";
|
|
|
|
private static readonly string apiKey = "Your API KEY";
|
|
|
|
private void Start()
|
|
{
|
|
myApiResultText = uiText;
|
|
Api.Init(InitCallback, appId);
|
|
}
|
|
|
|
private void InitCallback(int errorCode)
|
|
{
|
|
if (errorCode == 0)
|
|
{
|
|
IAPurchase.IsReady(new ThisCallbackWillWorkFine_01(), apiKey);
|
|
}
|
|
}
|
|
}
|