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
- Host: GitHub
- URL: https://github.com/mmeiburg/unityAndroidSensors
- Owner: mmeiburg
- License: mit
- Created: 2019-01-18T20:12:23.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-15T12:01:30.000Z (about 6 years ago)
- Last Synced: 2024-05-13T01:17:14.594Z (over 1 year ago)
- Topics: android, scriptableobject, unity, unity2d, unity3d, unity3d-plugin
- Language: C#
- Homepage:
- Size: 1.49 MB
- Stars: 17
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- altctrls-info - Android Sensors for Unity - A plugin for using Android sensors with Unity (versions before 2019.1) beyond the ones exposed by the engine. The new Unity's input system makes this much easier on versions after 2019.1. Made by [mmeiburg](https://github.com/mmeiburg). License: MIT. Price: Free. (Contents <!-- omit in toc --> / Game Engine Plugins and Tools)
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.

Events are accessible via the ListenSmartEvent Component

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.

### 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_.

## 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