Beispiel #1
0
 public CShaperPackager()
 {
     header   = new MessageHeader();
     keyboard = new MessageKeyboard();
     rocker   = new MessageRocker();
     gyro     = new MessageGyro();
 }
Beispiel #2
0
        /// <summary>
        /// 输入手柄消息
        /// </summary>
        /// <param name="msg">消息</param>
        private void OnGamepadMessage(GamepadEventArgs args)
        {
            switch (args.Msg.GetMessageType())
            {
            case MessageType.Keyboard:
                MessageKeyboard kb = args.Msg as MessageKeyboard;

                //Debug.Log($"Keyboard  Hid:{kb.Hid} KeyCode:{kb.KeyCode} State:{kb.State}");
                singlePool.Cache(kb.KeyCode, kb.State);
                multiPool.Cache(kb.KeyCode, kb.State);
                break;

            case MessageType.Rocker:
                MessageRocker r = args.Msg as MessageRocker;
                if (Rockers.TryGetValue(r.Hid, out IRocker rocker))
                {
                    rocker.SetMessage(args.Msg);
                }

                //Debug.Log($"Rocker  Hid:{r.Hid} KeyCode:{r.KeyCode} State:{r.State}");

                singlePool.Cache(r.KeyCode, r.State);
                multiPool.Cache(r.KeyCode, r.State);
                break;

            case MessageType.Gyro:
                MessageGyro g = args.Msg as MessageGyro;
                if (Gyros.TryGetValue(g.Hid, out IGyro gyro))
                {
                    gyro.SetMessage(args.Msg);
                }
                break;
            }
        }
Beispiel #3
0
            public void SetMessage(IMessage msg)
            {
                MessageGyro m = msg as MessageGyro;

                g = m.Gravity;
                u = m.UserAcceleration;
                r = m.RotationRate;
                a = m.Attitude;
            }
Beispiel #4
0
        /// <summary>
        /// 陀螺仪消息
        /// </summary>
        public static IMessage Gyro(byte hid)
        {
            MessageGyro msg = new MessageGyro();

            msg.Clear();
            msg.TimeStamp        = SystemTime.LowClientNow();
            msg.Hid              = hid;
            msg.Gravity          = Input.gyro.gravity;
            msg.RotationRate     = Input.gyro.rotationRate;
            msg.UserAcceleration = Input.gyro.userAcceleration;
            msg.Attitude         = Input.gyro.attitude;

            return(msg);
        }
Beispiel #5
0
        /// <summary>
        /// 接收手柄消息
        /// </summary>
        /// <param name="msg"></param>
        private void OnGamepadMessage(IMessage msg)
        {
            switch (msg.GetMessageType())
            {
            case MessageType.Keyboard:
                MessageKeyboard kb = msg as MessageKeyboard;

                if (kb.State == KeyboardState.KeyDown)
                {
                    keyDownPool.Add(kb.KeyCode);
                    keyPressPool.Add(kb.KeyCode);
                }
                else if (kb.State == KeyboardState.KeyUp)
                {
                    keyUpPool.Add(kb.KeyCode);

                    if (keyPressPool.Contains(kb.KeyCode))
                    {
                        keyPressPool.Remove(kb.KeyCode);
                    }
                }
                break;

            case MessageType.Rocker:
                MessageRocker r = msg as MessageRocker;

                if (r.State == KeyboardState.KeyDown)
                {
                    keyDownPool.Add(r.KeyCode);
                    keyPressPool.Add(r.KeyCode);
                }
                else if (r.State == KeyboardState.KeyUp)
                {
                    keyUpPool.Add(r.KeyCode);

                    if (keyPressPool.Contains(r.KeyCode))
                    {
                        keyPressPool.Remove(r.KeyCode);
                    }
                }

                Rocker rocker;
                if (Rockers.TryGetValue(r.DevID, out rocker))
                {
                    rocker.X = r.Rx;
                    rocker.Y = r.Ry;
                }
                break;

            case MessageType.Gyro:
                MessageGyro g = msg as MessageGyro;

                Gyro gyro;
                if (Gyros.TryGetValue(g.DevID, out gyro))
                {
                    gyro.Gravity          = g.Gravity;
                    gyro.Attitude         = g.Attitude;
                    gyro.RotationRate     = g.RotationRate;
                    gyro.UserAcceleration = g.UserAcceleration;
                }
                break;
            }
        }