private static void InternInit(bool shouldLog) { if (initialized) { Scan(); return; } if (m_instance == null) { m_instance = FindObjectOfType <iBeaconReceiver>(); if (m_instance == null) { BluetoothState.Init(); m_instance = GameObject.Find(BluetoothState.NAME).AddComponent <iBeaconReceiver>(); } } Stop(); var state = BluetoothState.GetBluetoothLEStatus(); if (state == BluetoothLowEnergyState.IBEACON_ONLY) { if (regions.Any(region => region.beacon.type == BeaconType.iBeacon)) { Debug.LogWarning(MessageiBeaconOnly); } else { throw new iBeaconException(MessageiBeaconOnly); } } else if (state != BluetoothLowEnergyState.POWERED_ON) { BluetoothState.EnableBluetooth(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { throw new iBeaconException("Bluetooth is off and could not be enabled."); } } #if !UNITY_EDITOR #if UNITY_IOS if (!InitReceiver(iBeaconRegion.regionsToString(m_instance._regions), shouldLog)) { throw new iBeaconException("Receiver initialization failed."); } #elif UNITY_ANDROID GetPlugin().Call( "Init", iBeaconRegion.regionsToString(m_instance._regions), Mathf.FloorToInt(m_instance._detectionTimespan * 1000), Mathf.FloorToInt(m_instance._scanPeriod * 1000), Mathf.FloorToInt(m_instance._betweenScanPeriod * 1000), shouldLog); #endif #endif initialized = true; Scan(); }
private static void InternInit(bool shouldLog) { if (initialized) { Transmit(); return; } if (m_instance == null) { m_instance = FindObjectOfType <iBeaconServer>(); if (m_instance == null) { BluetoothState.Init(); m_instance = GameObject.Find(BluetoothState.NAME).AddComponent <iBeaconServer>(); } } StopTransmit(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { BluetoothState.EnableBluetooth(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { throw new iBeaconException("Bluetooth is off and could not be enabled."); } } if (!checkTransmissionSupported(shouldLog)) { throw new iBeaconException("This device does not support transmitting as a beacon."); } #if !UNITY_EDITOR var sb = new StringBuilder(JsonUtility.ToJson(m_instance._region)); sb.Insert(sb.Length - 1, ",\"_txPower\":"); sb.Insert(sb.Length - 1, m_instance._txPower); #if UNITY_IOS if (!InitBeaconServer(sb.ToString(), shouldLog)) { throw new iBeaconException("Server initialization failed."); } #elif UNITY_ANDROID sb.Insert(sb.Length - 1, ",\"_powerLevel\":"); sb.Insert(sb.Length - 1, (int)m_instance._powerLevel); sb.Insert(sb.Length - 1, ",\"_mode\":"); sb.Insert(sb.Length - 1, (int)m_instance._mode); if (!GetPlugin().Call <bool>("Init", sb.ToString(), shouldLog)) { throw new iBeaconException("Server initialization failed."); } #endif #endif initialized = true; Transmit(); }
private static void InternInit(bool shouldLog) { if (initialized) { Scan(); return; } if (m_instance == null) { m_instance = FindObjectOfType <iBeaconReceiver>(); if (m_instance == null) { BluetoothState.Init(); m_instance = GameObject.Find(BluetoothState.NAME).AddComponent <iBeaconReceiver>(); } } Stop(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { BluetoothState.EnableBluetooth(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { throw new iBeaconException("Bluetooth is off and could not be enabled."); } } #if !UNITY_EDITOR #if UNITY_IOS if (!InitReceiver(iBeaconRegion.regionsToString(m_instance._regions), shouldLog)) { throw new iBeaconException("Receiver initialization failed."); } #elif UNITY_ANDROID GetPlugin().Call( "Init", iBeaconRegion.regionsToString(m_instance._regions), Mathf.FloorToInt(m_instance._androidDetectionTimespan * 1000), shouldLog); #endif #endif initialized = true; Scan(); }