Scripting with Litho

The Litho component acts as an interface between Litho hardware and Unity. It connects to Litho devices and forwards information about them to your Unity apps, via Litho events. Note that the Litho emulator can also produce (fake) Litho events in response to your mouse interactions within the Unity Editor’s Game view.

Manipulable

The Manipulable component represents that the Unity GameObject it is attached to can be interacted with by the Litho interaction system. It has some basic properties (listed below) that modify how it works, as well as a comprehensive range of events.

This component can be used to respond to Manipulator interactions directly, but it is designed to be inherited from. Several Litho classes already inherit from Manipulable , and can be used as examples: Positionable , Movable , Scalable , Rotatable , Selectable , Hidable .

Manipulable components may be attached to objects in different configurations and with different targets to achieve different interactions - refer to the LithoShowcase scene for a variety of examples.

Manipulable GameObjects must have at least one Unity Collider component attached to them or attached to one of their child GameObjects in order for a Manipulation to occur. Additionally, the Collider (s) must be assigned to a Unity physics layer that is not ignored by a given Manipulator in order for that Manipulator to interact with the Manipulable .

Manipulator

The Manipulator component represents that the Unity GameObject it is attached to can establish interactions with Manipulable objects by triggering events on them. It has some basic properties (listed below) that modify how it works. The Manipulator class itself is abstract, so cannot be attached to objects directly, but it is inherited by a selection of different implementations, including the Pointer class, which extends its functionality to work using the Litho hardware as input.

Manipulation

The Manipulation component is automatically generated on Manipulable s by Manipulator s when a hover event begins, and is destroyed when the Manipulator ends its interaction with (i.e. stops hovering and stops grabbing) the Manipulable . It represents the state of the interaction, which is unique to the Manipulable - Manipulator pair.

A reference to this component is passed along with each Manipulable event that is triggered, providing event handlers with information about the manipulation:

Specific Types of Manipulable (Objects That Can Be Manipulated)

Positionable

The Positionable component can be attached to a GameObject with a Rigidbody to allow it to be grabbed and repositioned by a Manipulator . Attaching this component to a child of a GameObject with a Rigidbody will make that child a ‘handle’ by which the Rigidbody can be moved. Positionable exposes the following properties in the Unity Inspector (in addition to those of Manipulable ):

Movable

The Movable component extends upon the functionality of Positionable . It can be attached to a GameObject with a Rigidbody to allow it to be grabbed, repositioned and rotated by a Manipulator . Attaching this component to a child of a GameObject with a Rigidbody will make that child a ‘handle’ by which the Rigidbody can be manipulated. Movable exposes the following properties in the Unity Inspector (in addition to those of Manipulable and Positionable ):

Movable Component

Rotatable

The Rotatable component implements precise angular control of the target object about the given rotation axis - this is controlled by pointing left or right whilst grabbing this Manipulable GameObject (typically a parent GameObject). It can be attached to any GameObject (which will then act as the ‘handle’ of the rotation manipulation), and set to target any GameObject. Rotatable exposes the following properties in the Unity Inspector (in addition to those of Manipulable ):

Rotatable Component

Scalable

The Scalable component implements precise scale (size) control of the target object - this is controlled by pointing up or down whilst grabbing this Manipulable GameObject. It can be attached to any GameObject (which will then act as the ‘handle’ of the scaling manipulation), and set to target any GameObject (typically a parent GameObject). Scalable exposes the following properties in the Unity Inspector (in addition to those of Manipulable ):

Scalable Component

Selectable

The Selectable component implements basic selection and deselection control. Selectable exposes the following properties in the Unity Inspector (in addition to those of Manipulable ):

Hidable

The Hidable component can be attached to a GameObject to allow it to toggle the visibility of the target object. Hidable exposes the following properties in the Unity Inspector:

This component can be attached to Manipulable objects (or their child objects) to make the Manipulable (or a chosen target object) disappear and reappear when grabbed by a Manipulator (e.g. a Pointer ). It exposes the following properties:

ManipulatorUnityEventForwarder

This component can be attached to Manipulable objects in order to expose the Manipulable events as UnityEvents - see more here.

Specific Types of Manipulator (Components That Manipulate Other Objects)

Pointer

A Pointer is a subclass of LaserManipulator (a long-range version of Manipulator ). This component bridges the gap between the Litho and Manipulator classes. A Pointer uses events received from the Litho hardware (via the Litho component, which must be attached to the same object) to trigger its Manipulator actions.

ItemHolder

An ItemHolder component extends the Manipulator class in order to implement automatic grabbing of Positionable objects that move into range. Note that the Release Range of this component also represents the grab range.

ItemSpawner

An ItemSpawner component extends the Manipulator class in order to implement creation of new objects. This creation is triggered by another Manipulator (e.g. a Pointer ) grabbing the icon (which is generated by the ItemSpawner ) and pulling it beyond the ItemSpawner ’s Release Range.

ItemDeleter

An ItemDeleter component extends the ItemHolder class in order to implement deletion of Positionable objects. This deletion is triggered by the target Positionable object moving into the Release Range of the ItemDeleter , at which point the ItemDeleter grabs the object and pulls it in the direction of the Deletion Offset Vector whilst shrinking it to delete it.

Litho Events

If you are unfamiliar with C# events, you can read an overview here and get more detail on using events here.

Litho events are processed in two categories: ‘global’ and ‘object-specific’.

Litho touch events that occur on a Manipulable will first occur as a global event.

Code examples of subscribing to Litho and Manipulable events can be found here.

List of Global Litho Events

Litho Connection Status Events:

Litho Device Info Events:

Litho Touch Events:

List of Manipulable Events

Touch Event Notes

Litho touch events provide two parameter values for touch positions. It is important to use the correct value in order to provide the same experience to left-handed and right-handed users. In the future these positions might remap the touch coordinates to account for different Litho grips.

Code Samples

Litho Touch Code Example (global)

When the script below is attached to a GameObject in your scene, touches on the Litho touchpad will be printed to the Unity Console window (whilst in Play mode, when your Litho hardware is connected).

using UnityEngine; // Tell your script that you are going to use Litho features using LITHO; // Define your own class as a subclass of MonoBehaviour, so that it can be attached to GameObjects public class MyLithoEventScript : MonoBehaviour  private void Start()  // At a relevant point in the code, check that there is a Litho script in the scene if (Litho.Instance != null)  // If there is a Litho script, tell this script to call the HandleLithoTouchStart() function at the moment the touchpad on the currently connected Litho is touched Litho.Instance.OnTouchStart += HandleLithoTouchStart; > > // Define the HandleLithoTouchStart() function with specific touch event parameters private void HandleLithoTouchStart(Vector2 position, Vector2 worldPosition)  // Print a message to the Unity Console, noting the touch positions Debug.LogFormat(": Touch started at position (, )", this, worldPosition.x, worldPosition.y); > > 

Manipulable Touch Code Example (object-specific)

When the script below is attached to a GameObject in your scene, it will insist on also having a Manipulable component attached to it, and will then print a message in the Unity console every time a Manipulator (e.g. a Pointer ) stops hovering over it.

using UnityEngine; // Tell your script that you are going to use Litho features using LITHO; // Specify that this component must also have a Manipulable component attached with it [RequireComponent(typeof(Manipulable))] // Define your own class as a subclass of MonoBehaviour, so that it can be attached to GameObjects public class MyManipulableEventScript : MonoBehaviour  private Manipulable _myManipulable; private void Start()  // Get the reference to the Manipulable attached next to this script _myManipulable = GetComponentManipulable>(); // Tell this script to call the HandleManipulatorExit() function when this object stops being hovered: _myManipulable.OnManipulatorExit += HandleManipulatorExit; > // Define the HandleManipulatorExit() function with specific manipulation event parameters private void HandleManipulatorExit(Manipulation manipulation)  // Print a message to the Unity Console, noting which Manipulator stopped hovering this object Debug.LogFormat(" stopped hovering over ", manipulation.Manipulator, name); > > 

Copyright © 2019-2020 Purple Tambourine Ltd