Beispiel #1
0
    private void setBeaconPropertiesAtStart()
    {
        //RestorePlayerPrefs();
        if (bm_Mode == BroadcastMode.unknown)           // first start
        {
            bm_Mode = BroadcastMode.receive;
            bt_Type = BeaconType.iBeacon;
            if (iBeaconServer.region.regionName != "")
            {
                Debug.Log("check iBeaconServer-inspector");
                s_Region = iBeaconServer.region.regionName;
                bt_Type  = iBeaconServer.region.beacon.type;
                if (bt_Type == BeaconType.EddystoneURL)
                {
                    s_UUID = iBeaconServer.region.beacon.UUID;
                }
                else if (bt_Type == BeaconType.EddystoneUID)
                {
                    s_UUID  = iBeaconServer.region.beacon.UUID;
                    s_Major = iBeaconServer.region.beacon.instance;
                }
                else if (bt_Type == BeaconType.iBeacon)
                {
                    s_UUID  = iBeaconServer.region.beacon.UUID;
                    s_Major = iBeaconServer.region.beacon.major.ToString();
                    s_Minor = iBeaconServer.region.beacon.minor.ToString();
                }
            }
            else if (iBeaconReceiver.regions.Length != 0)
            {
                Debug.Log("check iBeaconReceiver-inspector");
                s_Region = iBeaconReceiver.regions[0].regionName;
                bt_Type  = iBeaconReceiver.regions[0].beacon.type;
                if (bt_Type == BeaconType.EddystoneURL)
                {
                    s_UUID = iBeaconReceiver.regions[0].beacon.UUID;
                }
                else if (bt_Type == BeaconType.EddystoneUID)
                {
                    s_UUID  = iBeaconReceiver.regions[0].beacon.UUID;
                    s_Major = iBeaconReceiver.regions[0].beacon.instance;
                }
                else if (bt_Type == BeaconType.iBeacon)
                {
                    s_UUID  = iBeaconReceiver.regions[0].beacon.UUID;
                    s_Major = iBeaconReceiver.regions[0].beacon.major.ToString();
                    s_Minor = iBeaconReceiver.regions[0].beacon.minor.ToString();
                }
            }
        }

        InputDropdown.value = (int)bt_Type;
        bs_State            = BroadcastState.inactive;
        SetBeaconProperties();
        SetBroadcastMode();
        SetBroadcastState();
        Debug.Log("Beacon properties and modes restored");
    }
Beispiel #2
0
        /*
         * public static int ListenPortMod(int value)
         * {
         *  if (!MPInternet.Enabled)
         *      return value;
         *  return 8001; // Exception if olproxy is running...
         * }
         */

        // create receiving socket and also use it for sending by adding it to m_interfaces
        public static bool InitReceiveClient(BroadcastState bs)
        {
            if (!MPInternet.OldEnabled)
            {
                return(false);
            }

            var client = new UdpClient();

            var ep = new IPEndPoint(MPInternet.ServerAddress, 8001);

            if (MPInternet.ServerEnabled)
            {
                // allowing multiple servers doesn't work, only one of the servers receives the packet, and it might be busy etc.
                //client.Client.ExclusiveAddressUse = false;
                //client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, 0);
                //client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                try
                {
                    client.Client.Bind(ep);
                }
                catch (Exception ex)
                {
                    Debug.Log("Internet server setup failed " + ex.ToString());
                    Application.Quit();
                }
            }
            else
            {
                client.Connect(ep);

                // add socket to sending sockets (m_interfaces)
                var    IntfType = typeof(BroadcastState).Assembly.GetType("Overload.BroadcastState").GetNestedType("InterfaceState", BindingFlags.NonPublic);
                object intf     = Activator.CreateInstance(IntfType, new object[] { client, ep.Address, null, new IPAddress(-1) });
                var    intfs    = typeof(BroadcastState).GetField("m_interfaces", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(bs);
                intfs.GetType().GetMethod("Add").Invoke(intfs, new object[] { intf });
            }

            typeof(BroadcastState).GetField("m_receiveClient", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(bs, client);

            /*
             * ICollection intfs = typeof(BroadcastState).GetField("m_interfaces", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(bs) as ICollection;
             * foreach (var intf in intfs) {
             *  var client = intf.GetType().GetField("m_client").GetValue(intf);
             *  typeof(BroadcastState).GetField("m_receiveClient", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(bs, client);
             *  break;
             * }
             */
            return(true);
        }
Beispiel #3
0
    private void setBeaconPropertiesAtStart()
    {
        RestorePlayerPrefs();                                   //載入前次紀錄
        //----------------------------------------------------------------------------------------------------
        s_Region = ck_Region;                                   //讀入設定的區域名
        ck_UUID  = ck_UUID.ToLower();
        s_UUID   = ck_UUID;                                     //讀入設定的UUID
        bm_Mode  = BroadcastMode.receive;                       //廣播模式設定為接收
        bt_Type  = BeaconType.Any;                              //Beacon模式設定為所有類型
        bs_State = BroadcastState.inactive;                     //將廣播狀態設為未啟動
        //----------------------------------------------------------------------------------------------------
        // 若iBeaconServer或Receiver有設定,就優先讀取(目前未使用)

        /*if (bm_Mode == BroadcastMode.unknown) { // first start
         *      bm_Mode = BroadcastMode.receive;
         *      bt_Type = BeaconType.iBeacon;
         *      if (iBeaconServer.region.regionName != "") {
         *              Debug.Log("check iBeaconServer-inspector");
         *              s_Region = iBeaconServer.region.regionName;
         *              bt_Type     = iBeaconServer.region.beacon.type;
         *              if (bt_Type == BeaconType.EddystoneURL) {
         *                      s_UUID = iBeaconServer.region.beacon.UUID;
         *              } else if (bt_Type == BeaconType.EddystoneUID) {
         *                      s_UUID = iBeaconServer.region.beacon.UUID;
         *                      s_Major = iBeaconServer.region.beacon.instance;
         *              } else if (bt_Type == BeaconType.iBeacon) {
         *                      s_UUID = iBeaconServer.region.beacon.UUID;
         *                      s_Major = iBeaconServer.region.beacon.major.ToString();
         *                      s_Minor = iBeaconServer.region.beacon.minor.ToString();
         *              }
         *      } else if (iBeaconReceiver.regions.Length != 0) {
         *              Debug.Log("check iBeaconReceiver-inspector");
         *              s_Region	= iBeaconReceiver.regions[0].regionName;
         *              bt_Type     = iBeaconReceiver.regions[0].beacon.type;
         *              if (bt_Type == BeaconType.EddystoneURL) {
         *                      s_UUID = iBeaconReceiver.regions[0].beacon.UUID;
         *              } else if (bt_Type == BeaconType.EddystoneUID) {
         *                      s_UUID = iBeaconReceiver.regions[0].beacon.UUID;
         *                      s_Major = iBeaconReceiver.regions[0].beacon.instance;
         *              } else if (bt_Type == BeaconType.iBeacon) {
         *                      s_UUID = iBeaconReceiver.regions[0].beacon.UUID;
         *                      s_Major = iBeaconReceiver.regions[0].beacon.major.ToString();
         *                      s_Minor = iBeaconReceiver.regions[0].beacon.minor.ToString();
         *              }
         *      }
         * }
         * bs_State = BroadcastState.inactive;*/
    }
Beispiel #4
0
        public static BroadcastedTransactionState ToBroadcastedTransactionState(this BroadcastState self)
        {
            switch (self)
            {
            case BroadcastState.Broadcasted:
                return(BroadcastedTransactionState.InProgress);

            case BroadcastState.Completed:
                return(BroadcastedTransactionState.Completed);

            case BroadcastState.Failed:
                return(BroadcastedTransactionState.Failed);

            default:
                throw new ArgumentException($"Failed to convert " +
                                            $"{nameof(BroadcastState)}.{Enum.GetName(typeof(BroadcastState), self)} " +
                                            $"to {nameof(BroadcastedTransactionState)}");
            }
        }
Beispiel #5
0
 // the actual patch
 private static Exception Finalizer(object __instance, Exception __exception)
 {
     if (__exception != null)
     {
         Debug.LogFormat("BroadcastState receiveCallback died, telling main thread!");
         try {
             Type           anon0        = FindTypeHelper("c__AnonStorey0");
             Type           anon1        = FindTypeHelper("c__AnonStorey1");
             FieldInfo      _f_ref_field = AccessTools.Field(anon1, "<>f__ref$0");
             FieldInfo      _this_field  = AccessTools.Field(anon0, "$this");
             object         f_ref        = _f_ref_field.GetValue(__instance);
             BroadcastState bs           = (BroadcastState)_this_field.GetValue(f_ref);
             _BroadcastState_m_readLoopExit.SetValue(bs, true);
         } catch (Exception ex) {
             Debug.LogFormat("failed to inform main thread: {0}", ex.ToString());
         }
     }
     return(null);
 }
Beispiel #6
0
        // create receiving socket and also use it for sending by adding it to m_interfaces
        public static bool InitReceiveClient(BroadcastState bs)
        {
            if (!MPInternet.OldEnabled)
            {
                return(false);
            }

            var client = new UdpClient();

            var ep = new IPEndPoint(MPInternet.ServerAddress, 8001);

            if (MPInternet.ServerEnabled)
            {
                // allowing multiple servers doesn't work, only one of the servers receives the packet, and it might be busy etc.
                //client.Client.ExclusiveAddressUse = false;
                //client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, 0);
                //client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                try
                {
                    client.Client.Bind(ep);
                }
                catch (Exception ex)
                {
                    Debug.Log("Internet server setup failed " + ex.ToString());
                    Application.Quit();
                }
            }
            else
            {
                client.Connect(ep);

                // add socket to sending sockets (m_interfaces)
                object intf  = Activator.CreateInstance(_InterfaceState_Type, new object[] { client, ep.Address, null, new IPAddress(-1) });
                var    intfs = _BroadcastState_m_interfaces_Field.GetValue(bs);
                _List_BroadcastState_InterfaceState_Add_Method.Invoke(intfs, new object[] { intf });
            }

            _BroadcastState_m_receiveClient_Field.SetValue(bs, client);

            return(true);
        }
Beispiel #7
0
        protected virtual void SetBroadcastState(BroadcastState state)
        {
            if (state == m_BroadcastState)
            {
                return;
            }

            m_BroadcastState = state;

            try
            {
                if (BroadcastStateChanged != null)
                {
                    this.BroadcastStateChanged(state);
                }
            }
            catch (Exception x)
            {
                ReportError(x.ToString());
            }
        }
    // BroadcastState
    public void btn_StartStop()
    {
        if (!IsBeaconActive)
        {
            iBeaconReceiver.BeaconRangeChangedEvent += OnBeaconRangeChanged;

            var regions = new List <iBeaconRegion> ();
            foreach (var beacon in ApplicationData.IBeaconData)
            {
                regions.Add(new iBeaconRegion("vn.javis.yokaiget" + beacon.index.ToString(), new Beacon(beacon.uuid, Convert.ToInt32(beacon.major_id), Convert.ToInt32(beacon.minor_id))));
            }
            iBeaconReceiver.regions = regions.ToArray();
            iBeaconReceiver.Scan();
            bs_State = BroadcastState.active;
        }
        else
        {
            iBeaconReceiver.Stop();
            iBeaconReceiver.BeaconRangeChangedEvent -= OnBeaconRangeChanged;
            bs_State = BroadcastState.inactive;
        }
    }
Beispiel #9
0
        private static bool Prefix(BroadcastState __instance)
        {
            if (!MPInternet.ServerEnabled)
            {
                return(true);
            }

            var client = new UdpClient();
            var ep     = new IPEndPoint(IPAddress.Any, 8001);

            try
            {
                client.Client.Bind(ep);
            }
            catch (Exception ex)
            {
                Debug.Log("Internet server setup failed " + ex.ToString());
                Application.Quit();
            }

            _BroadcastState_m_receiveClient_Field.SetValue(__instance, client);

            return(false);
        }
Beispiel #10
0
    private void StartStates()
    {
        s_Region = ck_Region;                           //讀入設定的區域名
        ck_UUID  = ck_UUID.ToLower();
        s_UUID   = ck_UUID;                             //讀入設定的UUID
        bm_Mode  = BroadcastMode.receive;               //廣播模式設定為接收
        bt_Type  = BeaconType.Any;                      //Beacon模式設定為任意模式
        bs_State = BroadcastState.inactive;             //將廣播狀態設為未啟動

        ck_Minor1 = 1001;
        ck_Minor2 = 1002;
        ck_Minor3 = 1003;
        ck_Minor4 = 1004;

        /*ck_Minor1 = 22720;
        *  ck_Minor2 = 31168;
        *  ck_Minor3 = 64703;
        *  ck_Minor4 = 59583;*/
        myStr1  = -65;
        myStr2  = -62;
        myStr3  = -57;
        myStr4  = -59;
        envfac  = 2.0;
        sheight = 2.0;
        lheight = 0.5;
        pos12   = 4.4;
        pos23   = 9.6;
        tps     = 1.1f;

        /*if(_B1minor.text != "")
         *      ck_Minor1 = Convert.ToInt32(_B1minor.text);
         * if(_B2minor.text != "")
         *      ck_Minor2 = Convert.ToInt32(_B2minor.text);
         * if(_B3minor.text != "")
         *      ck_Minor3 = Convert.ToInt32(_B3minor.text);
         * if(_B4minor.text != "")
         *      ck_Minor4 = Convert.ToInt32(_B4minor.text);
         * if(_IFB1str.text != "")
         *      myStr1 = Convert.ToInt32(_IFB1str.text);
         * if(_IFB2str.text != "")
         *      myStr2 = Convert.ToInt32(_IFB2str.text);
         * if(_IFB3str.text != "")
         *      myStr3 = Convert.ToInt32(_IFB3str.text);
         * if(_IFB4str.text != "")
         *      myStr4 = Convert.ToInt32(_IFB4str.text);
         * if(_IFEV.text != "")
         *      envfac = Convert.ToDouble(_IFEV.text);
         * if(_IFHT.text != "")
         *      sheight = Convert.ToDouble(_IFHT.text);
         * if(_POS12.text != "")
         *      pos12 = Convert.ToDouble(_POS12.text);
         * else
         *      pos12 = 0.0;
         * if(_POS23.text != "")
         *      pos23 = Convert.ToDouble(_POS23.text);
         * else
         *      pos23 = 0.0;*/
        /*if(_POS34.text != "")
         * pos34 = Convert.ToDouble(_POS34.text);
         * else
         *      pos34 = 0.0;
         * if(_POS14.text != "")
         *      pos14 = Convert.ToDouble(_POS14.text);
         * else
         *      pos14 = 0.0;*/
        //四顆版面積
        //HF_area = pos12 * pos23;
    }
 public void broadcastEndAcked(POIUser u)
 {
     if (CheckEveryoneAckedBroadcastEnd())
     {
         myBroadcastState = BroadcastState.Idle;
     }
 }
        public void broadcastBeginAcked(POIUser u)
        {
            if (CheckEveryoneAckedBroadcastBegin())
            {
                SocketAsyncEventArgs sendArgs = new SocketAsyncEventArgs();

                sendArgs.RemoteEndPoint = new IPEndPoint(broadCastAddr, broadCastPort);
                sendArgs.SetBuffer(curBroadcastFrame[0], 0, curBroadcastFrame[0].Length);
                sendArgs.Completed += new EventHandler<SocketAsyncEventArgs>(broadcastContentPacketCompleted);
                sendArgs.UserToken = new Tuple<int, int>(0, 0);
                broadCastChannel.SendToAsync(sendArgs);

                myBroadcastState = BroadcastState.Broadcasting;
            }
        }
        public unsafe void BroadCastMsg(byte[] msg)
        {
            Console.WriteLine("Start broadcasting " + msg.Length + " bytes");

            PrepareBroadcastFrame(msg);

            numBroadcastBeginAcked = 0;
            numBroadcastEndAcked = 0;

            //Get the begin and end message
            BroadcastBeginPar beginPar = new BroadcastBeginPar();
            beginPar.frameNum = curBroadcastSeqNum;
            beginPar.lastPacketPayload = curFrameLastPktSize;
            beginPar.numPackets = curBroadcastFrame.Count;
            beginPar.packetPayload = payloadSizeUDP;

            BroadcastEndPar endPar = new BroadcastEndPar();
            endPar.frameNum = curBroadcastSeqNum;

            beginMsg = msgParser.getBroadcastBeginMsg(ref beginPar);
            endMsg = msgParser.getBroadcastEndMsg(ref endPar);

            //Send out the begin message
            foreach (POIUser u in POIGlobalVar.UserProfiles.Values)
            {
                u.BroadcastCtrlHandler.resetStateVariables();
                u.SendData(beginMsg, ConType.TCP_CONTROL);
            }

            myBroadcastState = BroadcastState.WaitForBeginAck;
        }
 void Awake()
 {
     bs_State = BroadcastState.inactive;
     BluetoothState.EnableBluetooth();
 }
 protected void SetBroadcastState(BroadcastState state)
 {
     m_BroadcastController.SetBroadcastState(state);
 }
Beispiel #16
0
 // BroadcastState
 public void btn_StartStop()
 {
     //Debug.Log("Button Start / Stop pressed");
     /*** Beacon will start ***/
     if (bs_State == BroadcastState.inactive)
     {
         // ReceiveMode
         if (bm_Mode == BroadcastMode.receive)
         {
             iBeaconReceiver.BeaconRangeChangedEvent += OnBeaconRangeChanged;
             // check if all mandatory propertis are filled
             if (s_Region == null || s_Region == "")
             {
                 input_Region.image.color = Color.red;
                 return;
             }
             if (bt_Type == BeaconType.Any)
             {
                 iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon()) };
             }
             else if (bt_Type == BeaconType.EddystoneEID)
             {
                 iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(BeaconType.EddystoneEID)) };
             }
             else
             {
                 if (s_UUID == null || s_UUID == "")
                 {
                     input_UUID.image.color = Color.red;
                     return;
                 }
                 if (bt_Type == BeaconType.iBeacon)
                 {
                     iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(s_UUID, Convert.ToInt32(s_Major), Convert.ToInt32(s_Minor))) };
                 }
                 else if (bt_Type == BeaconType.EddystoneUID)
                 {
                     iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(s_UUID, "")) };
                 }
                 else if (bt_Type == BeaconType.EddystoneURL)
                 {
                     iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(s_UUID)) };
                 }
             }
             // !!! Bluetooth has to be turned on !!! TODO
             iBeaconReceiver.Scan();
             Debug.Log("Listening for beacons");
         }
         // SendMode
         else
         {
             // check if all mandatory propertis are filled
             if (s_Region == null || s_Region == "")
             {
                 input_Region.image.color = Color.red;
                 return;
             }
             if (bt_Type == BeaconType.EddystoneEID)
             {
                 InputDropdown.image.color = Color.red;
             }
             if (bt_Type == BeaconType.Any)
             {
                 iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon());
             }
             else
             {
                 if (s_UUID == null || s_UUID == "")
                 {
                     input_UUID.image.color = Color.red;
                     return;
                 }
                 if (bt_Type == BeaconType.EddystoneURL)
                 {
                     iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon(s_UUID));
                 }
                 else
                 {
                     if (s_Major == null || s_Major == "")
                     {
                         input_Major.image.color = Color.red;
                         return;
                     }
                     if (bt_Type == BeaconType.EddystoneUID)
                     {
                         iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon(s_UUID, s_Major));
                     }
                     else if (bt_Type == BeaconType.iBeacon)
                     {
                         if (s_Minor == null || s_Minor == "")
                         {
                             input_Major.image.color = Color.red;
                             return;
                         }
                         iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon(s_UUID, Convert.ToInt32(s_Major), Convert.ToInt32(s_Minor)));
                     }
                 }
             }
             // !!! Bluetooth has to be turned on !!! TODO
             iBeaconServer.Transmit();
             Debug.Log("It is on, go sending");
         }
         bs_State = BroadcastState.active;
         img_ButtonBroadcastState.color = Color.red;
     }
     else
     {
         if (bm_Mode == BroadcastMode.receive)              // Stop for receive
         {
             iBeaconReceiver.Stop();
             iBeaconReceiver.BeaconRangeChangedEvent -= OnBeaconRangeChanged;
             removeFoundBeacons();
         }
         else                 // Stop for send
         {
             iBeaconServer.StopTransmit();
         }
         bs_State = BroadcastState.inactive;
         img_ButtonBroadcastState.color = Color.green;
     }
     SetBroadcastState();
     //SavePlayerPrefs();
 }
Beispiel #17
0
 // BroadcastState
 public void btn_StartStop()
 {
     //Debug.Log("Button Start / Stop pressed");
     /*** Beacon will start ***/
     if (bs_State == BroadcastState.inactive)
     {
         StartStates();                              //開始掃描時讀入輸入的參數
         SavePlayerPrefs();                          //儲存輸入的參數
         // ReceiveMode(接收模式)
         if (bm_Mode == BroadcastMode.receive)
         {
             iBeaconReceiver.BeaconRangeChangedEvent += OnBeaconRangeChanged;
             // check if all mandatory propertis are filled
             if (s_Region == null || s_Region == "")
             {
                 return;
             }
             if (bt_Type == BeaconType.Any)
             {
                 iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon()) };
             }
             else if (bt_Type == BeaconType.EddystoneEID)
             {
                 iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(BeaconType.EddystoneEID)) };
             }
             else
             {
                 if (s_UUID == null || s_UUID == "")
                 {
                     return;
                 }
                 if (bt_Type == BeaconType.iBeacon)
                 {
                     iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(s_UUID, Convert.ToInt32(s_Major), Convert.ToInt32(s_Minor))) };
                 }
                 else if (bt_Type == BeaconType.EddystoneUID)
                 {
                     iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(s_UUID, "")) };
                 }
                 else if (bt_Type == BeaconType.EddystoneURL)
                 {
                     iBeaconReceiver.regions = new iBeaconRegion[] { new iBeaconRegion(s_Region, new Beacon(s_UUID)) };
                 }
             }
             // !!! Bluetooth has to be turned on !!!
             iBeaconReceiver.Scan();
             _ssbutton.GetComponentInChildren <Text>().text = "Stop";
         }
         // SendMode(發送模式,目前不使用)
         else
         {
             // check if all mandatory propertis are filled
             if (s_Region == null || s_Region == "")
             {
                 return;
             }
             if (bt_Type == BeaconType.EddystoneEID)
             {
             }
             if (bt_Type == BeaconType.Any)
             {
                 iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon());
             }
             else
             {
                 if (s_UUID == null || s_UUID == "")
                 {
                     return;
                 }
                 if (bt_Type == BeaconType.EddystoneURL)
                 {
                     iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon(s_UUID));
                 }
                 else
                 {
                     if (s_Major == null || s_Major == "")
                     {
                         return;
                     }
                     if (bt_Type == BeaconType.EddystoneUID)
                     {
                         iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon(s_UUID, s_Major));
                     }
                     else if (bt_Type == BeaconType.iBeacon)
                     {
                         if (s_Minor == null || s_Minor == "")
                         {
                             return;
                         }
                         iBeaconServer.region = new iBeaconRegion(s_Region, new Beacon(s_UUID, Convert.ToInt32(s_Major), Convert.ToInt32(s_Minor)));
                     }
                 }
             }
             // !!! Bluetooth has to be turned on !!!
             iBeaconServer.Transmit();
         }
         bs_State = BroadcastState.active;
     }
     else
     {
         if (bm_Mode == BroadcastMode.receive)              // Stop for receive
         {
             iBeaconReceiver.Stop();
             StopStates();                                   //停止掃描時將參數歸零
             iBeaconReceiver.BeaconRangeChangedEvent       -= OnBeaconRangeChanged;
             _ssbutton.GetComponentInChildren <Text>().text = "Start";
         }
         else                 // Stop for send
         {
             iBeaconServer.StopTransmit();
         }
         bs_State = BroadcastState.inactive;
     }
 }
        protected virtual void SetBroadcastState(BroadcastState state)
        {
            if (state == m_BroadcastState)
            {
                return;
            }

            m_BroadcastState = state;

            try
            {
                if (BroadcastStateChanged != null)
                {
                    this.BroadcastStateChanged(state);
                }
            }
            catch (Exception x)
            {
                ReportError(x.ToString());
            }
        }