void Update() { if (!isUseUpdate) { return; } context = establishContext(); readersList = getReaders(context, nfc_state == NfcConstant.NFC_STATE_DISCONNECT); readerStateArray = readerStateChange(context, readersList); setState(); if (readerStateArray.Length != 0) { if ((readerStateArray[0].dwEventState & NfcConstant.SCARD_STATE_PRESENT) == NfcConstant.SCARD_STATE_PRESENT) { if (isBeginTouch) { //Debug.Log("タッチし始め"); if (eventNfc != null) { eventNfc(NfcState.Touch); } readCard(context, readerStateArray[0].szReader); SendCommand(context, readerStateArray[0].szReader); isTouchingCard = true; isBeginTouch = false; } //Debug.Log("カードタッチ中"); NfcApi.SCardReleaseContext(context); } else { if (isTouchingCard) { //Debug.Log("カードが離れた"); if (eventNfc != null) { eventNfc(NfcState.Release); } isBeginTouch = true; isTouchingCard = false; } //Debug.Log("カードがタッチされていない"); } } else { isBeginTouch = true; } }
public void start() { IntPtr context = establishContext(); List <string> readersList = getReaders(context); NfcApi.SCARD_READERSTATE[] readerStateArray = initializeReaderState(context, readersList); bool quit = false; while (!quit) { waitReaderStatusChange(context, readerStateArray, 1000); if ((readerStateArray[0].dwEventState & NfcConstant.SCARD_STATE_PRESENT) == NfcConstant.SCARD_STATE_PRESENT) { ReadResult result2 = readCard(context, readerStateArray[0].szReader); SendCommand(context, readerStateArray[0].szReader); quit = true; } } uint ret = NfcApi.SCardReleaseContext(context); }