public void DisplayToyData(SmartPiece sp) { // if ID is null, no smart piece was read if (sp.id != "null") { GetComponent <AudioSource>().Play(); Debug.Log("Scanned SmartPiece Id is " + sp.id); // trim ID to its 7 byte UID string trimmedId = sp.id.Substring(0, 14); // if ID begins with AF, we know its UID is only 4 bytes. Set the last 3 bytes to 0. if (trimmedId[0] == 'A') { trimmedId = trimmedId.Substring(0, 8); trimmedId += "000000"; } // convert UID string to long long id = long.Parse(trimmedId, System.Globalization.NumberStyles.HexNumber); // check if UID is registered in toyManager if (toyManager.toyUidToIndex.ContainsKey(id)) { int index = toyManager.toyUidToIndex[id]; string owner = toyManager.toyTokens[index].Owner; // check if scanned toy's owner is current wallet if (owner == accountManager.Account) { for (int i = 0; i < inventory.ownedToyUids.Count; ++i) { if (id == inventory.ownedToyUids[i]) { inventory.DisplayToy(i); } } } // if scanned toy's owner is not current wallet, reload inventory else { accountManager.SetAccount(owner); inventory.uidToDisplay = id; StartCoroutine(contractService.GetOwnedToys(owner)); StartCoroutine(contractService.GetBalance(owner)); } } // If UID is not registered in toyManager, display unregistered toy else { inventory.DisplayUnregistered(sp.id.Substring(0, 14)); } } // no smartpiece read, only a touch else { Debug.Log("id was null"); } }
void HeartbeatScanAutoFast() { //Debug.Log("HeartbeatScanAutoFast........................."); if (Input.touchCount > 0) { int xCoordinate = 0; int yCoordinate = 0; bool ynFound = false; foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { ynFound = true; xCoordinate = (int)touch.position.x; yCoordinate = canvasHeight - (int)touch.position.y; break; } } if (ynFound == true) { Vector2 p1 = new Vector2(xCoordinate, yCoordinate); Vector2 p2 = new Vector2(xCoordinateLast, yCoordinateLast); float dist = Vector2.Distance(p1, p2); if (dist > distNear || uidLast == "null") { string uid = IssueScan(xCoordinate, yCoordinate); spOrig = new SmartPiece(xCoordinate, canvasHeight - yCoordinate, uid); playTableScript.DisplayToyData(spOrig); string txt = "(" + cntScans + ") fast |||||||||||||||||| SmartPiece IssueScan for "; txt += xCoordinate + ", " + yCoordinate + " |" + uid + "|"; //textLog.text += txt + "\n"; Debug.Log("BlockChainReader " + txt); uidLast = uid; xCoordinateLast = xCoordinate; yCoordinateLast = yCoordinate; } } } Invoke("HeartbeatScanAutoFast", .01f); }
void VerifyNextInTouches() { if (Input.touchCount == 0) { // simulates heartbeat even when no touch, returning nulls for (int n = 0; n < maxNumTouchGos; n++) { lastTouchUids[n] = "null"; lastYnTouchExists[n] = false; } return; } currentTouchN++; if (currentTouchN >= Input.touchCount) { currentTouchN = 0; } Debug.Log("TouchExists ---- currentTouchN: " + currentTouchN + " TouchCount: " + Input.touchCount + "-----------------------------------------"); int xCoordinate = (int)Input.touches[currentTouchN].position.x; int yCoordinate = canvasHeight - (int)Input.touches[currentTouchN].position.y; // silent heartbeat string uid = IssueScan(xCoordinate, yCoordinate); // two consecutive nulls = touch up, non-null uid = touch down, touchup followed by touchdown calls delegate bool ynTouchExists = lastYnTouchExists[currentTouchN]; if (uid != "null") { ynTouchExists = true; } else { if (lastTouchUids[currentTouchN] == "null" && uid == "null") { ynTouchExists = false; } // if (Time.realtimeSinceStartup - lastScanTimestamp > 1f) // { // lastYnTouchExists[currentTouchN] = false; // } } string txtCall = ""; if (lastYnTouchExists[currentTouchN] == false && ynTouchExists == true) { spOrig = new SmartPiece(xCoordinate, canvasHeight - yCoordinate, uid); playTableScript.DisplayToyData(spOrig); Debug.Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TouchExists SmartPieceManager calling delegate >>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); txtCall = " >>>>>>>>>>>>>>>>>>>>>>>"; } Debug.Log("TouchExists ---------------------------------------------"); Debug.Log("TouchExists uids: " + lastTouchUids[currentTouchN] + ", " + uid); Debug.Log("TouchExists touch: " + lastYnTouchExists[currentTouchN] + ", " + ynTouchExists + " " + txtCall); if (currentTouchN >= 0 && currentTouchN < maxNumTouchGos) { lastYnTouchExists[currentTouchN] = ynTouchExists; lastTouchUids[currentTouchN] = uid; } // lastScanTimestamp = Time.realtimeSinceStartup; }