Example #1
0
    void Update()
    {
        if (_connection != IntPtr.Zero)
        {
            if (NeuronDataReader.BRGetSocketStatus(_connection) == SocketStatus.CS_Running)
            {
                _IsSocketConnected = true;
            }
            else
            {
                _IsSocketConnected = false;
            }

            ApplyMotionToTargetSkeleton();
        }

        if (_IsSocketConnected)
        {
            text.text = "CONNECTED";
        }
        else
        {
            text.text = "DISCONNECTED";
        }
    }
Example #2
0
 void OnApplicationQuit()
 {
     if (_connection != IntPtr.Zero)
     {
         if (NeuronDataReader.BRGetSocketStatus(_connection) != SocketStatus.CS_OffWork)
         {
             // disconnect
             NeuronDataReader.BRCloseSocket(_connection);
             _connection = IntPtr.Zero;
         }
     }
 }
        private void btnExitWindows(object sender, RoutedEventArgs e)
        {
            //添加状态判断,当TCP服务未断开时直接点击exit,会先关闭TCP连接再退出,避免程序崩溃
            if (NeuronDataReader.BRGetSocketStatus(sockTCPRef) == SocketStatus.CS_Running)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef);
            }
            //添加状态判断,当UDP服务未断开时直接点击exit,会先关闭UDP连接再退出,避免程序崩溃
            if (sockUDPRef != IntPtr.Zero)
            {
                NeuronDataReader.BRCloseSocket(sockUDPRef);
            }

            Environment.Exit(0);    //立即
        }
        private void btnConnect1_Click(object sender, RoutedEventArgs e)
        {
            if (NeuronDataReader.BRGetSocketStatus(sockTCPRef1) == SocketStatus.CS_Running)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef1);
                sockTCPRef1 = IntPtr.Zero;

                btnConnect1.Content = "Connect";
            }
            else
            {
                sockTCPRef1 = NeuronDataReader.BRConnectTo(txtIP1.Text, int.Parse(txtPort1.Text));
                if (sockTCPRef1 == IntPtr.Zero)
                {
                    string msg = NeuronDataReader.strBRGetLastErrorMessage();
                    MessageBox.Show(msg, "Connection error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                btnConnect1.Content = "Disconnect";

                _frameCount1 = 0;
            }
        }
        private void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            if (NeuronDataReader.BRGetSocketStatus(sockTCPRef) == SocketStatus.CS_Running)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef);
                sockTCPRef = IntPtr.Zero;

                btnConnect.Content = "Connect";
            }
            else
            {
                sockTCPRef = NeuronDataReader.BRConnectTo(txtIP.Text, int.Parse(txtPort.Text));
                if (sockTCPRef == IntPtr.Zero)
                {
                    string msg = NeuronDataReader.strBRGetLastErrorMessage();
                    MessageBox.Show(msg, "Connection error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                NeuronDataReader.BRRegisterAutoSyncParmeter(sockTCPRef, CmdId.Cmd_AvatarCount);
                btnConnect.Content = "Disconnect";

                _frameCount = 0;
            }
        }