コード例 #1
0
        // 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();
        }
コード例 #2
0
 // 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);
         }
     }
 }
コード例 #3
0
ファイル: Applet.cs プロジェクト: githubcatw/UniG
        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();
            }
        }
コード例 #4
0
 // 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));
 }
コード例 #5
0
ファイル: Applet.cs プロジェクト: githubcatw/UniG
 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;
     }
 }
コード例 #6
0
 // 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!");
     }
 }
コード例 #7
0
        // 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());
        }
コード例 #8
0
 // 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!");
         }
     }
 }
コード例 #9
0
 // 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!");
         }
     }
 }
コード例 #10
0
 // Called when the app quits
 private void OnApplicationQuit()
 {
     // Shut down the Arx SDK
     Arx.Shutdown();
 }
コード例 #11
0
ファイル: Applet.cs プロジェクト: githubcatw/UniG
 public void Show(string homepage = "index.html")
 {
     Arx.SetIndex(homepage);
 }
コード例 #12
0
ファイル: Applet.cs プロジェクト: githubcatw/UniG
 public void Upload(StreamingAssetArxFile file)
 {
     Arx.AddFileAs(file.Path, file.Name, file.MIME);
     files.Add(file);
 }
コード例 #13
0
ファイル: Applet.cs プロジェクト: githubcatw/UniG
 public void Upload(ArxFile file)
 {
     Arx.AddFileAs(file.Path, file.Name, file.MIME);
     files.Add(file);
 }