Example #1
0
 private void OnDestroy()
 {
     if (m_instance == this)
     {
         m_instance = null;
     }
 }
Example #2
0
    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();
    }
Example #3
0
    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();
    }
Example #4
0
    private void Awake()
    {
#if iBeaconDummy
        Debug.LogError("iBeaconDummy is still on! Please remove it from the Scripting Define Symbols.");
#endif
        if (m_instance != null && m_instance != this)
        {
#if UNITY_EDITOR
            DestroyImmediate(this);
#else
            Destroy(this);
#endif
            return;
        }
#if UNITY_EDITOR
        if (!gameObject.name.Equals(BluetoothState.NAME))
        {
            var obj = GameObject.Find(BluetoothState.NAME);
            if (obj == null)
            {
                gameObject.name = BluetoothState.NAME;
            }
            else
            {
        #if !iBeaconDummy
                var component = obj.AddComponent <iBeaconReceiver>();
                component._regions = _regions;
                DestroyImmediate(this);
                return;
        #endif
            }
        }
#endif
        m_instance  = this;
        initialized = false;
        receiving   = false;
#if UNITY_EDITOR
        UpdateDescription();
#endif
    }
Example #5
0
 // assign variables to statics
 void Awake()
 {
     m_instance = this;
 }
Example #6
0
 // assign variables to statics
 void Awake()
 {
     m_instance = this;
 }