Пример #1
0
 private void ProcessEventAtEndOfFrame(PhoneEvent e) {
   switch (e.Type) {
     case PhoneEvent.Types.Type.MOTION:
       EmulatorTouchEvent touchEvent = new EmulatorTouchEvent(e.MotionEvent, lastDownTimeMs);
       onTouchEvent(touchEvent);
       if (touchEvent.getActionMasked() == EmulatorTouchEvent.Action.kActionDown) {
         lastDownTimeMs = e.MotionEvent.Timestamp;
       }
       break;
     case PhoneEvent.Types.Type.GYROSCOPE:
       EmulatorGyroEvent gyroEvent = new EmulatorGyroEvent(e.GyroscopeEvent);
       onGyroEvent(gyroEvent);
       break;
     case PhoneEvent.Types.Type.ACCELEROMETER:
       EmulatorAccelEvent accelEvent = new EmulatorAccelEvent(e.AccelerometerEvent);
       onAccelEvent(accelEvent);
       break;
     case PhoneEvent.Types.Type.ORIENTATION:
       EmulatorOrientationEvent orientationEvent =
           new EmulatorOrientationEvent(e.OrientationEvent);
       onOrientationEvent(orientationEvent);
       break;
     case PhoneEvent.Types.Type.KEY:
       EmulatorButtonEvent buttonEvent = new EmulatorButtonEvent(e.KeyEvent);
       onButtonEvent(buttonEvent);
       break;
     default:
       Debug.Log("Unsupported PhoneEvent type: " + e.Type);
       break;
   }
 }
        private void ProcessConnection(TcpClient tcpClient)
        {
            byte[]        buffer = new byte[4];
            NetworkStream stream = tcpClient.GetStream();

            stream.ReadTimeout       = kSocketReadTimeoutMillis;
            tcpClient.ReceiveTimeout = kSocketReadTimeoutMillis;
            while (!shouldStop)
            {
                int bytesRead = blockingRead(stream, buffer, 0, 4);
                if (bytesRead < 4)
                {
                    Debug.LogWarning("Socket read failed, considering socket to have been disconnected.");
                    return;
                }
                int msgLen = unpack32bits(correctEndianness(buffer), 0);

                byte[] dataBuffer = new byte[msgLen];
                bytesRead = blockingRead(stream, dataBuffer, 0, msgLen);
                if (bytesRead < msgLen)
                {
                    Debug.LogWarning("Socket read failed, considering socket to have been disconnected.");
                    return;
                }

                PhoneEvent proto =
                    PhoneEvent.CreateBuilder().MergeFrom(dataBuffer).Build();
                phoneRemote.OnPhoneEvent(proto);

                // Debug.Log(BitConverter.ToString(dataBuffer));
                // Debug.Log(proto.Type);
            }
        }
Пример #3
0
 void Awake()
 {
     BackEvent = null;
     HomeEvent = null;
     PauseEvent = null;
     ResumeEvent = null;
     ExitEvent = null;
 }
Пример #4
0
 IEnumerator EndOfFrame() {
   while (true) {
     yield return waitForEndOfFrame;
     lock (pendingEvents.SyncRoot) {
       while (pendingEvents.Count > 0) {
         PhoneEvent phoneEvent = (PhoneEvent) pendingEvents.Dequeue();
         ProcessEventAtEndOfFrame(phoneEvent);
       }
     }
   }
 }
Пример #5
0
        private void ProcessConnection(TcpClient tcpClient)
        {
            byte[]        buffer = new byte[4];
            NetworkStream stream = tcpClient.GetStream();

            stream.ReadTimeout       = kSocketReadTimeoutMillis;
            tcpClient.ReceiveTimeout = kSocketReadTimeoutMillis;
            while (!shouldStop)
            {
                int bytesRead = blockingRead(stream, buffer, 0, 4);
                if (bytesRead < 4)
                {
                    // Caught by phoneEventSocketLoop.
                    throw new Exception(
                              "Failed to read from controller emulator app event socket." +
                              "\nVerify that the controller emulator app is running.");
                }

                int msgLen = unpack32bits(correctEndianness(buffer), 0);

                byte[] dataBuffer = new byte[msgLen];
                bytesRead = blockingRead(stream, dataBuffer, 0, msgLen);
                if (bytesRead < msgLen)
                {
                    // Caught by phoneEventSocketLoop.
                    throw new Exception(
                              "Failed to read from controller emulator app event socket." +
                              "\nVerify that the controller emulator app is running.");
                }

                PhoneEvent proto =
                    PhoneEvent.CreateBuilder().MergeFrom(dataBuffer).Build();
                phoneRemote.OnPhoneEvent(proto);

                connected = EmulatorClientSocketConnectionState.Connected;

                if (!lastConnectionAttemptWasSuccessful)
                {
                    Debug.Log("Successfully connected to controller emulator app.");

                    // Log first failure after after successful read from event socket.
                    lastConnectionAttemptWasSuccessful = true;
                }
            }
        }
Пример #6
0
 public void OnPhoneEvent(PhoneEvent e)
 {
     pendingEvents.Enqueue(e);
 }
Пример #7
0
 private void ProcessEventAtEndOfFrame(PhoneEvent e)
 {
     switch (e.Type) {
     case PhoneEvent.Types.Type.MOTION:
       EmulatorTouchEvent touchEvent = new EmulatorTouchEvent(e.MotionEvent, lastDownTimeMs);
       onTouchEvent(touchEvent);
       if (touchEvent.getActionMasked() == EmulatorTouchEvent.Action.kActionDown) {
     lastDownTimeMs = e.MotionEvent.Timestamp;
       }
       break;
     case PhoneEvent.Types.Type.GYROSCOPE:
       EmulatorGyroEvent gyroEvent = new EmulatorGyroEvent(e.GyroscopeEvent);
       onGyroEvent(gyroEvent);
       break;
     case PhoneEvent.Types.Type.ACCELEROMETER:
       EmulatorAccelEvent accelEvent = new EmulatorAccelEvent(e.AccelerometerEvent);
       onAccelEvent(accelEvent);
       break;
     case PhoneEvent.Types.Type.ORIENTATION:
       EmulatorOrientationEvent orientationEvent =
       new EmulatorOrientationEvent(e.OrientationEvent);
       onOrientationEvent(orientationEvent);
       break;
     case PhoneEvent.Types.Type.KEY:
       EmulatorButtonEvent buttonEvent = new EmulatorButtonEvent(e.KeyEvent);
       onButtonEvent(buttonEvent);
       break;
     default:
       Debug.Log("Unsupported PhoneEvent type: " + e.Type);
       break;
       }
 }
Пример #8
0
 public void OnPhoneEvent(PhoneEvent e)
 {
     pendingEvents.Enqueue(e);
 }
Пример #9
0
 public EmulatorGyroEvent(PhoneEvent.Types.GyroscopeEvent proto)
 {
     timestamp = proto.Timestamp;
       value = new Vector3(proto.X, proto.Y, proto.Z);
 }
Пример #10
0
 public EmulatorButtonEvent(PhoneEvent.Types.KeyEvent proto)
 {
     code = (ButtonCode) proto.Code;
       down = proto.Action == 0;
 }
Пример #11
0
 public EmulatorAccelEvent(PhoneEvent.Types.AccelerometerEvent proto)
 {
     timestamp = proto.Timestamp;
       value = new Vector3(proto.X, proto.Y, proto.Z);
 }
Пример #12
0
 public EmulatorTouchEvent(PhoneEvent.Types.MotionEvent proto, long lastDownTimeMs)
 {
     action = proto.Action;
       relativeTimestamp =
       (Action)(proto.Action & ACTION_MASK) == Action.kActionDown
       ? 0 : (int) (proto.Timestamp - lastDownTimeMs);
       pointers = new List<Pointer>();
       foreach (PhoneEvent.Types.MotionEvent.Types.Pointer pointer in
       proto.PointersList) {
     pointers.Add(
     new Pointer(pointer.Id, pointer.NormalizedX, pointer.NormalizedY));
       }
 }
Пример #13
0
 public EmulatorOrientationEvent(PhoneEvent.Types.OrientationEvent proto)
 {
     timestamp = proto.Timestamp;
       // Convert from right-handed coordinates to left-handed.
       orientation = new Quaternion(proto.X, proto.Y, -proto.Z, proto.W);
 }
Пример #14
0
 public static void Fire(Phone phone, PhoneEvent @event)
 {
     _stateMachine.FireTrigger(phone, @event);
 }