コード例 #1
0
ファイル: demo.cs プロジェクト: bbsyaya/Gear-VR-Android-Game
    void Start()
    {
        //The render scale. Higher numbers = better quality, but trades performance
        m_RenderScale          = 1.5f;
        VRSettings.renderScale = m_RenderScale;
        // Debug.Log("WORKING");



        PNUtils.LoadSkeletonReference(bones, rootTrans, "Robot_", 0);



        _connection = NeuronDataReader.BRConnectTo(ServerIP, int.Parse(ServerPort));



        // Socket status handle
        _OnSocketStatusChanged = new SocketStatusChanged(OnSocketStatusChanged);
        NeuronDataReader.BRRegisterSocketStatusCallback(IntPtr.Zero, _OnSocketStatusChanged);
        // Data receive handle
        _OnFrameDataReceived = new FrameDataReceived(OnFrameDataReceived);
        NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, _OnFrameDataReceived);
        // Data receive handle
        _OnMatchedRigidBodyDataReceived = new MatchedRigidBodyDataReceived(OnMatchedRigidBodyDataReceived);
        NeuronDataReader.BRRegisterMatchedDataCallback(IntPtr.Zero, _OnMatchedRigidBodyDataReceived);
    }
コード例 #2
0
        static NeuronSource CreateConnection(string address, int port, SocketType socketType)
        {
            // Try to make connection with using the native plugin.
            var socket = IntPtr.Zero;

            if (socketType == SocketType.TCP)
            {
                socket = NeuronDataReader.BRConnectTo(address, port);

                if (socket == IntPtr.Zero)
                {
                    Debug.LogError("[Neuron] Connection failed " + address + ":" + port);
                    return(null);
                }

                Debug.Log("[Neuron] Connected " + address + ":" + port);
            }
            else
            {
                socket = NeuronDataReader.BRStartUDPServiceAt(port);

                if (socket == IntPtr.Zero)
                {
                    Debug.LogError("[Neuron] Failed listening " + port);
                    return(null);
                }

                Debug.Log("[Neuron] Started listening " + port);
            }

            // If this is the first connection, register the reader callack.
            if (_sources.Count == 0)
            {
                NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, OnFrameDataReceived);
            }

            // Create a new source.
            var source = new NeuronSource(address, port, socketType, socket);

            lock (_sourcesLock) _sources.Add(source);

            return(source);
        }
コード例 #3
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;
            }
        }
コード例 #4
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;
            }
        }
コード例 #5
0
        static NeuronSource CreateConnection(string address, int port, int commandServerPort, SocketType socketType)
        {
            NeuronSource source                 = null;
            IntPtr       socketReference        = IntPtr.Zero;
            IntPtr       commandSocketReference = IntPtr.Zero;

            if (socketType == SocketType.TCP)
            {
                socketReference = NeuronDataReader.BRConnectTo(address, port);
                if (socketReference != IntPtr.Zero)
                {
                    Debug.Log(string.Format("[NeuronConnection] Connected to {0}:{1}.", address, port));
                }
                else
                {
                    Debug.LogError(string.Format("[NeuronConnection] Connecting to {0}:{1} failed.", address, port));
                }
            }
            else
            {
                socketReference = NeuronDataReader.BRStartUDPServiceAt(port);
                if (socketReference != IntPtr.Zero)
                {
                    Debug.Log(string.Format("[NeuronConnection] Start listening at {0}.", port));
                }
                else
                {
                    Debug.LogError(string.Format("[NeuronConnection] Start listening at {0} failed.", port));
                }
            }

            if (socketReference != IntPtr.Zero)
            {
                if (connections.Count == 0)
                {
                    RegisterReaderCallbacks();
                }

                if (commandServerPort > 0)
                {
                    // connect to command server
                    commandSocketReference = NeuronDataReader.BRConnectTo(address, commandServerPort);
                    if (commandSocketReference != IntPtr.Zero)
                    {
                        Debug.Log(string.Format("[NeuronConnection] Connected to command server {0}:{1}.", address,
                                                commandServerPort));
                    }
                    else
                    {
                        Debug.LogError(string.Format("[NeuronConnection] Connected to command server {0}:{1} failed.",
                                                     address, commandServerPort));
                    }
                }

                source = new NeuronSource(address, port, commandServerPort, socketType, socketReference,
                                          commandSocketReference);
                connections.Add(source.guid, source);
                socketReferencesIndex.Add(socketReference, source);
                if (commandSocketReference != IntPtr.Zero)
                {
                    commandSocketReferenceIndex.Add(commandSocketReference, source);
                }
            }

            return(source);
        }
コード例 #6
0
    static NeuronSource CreateConnection(string address, int port, int commandServerPort, NeuronConnection.SocketType socketType)
    {
        NeuronSource source                 = null;
        IntPtr       socketReference        = IntPtr.Zero;
        IntPtr       commandSocketReference = IntPtr.Zero;

        if (socketType == NeuronConnection.SocketType.TCP)
        {
            socketReference = NeuronDataReader.BRConnectTo(address, port);
            if (socketReference != IntPtr.Zero)
            {
                if (bDebugLog)
                {
                    Debug.Log(string.Format("[NeuronConnection] Connected to {0}:{1}.", address, port));
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.LogError(string.Format("[NeuronConnection] Connecting to {0}:{1} failed.", address, port));
                }
            }
        }
        else
        {
            socketReference = NeuronDataReader.BRStartUDPServiceAt(port);
            if (socketReference != IntPtr.Zero)
            {
                if (bDebugLog)
                {
                    Debug.Log(string.Format("[NeuronConnection] Start listening at {0}.", port));
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.LogError(string.Format("[NeuronConnection] Start listening at {0} failed.", port));
                }
            }
        }

        if (socketReference != IntPtr.Zero)
        {
            if (commandServerPort > 0)
            {
                // connect to command server
                commandSocketReference = NeuronDataReader.BRConnectTo(address, commandServerPort);
                if (commandSocketReference != IntPtr.Zero)
                {
                    if (bDebugLog)
                    {
                        Debug.Log(string.Format("[NeuronConnection] Connected to command server {0}:{1}.", address, commandServerPort));
                    }
                }
                else
                {
                    if (bDebugLog)
                    {
                        Debug.LogError(string.Format("[NeuronConnection] Connected to command server {0}:{1} failed.", address, commandServerPort));
                    }
                }
            }

            source = new NeuronSource(address, port, commandServerPort, socketType, socketReference, commandSocketReference);
        }

        return(source);
    }