Skip to content

Commit

Permalink
feat(structure): create initial prefab and user guides
Browse files Browse the repository at this point in the history
The structure of the repository has been created with all the required
files for the package, the prefab and the documentation.
  • Loading branch information
extendreality committed Oct 31, 2019
1 parent 7af5a8e commit 69084ca
Show file tree
Hide file tree
Showing 83 changed files with 17,701 additions and 22 deletions.
8 changes: 8 additions & 0 deletions Documentation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Documentation/HowToGuides.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Documentation/HowToGuides/Installation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 80 additions & 6 deletions Documentation/HowToGuides/Installation/README.md
Expand Up @@ -2,18 +2,92 @@

> * Level: Beginner
>
> * Reading Time: {x} minutes
> * Reading Time: 2 minutes
>
> * Checked with: {platform and version}
> * Checked with: Unity 2018.3.14f1
## Introduction

{Description of how the package is digested into the supported platform.}
The [Unity Input Manager] prefabs provide a collection of wrapped Zinnia Actions that make it possible to listen for keyboard, mouse, button, axis changes on input peripherals via the Unity Input Manager framework. A collection of popular controller mappings is also included to save time on needing to manually build up the required actions to map to a controller type.

The provided controller mapping prefabs map directly to the internal input mappings provided by Unity:

* Xbox Gamepad - [Xbox Gamepad Input Map]
* OpenVR controller - [OpenVR Input Map]
* Oculus Remote - [Oculus Input Map]
* Oculus Touch controller - [Oculus Input Map]
* Windows Mixed Reality controller - [Windows Mixed Reality Input Map]

These prefabs can be included in a [Unity] software project via the [Unity Package Manager].

## Let's Start

### Step X
### Step 1: Creating a Unity project

> You may skip this step if you already have a Unity project to import the package into.
* Create a new project in the Unity software version `2018.3.10f1` (or above) using `3D Template` or open an existing project.

### Step 2: Configuring the Unity project

* Ensure the project `Scripting Runtime Version` is set to `.NET 4.x Equivalent`:
* In the Unity software select `Main Menu -> Edit -> Project Settings` to open the `Project Settings` inspector.
* Select `Player` from the left hand menu in the `Project Settings` window.
* In the `Player` settings panel expand `Other Settings`.
* Ensure the `Scripting Runtime Version` is set to `.NET 4.x Equivalent`.

### Step 3: Adding the package to the Unity project manifest

* Navigate to the `Packages` directory of your project.
* Adjust the [project manifest file][Project-Manifest] `manifest.json` in a text editor.
* Ensure `https://registry.npmjs.org/` is part of `scopedRegistries`.
* Ensure `io.extendreality` is part of `scopes`.
* Add `io.extendreality.tilia.input.unityinputmanager` to `dependencies`, stating the latest version.

A minimal example ends up looking like this. Please note that the version `X.Y.Z` stated here is to be replaced with [the latest released version][Latest-Release] which is currently [![Release][Version-Release]][Releases].
```json
{
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.org/",
"scopes": [
"io.extendreality"
]
}
],
"dependencies": {
"io.extendreality.tilia.input.unityinputmanager": "X.Y.Z",
...
}
}
```
* Switch back to the Unity software and wait for it to finish importing the added package.

### Step 4: Creating the required Unity Input Manager axis definitions.

The Unity software has no way of accessing axis data unless the axis is specifically defined in the Unity Input Manager UI. The axis definitions used by this package can be automatically created by using the `Manage Unity Input Manager Axis Definitions` window.

The `Manage Unity Input Manager Axis Definitions` window should automatically display once the package has loaded into the Unity software.

If it doesn't automatically load then it can be accessed by going to `Main Menu -> Window -> Tilia -> Input -> Manage Unity Input Manager Axis Definitions`.

Click the `Add Input Definitions` button and this will create 18 additional axis definitions that relate to many different popular input peripherals.

### Done

The `Tilia.Input.UnityInputManager` package will now be available in your Unity project `Packages` directory ready for use in your project.

{Describe each step with any useful imagery.}
The package will now also show up in the Unity Package Manager UI. From then on the package can be updated by selecting the package in the Unity Package Manager and clicking on the `Update` button or using the version selection UI.

### Done
[Unity Input Manager]: https://docs.unity3d.com/Manual/class-InputManager.html
[Xbox Gamepad Input Map]: https://wiki.unity3d.com/index.php/Xbox360Controller
[OpenVR Input Map]: https://docs.unity3d.com/Manual/OpenVRControllers.html
[Oculus Input Map]: https://docs.unity3d.com/Manual/OculusControllers.html
[Windows Mixed Reality Input Map]: https://docs.unity3d.com/Manual/Windows-Mixed-Reality-Input.html
[Unity]: https://unity3d.com/
[Unity Package Manager]: https://docs.unity3d.com/Manual/upm-ui.html
[Project-Manifest]: https://docs.unity3d.com/Manual/upm-manifestPrj.html
[Version-Release]: https://img.shields.io/github/release/ExtendRealityLtd/Tilia.Input.UnityInputManager.svg
[Releases]: ../../releases
[Latest-Release]: ../../releases/latest
7 changes: 7 additions & 0 deletions Documentation/HowToGuides/Installation/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Documentation/HowToGuides/UsingTheUnityAxisAction.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions Documentation/HowToGuides/UsingTheUnityAxisAction/README.md
@@ -0,0 +1,97 @@
# Using The Unity Axis Action

> * Level: Beginner
>
> * Reading Time: 10 minutes
>
> * Checked with: Unity 2018.3.14f1
## Introduction

Unity Input Manager Axis Actions tie into the [Unity Input Manager] and emit events when a defined input axis changes value. There are two kinds of Unity Axis Action:

* UnityInputManager.1DAxisAction: listens for changes on a single axis and emits a `float` value for the axis changes.
* UnityInputManager.2DAxisAction: listens for changes on a two axes and emits a `Vector2` value combining both axis changes.

A Unity Axis Action is derived from a [Zinnia] Action and therefore can be injected into any component that accepts a Zinnia Action.

The `Tilia.Input.UnityInputManager` package comes with a prefab Action that wraps the required components to make using a `UnityInputManager.1DAxisAction` much easier.

## Prerequisites

* [Install the Tilia.Input.UnityInputManager] package dependency in to your [Unity] project.
* Create the [Tilia Input Axis Definitions] in your Unity project.

### Step 1

Create a new `Sphere` Unity 3D Object by selecting `Main Menu -> GameObject -> 3D Object -> Sphere`.

We will utilize a 1D axis action to control the position of this sphere in the scene.

### Step 2

Expand the `Tilia Input UnityInputManager` Package directory in the Unity Project window and select then `Packages -> Tilia Input UnityInputManager -> Runtime -> Prefabs -> Actions` directory then drag and drop the `Input.UnityInputManager.1DAxisAction` prefab into the Hierarchy window.

> Be sure to use the `Input.UnityInputManager.1DAxisAction` prefab and not just add the `Unity Input Manager Axis 1D Action` component to a GameObject as the component needs linking to a `MomentProcessor` to function.
![Drag 1D AxisAction To Hierarchy](assets/images/Drag1DAxisActionToHierarchy.png)

### Step 3

We need to define the axis to listen to on the `Unity Input Manager Axis 1D Action` component found within the `Input.UnityInputManager.1DAxisAction` prefab.

There are many different supported axes depending on the input peripheral being used and this package creates an additional 18 axis definitions named `Tilia.Input.UnityInputManager_AxisX` (where X is the number of the axis ranging from 3 to 20 e.g. `Tilia.Input.UnityInputManager_Axis3`).

The Unity software also has 2 default axis values called `Horizontal` and `Vertical` which map to the arrows on the keyboard and the standard joystick movement of an input peripheral.

Select the `Input.UnityInputManager.1DAxisAction` GameObject in the Hierarchy window and update the `Axis Name` parameter on the `Unity Input Manager Axis 1D Action` component to listen changes on the specified axis, in this case type `Horizontal` to listen for changes on the default horizontal axis definition within the Unity Input Manager definitions.

![Change Axis Name To Horizontal](assets/images/ChangeAxisNameToHorizontal.png)

### Step 4

We'll need to create a small script that allows us to change the position of our `Sphere` GameObject to test our newly created `1D Axis Action`.

Create a new `Script` by selecting `Main Menu -> Assets -> Create -> C# Script` in the Unity software and name it `PositionUpdater`.

Copy and paste the below code into the newly created `PositionUpdater` script:

```
using UnityEngine;
public class PositionUpdater : MonoBehaviour
{
public void SetHorizontalPosition(float newPosition)
{
transform.position = Vector3.right * newPosition;
}
}
```

This simply script has a single method called `SetHorizontalPosition` which will take a `float` value that sets the position of the `Transform` that the component is on in relation to the left/right axis of the GameObject.

> The `Vector3.right * newPosition` calculation is basically creating a new Vector3 position value based on the world right direction multiplied by the new position value provided. So if `newPosition` was `0` then `Vector3.right` which is a literal of `(0, 0, 1)` would be `(0, 0, 1) * 0 = (0, 0, 0)` and this would set the GameObject position to a world space of `(0, 0, 0)`. If we passed in a `newPosition` of `1` then the GameObject position will be calculated as `(0, 0, 1)`.
Add the `PositionUpdater` scrip to the `Sphere` GameObject.

### Step 5

Now to set up the `Unity Input Manager Axis 1D Action` component to update the position of the `Sphere` GameObject when the horizontal axis changes (e.g. when we press the left/right arrow keys on the keyboard or move the left thumbstick on an Xbox controller).

Click the `+` symbol in the bottom right corner of the `Value Changed` event parameter in the `Unity Input Manager Axis 1D Action` component and then drag and drop the `Sphere` GameObject into the box that appears and displays `None (Object)`.

Select a `Function` to perform when the `Value Changed` event is emitted. For this example, select `PositionUpdater -> SetHorizontalPosition` (be sure to select `Dynamic float - SetHorizontalPosition` for this example).

![Set Value Changed Listener To PositionUpdater SetHorizontalPosition Method](assets/images/SetValueChangedListenerToPositionUpdaterSetHorizontalPositionMethod.png)

### Done

Play the Unity scene and press the left/right arrow keys on the keyboard and the `Sphere` GameObject will snap to a new position according to the key being pressed. Alternatively, use an Xbox Controller and move the left thumbstick left and right to see the `Sphere` match the position of where the left thumbstick is being pushed to.

This is because when the axis is not being touched at all, the axis value will be `0`. When the axis is fully pushed to the right, the axis value will be `1`. When the axis is fully pushed to the left, the axis value will be `-1`. The value of the axis can be anything between `-1` and `1` depending on the amount of pressure applied to the input peripheral. This axis value is then being passed to control the `X` position of the GameObject in world space.

[Unity Input Manager]: https://docs.unity3d.com/Manual/class-InputManager.html
[Zinnia]: https://github.com/ExtendRealityLtd/Zinnia.Unity
[Install the Tilia.Input.UnityInputManager]: ../Installation/README.md
[Unity]: https://unity3d.com/
[Tilia Input Axis Definitions]: ../Installation/README.md#step-4-creating-the-required-unity-input-manager-axis-definitions

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Documentation/HowToGuides/UsingTheUnityAxisAction/assets.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69084ca

Please sign in to comment.