1

私は Unityscript を使用して Unity でレース ゲームを作成しており、レゴ マインドストーム EV3 ロボットで操舵を行いました。ロボットから Bluetooth でゲームに情報を送信できるようにしましたが、その方法がわかりません。Bluetooth を実行して C# を動作させるためのコードは既にありますが、それを unityscript に変換する方法を知る必要があることはわかっています。私はすでにグーグルでそれを見つけようとしましたが、ロボットをハックするためのソフトウェアを入手しただけのようですが、ステアを接続するためのユニティスクリプトでコードを作成することはできませんでした。

以下に C# コードを示します。

        // EV3: The EV3Messenger is used to communicate with the Lego EV3.
private EV3Messenger ev3Messenger;


            // EV3: Create an EV3Messenger object which you can use to talk to the EV3.
            ev3Messenger = new EV3Messenger();

            // EV3: Connect to the EV3 serial port over Bluetooth.
            //      If the program 'hangs' on a call to ev3Messenger.Connect, 
            //      then your EV3 is not paired with your PC yet/anymore. 
            //      To pair: Remove the EV3 from the Windows Bluetooth device list and add it again.
            ev3Messenger.Connect("COM3"); // Hardcoded serial port: put the serial port 
            // of the Bluetooth connection to your EV3 here!
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // Unload any non ContentManager content here

            // EV3: Disconnect
            if (ev3Messenger.IsConnected)
            {
                ev3Messenger.Disconnect();
            }
        }

                // EV3: send Brake message to mailbox with name "MakeNoise"
                if (ev3Messenger.IsConnected)
                {
                    ev3Messenger.SendMessage("MakeNoise", "Brake");
                }


            // Game can be controlled by both the arrow keys and the Steer, gas and brake paddle of                         the connected EV3
            UpdatePaddlePositionUsingKeys();
            UpdatePaddlePositionUsingEV3();

            base.Update(gameTime);
        }
///Steer update
        private void UpdatePaddlePositionUsingEV3()
        {
            if (ev3Messenger.IsConnected)
            {
                // EV3: Receive a new command from mailbox "COMMAND" of the EV3
                // and use it to change the direction of the paddle or to exit the game.
                EV3Message message = ev3Messenger.ReadMessage();
                if (message != null
                    && message.MailboxTitle == "Command")
                {
                    if (message.ValueAsText == "")
                    {
                    }

                    {
                        ev3Messenger.Disconnect();
                        Exit();
                    }
                }
            }
        }

これを行う方法、またはさらに支援する方法をどこで見つけることができるかを知っていただければ幸いです。私がインスピレーションを得た小さな卓球ゲームの元のコードが必要な場合は、コメントしてください。

あなたが私を助けてくれることを願っています。

4

2 に答える 2

2

EV3 ファームウェアに関するドキュメントへの便利なリンクを次に示します。

特に、直接コマンドを送信する方法を学び、それを使用してBluetooth メールボックスを読み書きする必要があります。

javascript を使用して COM ポート自体と通信するには、少し検索するだけです。たとえば、かなりの数の異なるアイデアを持つこの SO の質問を見つけました。

于 2014-10-25T17:54:47.767 に答える