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); } }
void Awake() { BackEvent = null; HomeEvent = null; PauseEvent = null; ResumeEvent = null; ExitEvent = null; }
IEnumerator EndOfFrame() { while (true) { yield return waitForEndOfFrame; lock (pendingEvents.SyncRoot) { while (pendingEvents.Count > 0) { PhoneEvent phoneEvent = (PhoneEvent) pendingEvents.Dequeue(); ProcessEventAtEndOfFrame(phoneEvent); } } } }
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; } } }
public void OnPhoneEvent(PhoneEvent e) { pendingEvents.Enqueue(e); }
public EmulatorGyroEvent(PhoneEvent.Types.GyroscopeEvent proto) { timestamp = proto.Timestamp; value = new Vector3(proto.X, proto.Y, proto.Z); }
public EmulatorButtonEvent(PhoneEvent.Types.KeyEvent proto) { code = (ButtonCode) proto.Code; down = proto.Action == 0; }
public EmulatorAccelEvent(PhoneEvent.Types.AccelerometerEvent proto) { timestamp = proto.Timestamp; value = new Vector3(proto.X, proto.Y, proto.Z); }
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)); } }
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); }
public static void Fire(Phone phone, PhoneEvent @event) { _stateMachine.FireTrigger(phone, @event); }