Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Last active October 4, 2017 03:13
Show Gist options
  • Save nkjzm/802d20c88f5bd9da3a5952bcc7cb0491 to your computer and use it in GitHub Desktop.
Save nkjzm/802d20c88f5bd9da3a5952bcc7cb0491 to your computer and use it in GitHub Desktop.
Observable wrapper class of GvrControllerInput class.
using UnityEngine;
namespace UniRx.GvrController
{
public static class ObservableGvrController
{
public static IObservable<GvrConnectionState> StateAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.State).DistinctUntilChanged();
}
public static IObservable<GvrControllerApiStatus> ApiStatusAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.ApiStatus).DistinctUntilChanged();
}
public static IObservable<Quaternion> OrientationAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.Orientation);
}
public static IObservable<Vector3> GyroAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.Gyro);
}
public static IObservable<Vector3> AccelAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.Accel);
}
public static IObservable<bool> IsTouchingAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.IsTouching);
}
public static IObservable<Vector2> TouchDownAsObservable(bool isCenterd = false)
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.TouchDown)
.Select(_ => isCenterd ? GvrControllerInput.TouchPosCentered : GvrControllerInput.TouchPos);
}
public static IObservable<Vector2> TouchUpAsObservable(bool isCenterd = false)
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.TouchUp)
.Select(_ => isCenterd ? GvrControllerInput.TouchPosCentered : GvrControllerInput.TouchPos);
}
public static IObservable<Vector2> TouchPosAsObservable(bool isCenterd = false)
{
return Observable.EveryUpdate().Select(_ => isCenterd ? GvrControllerInput.TouchPosCentered : GvrControllerInput.TouchPos);
}
public static IObservable<bool> RecenteringAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.Recentering);
}
public static IObservable<Unit> RecenteredAsObservable()
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.Recentered).AsUnitObservable();
}
public static IObservable<bool> ClickButtonAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.ClickButton);
}
public static IObservable<Vector2> ClickButtonDownAsObservable(bool isCenterd = false)
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.ClickButtonDown)
.Select(_ => isCenterd ? GvrControllerInput.TouchPosCentered : GvrControllerInput.TouchPos);
}
public static IObservable<Vector2> ClickButtonUpAsObservable(bool isCenterd = false)
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.ClickButtonUp)
.Select(_ => isCenterd ? GvrControllerInput.TouchPosCentered : GvrControllerInput.TouchPos);
}
public static IObservable<bool> AppButtonAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.AppButton);
}
public static IObservable<Unit> AppButtonDownAsObservable()
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.AppButtonDown).AsUnitObservable();
}
public static IObservable<Unit> AppButtonUpAsObservable()
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.AppButtonUp).AsUnitObservable();
}
public static IObservable<bool> HomeButtonAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.HomeButtonState);
}
public static IObservable<Unit> HomeButtonDownAsObservable()
{
return Observable.EveryUpdate().Where(_ => GvrControllerInput.HomeButtonDown).AsUnitObservable();
}
public static IObservable<string> ErrorDetailsAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.ErrorDetails).DistinctUntilChanged().Where(e => string.IsNullOrEmpty(e));
}
public static IObservable<bool> IsChargingAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.IsCharging);
}
public static IObservable<GvrControllerBatteryLevel> BatteryLevelAsObservable()
{
return Observable.EveryUpdate().Select(_ => GvrControllerInput.BatteryLevel).DistinctUntilChanged();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment