// Update is called once per frame void Update() { // Update the gold count in the applet Arx.SetTagContentById("gold", "You have " + gold + " gold."); // Make a temporary string var itemp = ""; // For each item: foreach (var it in items) { // Add it to our string itemp += it; // Add a comma itemp += ", "; } // Set our item text to the temporary string without the trailing comma if (itemp.Length > 2) { itemList.text = itemp.Substring(0, itemp.Length - 2); } else { itemList.text = itemp; } // Check if we can afford all items CanWeAfford(); }
// Callback function for Arx SDK static void SDKCallback(int eventType, int eventValue, string eventArg, IntPtr context) { Debug.Log(eventType + " " + eventArg); // If our event is a device connecting: if (eventType == (int)Arx.Event.Arrival) { // Send our applet's index file Arx.AddStreamingAssetAs("/ArxShopApplet/index.html", "index.html"); // Send all its dependencies Arx.AddStreamingAssetAs("/ArxShopApplet/cannon.png", "cannon.png"); Arx.AddStreamingAssetAs("/ArxShopApplet/sword.png", "sword.png"); // Set our index file // This makes the applet show up and become active in Arx Control Arx.SetIndex("index.html"); } // Else, if it's a tap on a tag: else if (eventType == (int)Arx.Event.TagTapped) { // If the argument starts with "buy": if (eventArg.StartsWith("buy")) { Debug.Log(eventArg); // Get the ID of the item the user bought var item = int.Parse(eventArg.Replace("buy_it_", "")); // Buy it BuyItem(item); } } }
public Applet(ArxFile[] files) { if (_instance != null) { throw new InvalidOperationException("Only one applet can be defined per app. Destroy the other applet."); } _instance = this; Tap = new UnityEvent <string>(); Connected = new UnityEvent(); this.files = new List <ArxFile>(files); Debug.LogWarning("The ArxOOP API is experimental. It might not feature everything available with the Arx class or have issues."); // Create a field for the callback Arx.logiArxCbContext contextCallback; // Set its content and callback funtion contextCallback.arxCallBack = SDKCallback; contextCallback.arxContext = IntPtr.Zero; // Initialize the SDK bool retVal = Arx.Init(ref contextCallback); if (!retVal) { int retCode = Arx.GetLastError(); Debug.LogError("Cannot initialize Arx SDK: " + retCode); return; } // Upload files if needed if (uploadOnConnection) { UploadFiles(); } }
// Start is called before the first frame update void Start() { Arx.Shutdown(); applet = new Applet(appletFiles) { uploadOnConnection = true, }; applet.Connected.AddListener(() => Show()); applet.Tap.AddListener(z => BuyItem(z)); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { // Destroy files array files = null; // Remove all listeners Tap.RemoveAllListeners(); Connected.RemoveAllListeners(); // Shut down Arx integration Arx.Shutdown(); disposedValue = true; } }
// Helper function for buying items static void BuyItem(int item) { // If we can afford it: if (gold >= costs[item]) { // Subtract its cost gold -= costs[item]; // Add it to the item list items.Add(names[item]); } // else: else { // Show a warning that we are too poor Arx.SetTagContentById("cant_afford_" + item, "Cannot afford this weapon!"); } }
// Start is called before the first frame update void Start() { // Create a field for the callback Arx.logiArxCbContext contextCallback; // Set its content and callback funtion contextCallback.arxCallBack = SDKCallback; contextCallback.arxContext = IntPtr.Zero; // Initialize the SDK bool retVal = Arx.LogiArxInit("com.unig.arx.shop", "Weapon Shop", ref contextCallback); if (!retVal) { int retCode = Arx.GetLastError(); Debug.LogError("Cannot initialize Arx SDK: " + retCode); } namesRev = names.ToDictionary(x => x.Value, y => y.Key); StartCoroutine(GiveGold()); }
// Helper function for updating texts void CanWeAfford() { // For each item: for (int item = 1; item < items.Count; item++) { Debug.Log(item); // If we can afford it: if (gold >= costs[item]) { // Clear the affordability warning Arx.SetTagContentById("cant_afford_" + item, ""); } // else: else { // Show a warning that we are too poor Arx.SetTagContentById("cant_afford_" + item, "Cannot afford this weapon!"); } } }
// Helper function for buying items static void BuyItem(string arg) { // If the argument starts with "buy": if (arg.StartsWith("buy")) { Debug.Log(arg); // Get the ID of the item the user bought var item = int.Parse(arg.Replace("buy_it_", "")); // If we can afford it: if (gold >= costs[item]) { // Subtract its cost gold -= costs[item]; // Add it to the item list items.Add(names[item]); } // else: else { // Show a warning that we are too poor Arx.SetTagContentById("cant_afford_" + item, "Cannot afford this weapon!"); } } }
// Called when the app quits private void OnApplicationQuit() { // Shut down the Arx SDK Arx.Shutdown(); }
public void Show(string homepage = "index.html") { Arx.SetIndex(homepage); }
public void Upload(StreamingAssetArxFile file) { Arx.AddFileAs(file.Path, file.Name, file.MIME); files.Add(file); }
public void Upload(ArxFile file) { Arx.AddFileAs(file.Path, file.Name, file.MIME); files.Add(file); }