TouchScript and uGui (Unity 4.6)

Got a good idea for TouchScript? Post it here.

TouchScript and uGui (Unity 4.6)

Postby valyard » Fri Sep 12, 2014 7:42 pm

Moved here from https://github.com/InteractiveLab/TouchScript/issues/122.

Martin80:
Hi,
is there any chance that uGui can be used with TouchScript?
It seems still Unity does not support multitouch on win7 / win8 standalone! The new UI systems behavior on win7 multitouch device is like a normal mouse cursor...

At the moment I use colliders on ui elements to work with touchscript, not bad at all, but all those handy scripts (scroll rect, button, slider etc.) cannot be used!

Maybe a custom touch layer could do the job??


N3uRo:
We need this!

There is a "BaseInputModule" class where you inherit and you can process all events there.

Here you have some examples ("stramit" is Tim Cooper from the UI Team in Unity):

https://gist.github.com/stramit/ce455682b7944bdff0e7
https://gist.github.com/stramit/c98b992c43f7313084ac
https://gist.github.com/stramit/1d6971fdac4dd5f57dbb
valyard
Site Admin
 
Posts: 434
Joined: Mon Sep 08, 2014 11:57 pm

Re: TouchScript and uGui (Unity 4.6)

Postby valyard » Fri Sep 12, 2014 7:42 pm

Yes, TouchScript should definitely work with UGUI.
But what do you want to do with the GUI? Do you want to have windows touch or TUIO work with GUI elements? Do you want to be able to use gestures on GUI elements?
valyard
Site Admin
 
Posts: 434
Joined: Mon Sep 08, 2014 11:57 pm

Re: TouchScript and uGui (Unity 4.6)

Postby N3uRo » Fri Sep 12, 2014 10:22 pm

In my case Windows 8 touch.

You know that the UI system is based in a new Unity Event System that we have to implement the apropiated interfaces.

Imagine that I want to drag multiple UI elements at one. I will implement "IDragHandler" and I expect with a TouchScript Unity InputModule to work.

Same with TouchScript built-in gestures.
N3uRo
 
Posts: 3
Joined: Fri Sep 12, 2014 8:16 pm

Re: TouchScript and uGui (Unity 4.6)

Postby Martin80 » Sat Sep 13, 2014 1:12 am

valyard wrote:Yes, TouchScript should definitely work with UGUI.

Great news! :D

valyard wrote:Do you want to have windows touch or TUIO work with GUI elements?

Yes, exactly! It would be great if the UGUI event system would notice touchscript, so all the new UI elements could be used with multitouch on win7 / win8 out of the box (like on mobile platforms).
I would like to use ui elements like slider, drag and drop elements, scroll etc., and there will come more and more since some of the UI stuff will be open source...

valyard wrote:Do you want to be able to use gestures on GUI elements?

This would be even more powerful!
At the moment I use a 3D object as parent and a canvas with world space as child, so I can drag, rotate, scale the canvas. The canvas has different elements in it, like "image", "raw image", "button". I use press gesture (with collider on buttons) to make use of the gui buttons...

I think both would be cool, support for the new ugui standard events (s. attachment) and the power of touchscript gestures on ui elements!
Attachments
event_trigger.jpg
event_trigger.jpg (59.36 KiB) Viewed 22021 times
Martin80
 
Posts: 14
Joined: Sat Sep 13, 2014 12:14 am

Re: TouchScript and uGui (Unity 4.6)

Postby Martin80 » Thu Oct 09, 2014 1:27 pm

Today I found this wrapper script (https://github.com/InteractiveLab/TouchScript/issues/6) which makes NGUI compatible with touchscript.
It works really well, NGUI elements etc can be used with touchscript input and even combined with gestures! It is very easy to use, it adds a touch layer to the touchmanager.

Could a wrapper-script used in a similar way like this used for a UGUI and touchscript ?
Martin80
 
Posts: 14
Joined: Sat Sep 13, 2014 12:14 am

Re: TouchScript and uGui (Unity 4.6)

Postby valyard » Thu Oct 09, 2014 5:08 pm

I have a plan to work on it. Just don't have much time lately (8
valyard
Site Admin
 
Posts: 434
Joined: Mon Sep 08, 2014 11:57 pm

Re: TouchScript and uGui (Unity 4.6)

Postby N3uRo » Fri Nov 07, 2014 8:22 pm

valyard wrote:I have a plan to work on it. Just don't have much time lately (8


Any news? It's been one month and there is already published a 4.6 RC1 (it's near it's stable release).
N3uRo
 
Posts: 3
Joined: Fri Sep 12, 2014 8:16 pm

Re: TouchScript and uGui (Unity 4.6)

Postby noamg » Wed Nov 26, 2014 7:10 pm

I wanted to use TouchScript with uGui, but just to have uGui mask touchscript events (so drags that start on top of buttons don't affect, etc)

I found this : http://answers.unity3d.com/questions/78 ... throu.html

And slightly modified it to use reflection to access internal methods so you don't have to modify TouchScript itself in order for it to work :

Code: Select all
using UnityEngine;
using System.Collections;
using TouchScript;
using TouchScript.Gestures;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Reflection;

// original idea for integrating NGUI and TouchScript came from here:
// LINK https://github.com/InteractiveLab/TouchScript/issues/6
public class FilteruGUITouch : MonoBehaviour
{
    void Start()
    {
        TouchScript.TouchManager.Instance.TouchesBegan += TouchManagerBegan;
        TouchScript.TouchManager.Instance.TouchesMoved += TouchManagerMoved;
        TouchScript.TouchManager.Instance.TouchesEnded += TouchManagerEnded;
        TouchScript.TouchManager.Instance.TouchesCancelled += TouchManagerCancelled;
    }

    private void TouchManagerBegan(object sender, TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender, eventArgs, TouchPhase.Began);
    }

    private void TouchManagerMoved(object sender, TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender, eventArgs, TouchPhase.Moved);
    }

    private void TouchManagerEnded(object sender, TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender, eventArgs, TouchPhase.Ended);
    }

    private void TouchManagerCancelled(object sender, TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender, eventArgs, TouchPhase.Canceled);
    }

    private void TouchManagerChanged(object sender, TouchEventArgs eventArgs, TouchPhase touchPhase)
    {
        if (touchPhase != TouchPhase.Began)
            return;

        ITouchManager gesture = sender as ITouchManager;
       
        // to make sure this works for mouse input and touch-devices, starting from -1 (mouse) loop through 
        // each 'touch' in Input.touches and pass in the id to 'IsPointerOverEventSystemObject'
        // LINK http://forum.unity3d.com/threads/ispointerovereventsystemobject-always-returns-false-on-mobile.265372/
        for (int i = -1, il = Input.touches.Length; i < il; i++)
        {
            if (EventSystem.current.IsPointerOverGameObject(i))
            {
                foreach (ITouch touchPoint in eventArgs.Touches) {
                    //Hacking internals...
                    MethodInfo method = gesture.GetType().GetMethod("CancelTouch", BindingFlags.Instance | BindingFlags.NonPublic);
                    method.Invoke(gesture, new object[] { touchPoint.Id });
                }
                return;
            }
        }
    }
}


Something similar should be included in future versions of TouchScript to make it easy for uGUI and TouchScript to work separately, I think.
noamg
 
Posts: 15
Joined: Wed Nov 26, 2014 1:12 pm

Re: TouchScript and uGui (Unity 4.6)

Postby pajama » Wed Jan 07, 2015 3:08 am

+1
Any news? Would love to use touchscript with Unity UI!

Thank you for the awesome library!
pajama
 
Posts: 1
Joined: Wed Jan 07, 2015 3:05 am

Re: TouchScript and uGui (Unity 4.6)

Postby smonbrogg » Sat Jan 24, 2015 2:19 am

smonbrogg
 
Posts: 2
Joined: Sat Jan 24, 2015 2:16 am

Next

Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest