public static void Start()
        {
            FormMain form = FormMain.GetInstance();

            bool localCameraSign = true;

            foreach (var singleMode in otherModes)
            {
                if (form.GetComboBox_CaptureDevice().SelectedItem.ToString() == singleMode)
                {
                    localCameraSign = false;
                    State           = NowState.TcpIp;
                    form.GetPictureBoxTcpIp().Show();
                    form.GetVideoSourcePlayer().Hide();
                }
            }
            if (localCameraSign)
            {
                form.GetPictureBoxTcpIp().Hide();
                form.GetVideoSourcePlayer().Show();
                State        = NowState.LocalCamera;
                _videoSource = new VideoCaptureDevice(_videoDevices[form.GetComboBox_CaptureDevice().SelectedIndex - 1].MonikerString);
                _videoSource.VideoResolution = _videoSource.VideoCapabilities[form.GetComboBox_CaptureResolution().SelectedIndex];
                form.GetVideoSourcePlayer().VideoSource = _videoSource;
                form.GetVideoSourcePlayer().Start();
            }
        }
Example #2
0
        private async void Init()
        {
            _state = NowState.NotFindServer;

            _localName      = Dns.GetHostName();
            _localAddresses = await Dns.GetHostAddressesAsync(_localName);

            bool multiResult = false;

            foreach (var singleAddress in _localAddresses)
            {
                if (singleAddress.AddressFamily == AddressFamily.InterNetwork)
                {
                    if (!multiResult)
                    {
                        multiResult       = true;
                        _localIpV4Address = singleAddress;
                    }
                    else
                    {
                        throw new MultiIpV4AddressException();
                    }
                }
            }
            _localUdpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _localUdpSocket.Bind(new IPEndPoint(_localIpV4Address, _localUdpPort));
            _localUdpSocket.EnableBroadcast   = true;
            _localUdpSocket.ReceiveBufferSize = 256;

            Console _console = Console.GetInstance();

            _console.Display("Open port: " + _localUdpSocket.LocalEndPoint.ToString());
        }
    //更新目前狀態
    public void SwitchToState(NowState condition)
    {
        _nowStage = condition;

        if (_nowStage == NowState.initialize)//如果目前是要初始化
        {
            StageCondition_Initialize(_initialize);
        }
        else if (_nowStage == NowState.startGame)//開使
        {
            StageCondition_Initialize(_startGame);
        }
        else if (_nowStage == NowState.state)//正在遊戲
        {
            StageCondition_Initialize(_state);
        }
        else if (_nowStage == NowState.AskRestartGame)//要不要重新遊戲
        {
            StageCondition_Initialize(_askRestart);
        }
        else if (_nowStage == NowState.gameOver)//遊戲失敗
        {
            StageCondition_Initialize(_gameOver);
        }
        else if (_nowStage == NowState.gameSuccess)//遊戲成功
        {
            StageCondition_Initialize(_gameSuccess);
        }
        else if (_nowStage == NowState.gameShowResult)//顯示結果
        {
            StageCondition_Initialize(_gameShowResult);
        }
    }
Example #4
0
 public void SetStop()
 {
     _state = NowState.Stop;
     // the behavior of ending
     FormMain.GetInstance().GetButton_BeginEnd().Text  = "Start";
     FormMain.GetInstance().GetButton_Sample().Enabled = false;
     VideoSourceDevice.End();
 }
Example #5
0
 public void SetStart()
 {
     _state = NowState.Start;
     // the behavior of starting
     FormMain.GetInstance().GetButton_BeginEnd().Text  = "End";
     FormMain.GetInstance().GetButton_Sample().Enabled = true;
     VideoSourceDevice.Start();
 }
Example #6
0
 public void SetUdpWaitForConnection(string info = null)
 {
     _state = NowState.WaitForConnection;
     if (String.IsNullOrWhiteSpace(info))
     {
         FormMain.GetInstance().LabelUDP.Text = "UDP: Wait for connection";
     }
     else
     {
         FormMain.GetInstance().LabelUDP.Text = "UDP: Wait for connection Info: " + info;
     }
 }
Example #7
0
 public void SetUdpClose(string info = null)
 {
     _state = NowState.Close;
     if (String.IsNullOrWhiteSpace(info))
     {
         FormMain.GetInstance().LabelUDP.Text = "UDP: Close";
     }
     else
     {
         FormMain.GetInstance().LabelUDP.Text = "UDP: Close Info: " + info;
     }
 }
    private void Tap(RaycastHit info)
    {
        switch (state)
        {
        case NowState.Start:
            FlagHolder = Instantiate(StartFlag, info.point + new Vector3(0, 0.5f, 0), Quaternion.identity);

            MarkerHolder = new List <GameObject>();

            MarkerManager.Instance.StartMarker(FlagHolder);

            state = NowState.Marker;
            break;

        case NowState.Marker:
            if (info.transform.tag == StartFlag.tag)
            {
                MarkerManager.Instance.EndMarker();

                state = NowState.TimeAttack;
            }
            else if (info.transform.tag == Marker.tag)
            {
                break;
            }
            else
            {
                GameObject tmp = Instantiate(Marker, info.point + new Vector3(0, 0.5f, 0), Quaternion.identity);

                MarkerManager.Instance.SetNewMarker(tmp.GetComponent <Node>());
            }

            break;

        case NowState.TimeAttack:

            Destroy(FlagHolder);

            for (int i = 0; i < MarkerHolder.Count; i++)
            {
                if (MarkerHolder[i] == null)
                {
                    continue;
                }

                Destroy(MarkerHolder[i].gameObject);
            }

            state = NowState.Start;
            break;
        }
    }
Example #9
0
 public void SetUdpFindClient(string info = null)
 {
     _state = NowState.Connected;
     try
     {
         if (String.IsNullOrWhiteSpace(info))
         {
             FormMain.GetInstance().LabelUDP.Text = "UDP: Find client, waiting for data";
         }
         else
         {
             FormMain.GetInstance().LabelUDP.Text = "UDP: Find client, waiting for data Info: " + info;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #10
0
        public void SendPictureAsync(string path)
        {
            long contentLen = 0;

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                sock.Connect(_remoteIpEndPoint);
            }
            catch (Exception)
            {
                //Set State Not Find Server
                State = NowState.NotFindServer;
                Console console = Console.GetInstance();
                console.Display("Lost Server");
                return;
            }

            //Send Picture Command
            sock.Send(BitConverter.GetBytes(1L));

            FileStream fs = new FileStream(path, FileMode.Open);

            contentLen = fs.Length;
            sock.Send(BitConverter.GetBytes(contentLen));
            //循环发送文件内容
            while (true)
            {
                byte[] bits = new byte[256];
                int    r    = fs.Read(bits, 0, bits.Length);
                if (r <= 0)
                {
                    break;                         //如果从流中读取完毕,则break;
                }
                sock.Send(bits, r, SocketFlags.None);
            }
            sock.Shutdown(SocketShutdown.Both);
            //由于读取操作会是文件指针产生偏移,最后读取结束之后,要将指针置为0;
            fs.Flush();
            fs.Dispose();
        }
Example #11
0
 public IOCard()
 {
     for (int line_index = 0; line_index < Config.IOCard.Line.Count; line_index++)
     {
         LastState.Add(line_index, false);
         NowState.Add(line_index, false);
         LastStateDate.Add(line_index, null);
     }
     CardNo = USBDASK.UD_Register_Card(USBDASK.USB_7230, (ushort)Config.IOCard.CardNo);
     if (CardNo < 0)
     {
         LogInfo.Log.Fatal("IO 控制板连接失败!");
         Task.Run(() =>
         {
             Task.Delay(1000).Wait();
             OnMoni?.Invoke();
         });
     }
     else
     {
         Start();
     }
 }
 public static void End()
 {
     if (State == NowState.Stop)
     {
         //Reach when when init
     }
     else if (State == NowState.LocalCamera)
     {
         FormMain form = FormMain.GetInstance();
         form.GetVideoSourcePlayer().SignalToStop();
         form.GetVideoSourcePlayer().WaitForStop();
         State = NowState.Stop;
     }
     else if (State == NowState.TcpIp)
     {
         State = NowState.Stop;
     }
     else
     {
         //Never reach
         throw new LogicErrorException();
     }
 }
Example #13
0
        public async Task ListenAsync()
        {
            while (true)
            {
                byte[]   dataSend = Encoding.ASCII.GetBytes("TEST");
                EndPoint ep       = new IPEndPoint(IPAddress.Broadcast, 0);
                _localUdpSocket.SendTo(dataSend, ep);
                await Task.Delay(100);

                byte[]   buffer         = new byte[256];
                EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                Flush();
                _localUdpSocket.ReceiveFrom(buffer, ref remoteEndPoint);
                string   data  = Encoding.ASCII.GetString(buffer);
                string[] parts = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);

                if (parts[0] == "Server")
                {
                    _remoteIpEndPoint = new IPEndPoint(IPAddress.Parse(parts[1]), Convert.ToInt32(parts[2]));
                    break;
                }
                else if (parts[0] == "Motor")
                {
                }
                else
                {
                    throw new LogicErrorException();
                }
            }

            //Set State Find Sever
            State = NowState.FindServer;
            Console console = Console.GetInstance();

            console.Display("Find server: " + _remoteIpEndPoint);
        }
Example #14
0
    /// <summary>
    /// 赋值
    /// </summary>
    /// <param name="index_"> 保存是第几个数组的索引 </param>
    /// <param name="LostNum_"> 多少个这个红包 </param>
    /// <param name="state_"> 是否分享 0什么都没有 1需要分享 2分享成功 </param>
    /// <param name="RedPageName_"> 红包名称 </param>
    /// <param name="BigRedpageID_"> 大红包的ID </param>
    public void OnSetValue(int index_, int LostNum_, int state_, string RedPageName_, NowState From_, int BigRedpageID_ = 0)
    {
        m_iIndex       = index_;
        m_iLostNum     = LostNum_;
        m_iState       = state_;
        m_sRedPageName = RedPageName_;
        m_iRpid        = BigRedpageID_;
        From           = (int)From_;

        if (RedPageName_ == "新手红包")
        {
            //新手红包
            RpCanle.gameObject.SetActive(false);
        }
        else
        {
            //新手红包
            RpCanle.gameObject.SetActive(true);
        }

        Debug.Log("state_" + state_);
        if (state_ == 2)
        {
            RpBackCancle.enabled      = false;
            RpBackCancle_mogu.enabled = false;
            RpCanle.gameObject.SetActive(false);
        }
        else
        {
            RpBackCancle.enabled      = true;
            RpBackCancle_mogu.enabled = true;
            RpCanle.gameObject.SetActive(false);
        }

        //红包界面打开之后是不是还需要分享
        if (m_iState != 0)
        {
            BehindShareForOpenRedPagePanel();
            gameObject.SetActive(true);
        }
    }
 public void ChangeStop()
 {
     //状態をActiveにする
     dollState = NowState.Stop;
     //Debug.Log("Good-By!!" );
 }
 public void ChangeActive()
 {
     //状態をActiveにする
     dollState = NowState.Active;
 }
 // Use this for initialization
 void Start()
 {
     dollState = NowState.Stay;
     owner = OwnerState.None;
     netState = GetComponent<NetworkView>();
 }
Example #18
0
 /// <summary>
 /// 保存值,但是不开启界面
 /// </summary>
 /// <param name="index_"></param>
 /// <param name="LostNum_"></param>
 /// <param name="state_"></param>
 /// <param name="RedPageName_"></param>
 /// <param name="BigRedpageID_"></param>
 public void OnSetValueAndNotOpenPanel(int index_, int LostNum_, int state_, string RedPageName_, NowState From_, int BigRedpageID_ = 0)
 {
     m_iIndex       = index_;
     m_iLostNum     = LostNum_;
     m_iState       = state_;
     m_sRedPageName = RedPageName_;
     m_iRpid        = BigRedpageID_;
     From           = (int)From_;
 }