An open API service indexing awesome lists of open source software.

https://github.com/mmeiburg/unityAndroidSensors

Access to android sensors for Unity
https://github.com/mmeiburg/unityAndroidSensors

android scriptableobject unity unity2d unity3d unity3d-plugin

Last synced: about 1 month ago
JSON representation

Access to android sensors for Unity

Awesome Lists containing this project

README

          

# Android Sensors for Unity

## Overview

Want to get the light sensor output or other cool stuff of your Android smartphone? This package provide you an easy access to the Android _Sensor Manager_. You can get a full list of possible sensors on this [page](https://developer.android.com/guide/topics/sensors/sensors_overview). Each output get stored in a smart variable.

Inspired by the talk of Ryan Hipple's ([twitter](https://twitter.com/roboryantron) | [github](https://github.com/roboryantron)) amazing talk from Unite Austin 2017, you can find part of that in the unity [blog post](https://unity3d.com/how-to/architect-with-scriptable-objects), I wrote a simple event system based on _Scriptable Objects_. These system allows you to drag & drop variables and events around.
## Installation

* Grab unityAndroidSensors.unitypackage from the Releases page for everything you need!
* OR, use the git repository.
* Tested with Unity 2018.3 (New Prefab Workflow) or above.

## What you get

Firstly, You have access to every sensor value of the Android _Sensor Manager_.
Secondly, You get a simple extentable event system which allows you to create _SmartEvents_ and _SmartVars_ in the project view.

## Events and Variables

To create a new _SmartEvent_ or a _SmartVar_ you can use the _Create->SensorPlugin->SmartData_ context menu in the project view.

Sensor Reader

Events are accessible via the ListenSmartEvent Component

Sensor Reader

Here you can listen to _SmartEvent_'s. If a event gets fired all callbacks get invoked.

These are particularly useful for game-level events, such as starting, pausing the game, a player dying etc.

## Variables

Variables are just container of data, with the advantage that you can drag & drop them around like the events.

## Comparators

Float- and IntVars can be compared by the _Float_- or _IntVarComparator_. You can choose to compare with a constant or another smart variable.

Sensor Reader

### Unity Sensor Plugin

The heart of the plugin is the _UnitySensorPlugin_ class. You need the class just once in your scene to get the connection to your Android phone. All sensor readers communicate with the _UnitySensorPlugin_ to get the sensor data as a float[3] array.

### Sensor Reader

The *Sensor Reader* provides you with some option to choose the right sensor, the output type and the update interval (per frame). The output is stored in a _SmartVar_. This can be of type float, int or Vector3.

If you choose int or float you have the option to select the specific axis of the output value, otherwise you get all axis as a _Vector3Var_.

Sensor Reader

## Modifier

If you want to modifiy the output of a sensor before it is written into a _SmartVar_ you can create a modifier which can manipulate the raw float[3] array from the sensor.

An example of a modifier is in the Modifier folder.
It is applied to the pre-configured acceleration sensor.

## New Unity Input System (Update 2019-10-15)
Hey guys with the new input system the plugin is obsolet. https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Sensors.html