<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://powerui.kulestar.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mtorni</id>
		<title>PowerUI - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://powerui.kulestar.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mtorni"/>
		<link rel="alternate" type="text/html" href="https://powerui.kulestar.com/wiki/index.php?title=Special:Contributions/Mtorni"/>
		<updated>2026-06-04T04:23:52Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>https://powerui.kulestar.com/wiki/index.php?title=Input_Pointers&amp;diff=777</id>
		<title>Input Pointers</title>
		<link rel="alternate" type="text/html" href="https://powerui.kulestar.com/wiki/index.php?title=Input_Pointers&amp;diff=777"/>
				<updated>2017-07-11T11:32:33Z</updated>
		
		<summary type="html">&lt;p&gt;Mtorni: Note about LaserPointer example requiring release past 2.0.700&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;An input pointer is [https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events#term_pointer any kind of pointing device] which presses, hovers, or both. A mouse, a finger and a stylus are the three main ones. They are related to the (draft) [https://w3c.github.io/pointerevents/ W3C Pointer Events specification]. Here&amp;#039;s some specific notes about the input pointers available in PowerUI.&lt;br /&gt;
&lt;br /&gt;
== Mouse Input ==&lt;br /&gt;
&lt;br /&gt;
PowerUI assumes that only a desktop platform will have a mouse. A [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1MousePointer.html MousePointer] is created when it&amp;#039;s running on a desktop and [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1Input.html#a7527e2574ccda7fb7cdd2d8a28fff6db PowerUI.Input.CreateSystemMouse] is true &amp;#039;&amp;#039;(the default)&amp;#039;&amp;#039;. If your project doesn&amp;#039;t use a mouse pointer on a desktop platform (it&amp;#039;s [[Virtual Reality Cameras|virtual reality]] for example), you&amp;#039;d remove it by setting [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1Input.html#a7527e2574ccda7fb7cdd2d8a28fff6db CreateSystemMouse] to false in an Awake method.&lt;br /&gt;
&lt;br /&gt;
== Touch and Stylus Input ==&lt;br /&gt;
&lt;br /&gt;
PowerUI handles multi-touch input by default on any platform which supports it. It will automatically stack with a mouse input on desktops which also have touchscreens. Each time a new touch is detected, a [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1FingerPointer.html FingerPointer] or a [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1StylusPointer.html StylusPointer] is created. They fire the various [https://developer.mozilla.org/en-US/docs/Web/API/Touch_events touch events] as well as [https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent mouse events].&lt;br /&gt;
&lt;br /&gt;
All pointers are [https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary primary] (which means they all fire those mouse events too).&lt;br /&gt;
&lt;br /&gt;
== Virtual Reality ==&lt;br /&gt;
&lt;br /&gt;
PowerUI has a custom input pointer, a [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1CameraPointer.html CameraPointer], for virtual reality. See [[Virtual Reality Cameras|the article]] relating to virtual reality camera&amp;#039;s. Alternatively here&amp;#039;s a (rough!) laser pointer input example. Just add it to your project and see the notes below on how to e.g. add it and make it click:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;#039;csharp&amp;#039;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using UnityEngine;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/// &amp;lt;summary&amp;gt;A laser pointer which fires an input ray from e.g. a 3D hand.&amp;lt;/summary&amp;gt;&lt;br /&gt;
/// NOTE: PowerUI.InputPointer.Raycast is defined in PowerUI git master, not in releases at least up to 2.0.700&lt;br /&gt;
public class LaserPointer : PowerUI.InputPointer{&lt;br /&gt;
    &lt;br /&gt;
    public Transform Transform;&lt;br /&gt;
    /// &amp;lt;summary&amp;gt;True if UI&amp;#039;s move around.&amp;lt;/summary&amp;gt;&lt;br /&gt;
    public bool MovingUIs; &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
    /// &amp;lt;summary&amp;gt;Setup a laser pointer from the given transform (e.g. a hand object).&amp;lt;/summary&amp;gt;&lt;br /&gt;
    public LaserPointer(Transform transform):this(transform,true){}&lt;br /&gt;
   &lt;br /&gt;
    /// &amp;lt;summary&amp;gt;Setup a laser pointer from the given transform (e.g. a hand object).&amp;lt;/summary&amp;gt;&lt;br /&gt;
    /// &amp;lt;param name=&amp;#039;movingUIs&amp;#039;&amp;gt;Set this to true if your WorldUI&amp;#039;s move around.&lt;br /&gt;
    /// Setting it to false is a small performance saving. If you&amp;#039;re not sure, just use true.&amp;lt;/param&amp;gt;&lt;br /&gt;
    public LaserPointer(Transform transform, bool movingUIs){&lt;br /&gt;
       Transform = transform;&lt;br /&gt;
       MovingUIs = movingUIs;&lt;br /&gt;
       &lt;br /&gt;
       // It won&amp;#039;t interact with the main UI so just put it offscreen to skip checking entirely:&lt;br /&gt;
       ScreenX = ScreenY = -1000f;&lt;br /&gt;
       &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public override bool Raycast(out RaycastHit hit, Camera cam, Vector2 screenPoint){&lt;br /&gt;
        &lt;br /&gt;
        // Fire off your ray in whatever your pointers direction is; we&amp;#039;ll use transform.forward here.&lt;br /&gt;
        // (&amp;#039;forward&amp;#039; is +ve z):&lt;br /&gt;
        Ray ray = new Ray(Transform.position, Transform.forward);&lt;br /&gt;
&lt;br /&gt;
        return Physics.Raycast(theRay, out hit);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public override bool Relocate(out Vector2 delta){&lt;br /&gt;
        &lt;br /&gt;
        // We can just ignore delta (it&amp;#039;s for the main UI):&lt;br /&gt;
        delta = Vector2.zero;&lt;br /&gt;
        &lt;br /&gt;
        if(MovingUIs){&lt;br /&gt;
            // Always recompute.&lt;br /&gt;
            return true;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Transform moved?&lt;br /&gt;
        if(Transform!=null &amp;amp;&amp;amp; Transform.hasChanged){&lt;br /&gt;
            Transform.hasChanged = false;&lt;br /&gt;
            return true;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Don&amp;#039;t bother recalculating - it&amp;#039;s not moved.&lt;br /&gt;
        // (Always return true if your UI&amp;#039;s are moving instead).&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;#039;csharp&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Fires a ray from the given hand object. If your UI&amp;#039;s don&amp;#039;t move around, use LaserPointer(aHandObject,false) to make a performance gain.&lt;br /&gt;
LaserPointer myPointer = new LaserPointer(aHandObject);&lt;br /&gt;
&lt;br /&gt;
// Add it:&lt;br /&gt;
myPointer.Add();&lt;br /&gt;
&lt;br /&gt;
// myPointer.LeftDown(); etc to click (see more below)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Define your own ==&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;re doing something more specialised then you can also define your own input pointer. Multiple Wii controllers, for example. This is very straight forward to do - at a minimum you must inherit from InputPointer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class MyCustomPointer : InputPointer{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then to use it, all you need to do is create and add it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
    MyCustomPointer pointer = new MyCustomPointer();&lt;br /&gt;
    pointer.Add();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be clicked etc or have a pressure value like any other pointer. To move it around, set the Position property (Top left corner is 0,0):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
    pointer.Position = new Vector2(100,100);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively you can put your position update logic inside the pointer itself by overriding the Relocate method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class MyCustomPointer : InputPointer{&lt;br /&gt;
    &lt;br /&gt;
    public override bool Relocate(out Vector2 positionChange){&lt;br /&gt;
    &lt;br /&gt;
        // - Get your latest coordinates here -&lt;br /&gt;
        Vector2 newPosition = Vector2.zero;&lt;br /&gt;
        &lt;br /&gt;
        // Try moving it (just returns false if your position wasn&amp;#039;t different to the current one):&lt;br /&gt;
        return TryChangePosition(newPosition, out positionChange);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making it click ==&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;ve got an input pointer and you&amp;#039;d like to click it (or vary its downward pressure), you can either:&lt;br /&gt;
&lt;br /&gt;
* Use the convenience method for mouse up/down events from OnGUI:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void OnGUI(){&lt;br /&gt;
&lt;br /&gt;
  // Returns true if your pointer actually did something (it went down or up)&lt;br /&gt;
  // You can also directly pass a UnityEngine.Event too.&lt;br /&gt;
  bool didSomething = MyPointer.HandleEvent();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Call the MyPointer.Down and MyPointer.Up methods (Optionally specifying a [https://docs.unity3d.com/ScriptReference/Event-button.html mouse button ID]):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Mousedown event, left button:&lt;br /&gt;
MyPointer.Down(0);&lt;br /&gt;
&lt;br /&gt;
// Which is also the same as:&lt;br /&gt;
MyPointer.LeftDown();&lt;br /&gt;
&lt;br /&gt;
// Mouseup event, left button:&lt;br /&gt;
MyPointer.Up(0);&lt;br /&gt;
&lt;br /&gt;
// Which is the same as:&lt;br /&gt;
MyPointer.LeftUp();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use SetPressure directly - this is useful if you&amp;#039;ve got some kind of stylus &amp;#039;&amp;#039;(every other option is just an abstraction of SetPressure)&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void Update(){&lt;br /&gt;
  &lt;br /&gt;
  // Update the pointer pressure:&lt;br /&gt;
  MyPointer.SetPressure(someVaryingField);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Accessing all pointers ==&lt;br /&gt;
&lt;br /&gt;
PowerUI implements various standard API&amp;#039;s for accessing pointers:&lt;br /&gt;
&lt;br /&gt;
* [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1TouchEvent.html TouchEvent].touches&lt;br /&gt;
* TouchEvent.targetTouches&lt;br /&gt;
* TouchEvent.changedTouches&lt;br /&gt;
* TouchEvent.identifier&lt;br /&gt;
* &amp;#039;&amp;#039;More!&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The non-standard internal ones:&lt;br /&gt;
&lt;br /&gt;
* [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1UIEvent.html#a2daa44fbceddd8510bc2791340a432b4 UIEvent.trigger] - &amp;#039;&amp;#039;MouseEvent, TouchEvent etc; The InputPointer instance this event came from&amp;#039;&amp;#039;&lt;br /&gt;
* [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1InputPointer.html#a77189cd51fedf33c73759f641c8380ef InputPointer.All] - &amp;#039;&amp;#039;All active pointers (array created on use; Use AllRaw and PointerCount for better performance)&amp;#039;&amp;#039;&lt;br /&gt;
* [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1InputPointer.html#a731d759f87ece43622fb497b5e3d88b3 InputPointer.PointerCount] - &amp;#039;&amp;#039;The number of actual pointers in the AllRaw pointer set&amp;#039;&amp;#039;&lt;br /&gt;
* [http://powerui.kulestar.com/powerdocs-2_0/classPowerUI_1_1InputPointer.html#aa76092f569304c8fcf6c3bea1f9612e3 InputPointer.AllRaw] - &amp;#039;&amp;#039;The raw set of pointers. Entries beyond PointerCount are random noise/ undefined.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source locations ==&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll find the implementations of MousePointer, FingerPointer etc here:&lt;br /&gt;
&lt;br /&gt;
* PowerUI/Source/Engine/Input/&lt;/div&gt;</summary>
		<author><name>Mtorni</name></author>	</entry>

	</feed>