Comments (31)
What are you trying to do? Why do you need the state of a MetaGesture?
Because it exists only to convert touch points into events.
from touchscript.
I have written a NGUI-Wrapper (GUI toolkit). if everything works i will post it as well so you can integrate it in TouchScript.
What i'm currently working on is a object orbiting script.
- A object in the center of the room
- a camera is orbiting around the object
- with a zoom pinch the distance can be modified
do you have a hint how to do this easily?
i'm currently thinking about using the metagesture as well, as i failed doing it with the other gestures.
thanks
[ Reto Spoerri ]
+41 78 621 65 15
[email protected]
[ Ludic | GmBH in g | Game Development ]
Hardturmstrasse 8
CH-8005 Zürich
http://www.ludic.ch/
Am 24.03.2013 um 19:05 schrieb Valentin Simonov [email protected]:
What are you trying to do? Why do you need the state of a MetaGesture?
Because it exists only to convert touch points into events.—
Reply to this email directly or view it on GitHub.
from touchscript.
- Do NGUI containers have colliders on them?
- This pinch behaviour can be done using ScaleGesture and FullscreenBackgroundTarget on camera to catch touch events outside of the object.
from touchscript.
- Yes, NGUI Objects have colliders. The Wrapper i have written works pretty well right now. in the latest version i am using the TouchManager's TouchesBegan, TouchesMoved, … functions to detect touches anywhere. And it doesn't distribute events behind the GUI elements.
- i have tried to use the scaleGesture with the fullscreenbackground. however it only responded to touches that would hit Colliders from Rays of the GUI-Camera and not the Perspective Camera (which would be the relevant one). I think some way of choosing the camera that should be used to check for collisions (or a collision mask) should be added.
thanks & regards, reto
[ Reto Spoerri ]
+41 78 621 65 15
[email protected]
[ Ludic | GmBH in g | Game Development ]
Hardturmstrasse 8
CH-8005 Zürich
http://www.ludic.ch/
Am 24.03.2013 um 20:27 schrieb Valentin Simonov [email protected]:
Do NGUI containers have colliders on them?
This pinch behaviour can be done using ScaleGesture and FullscreenBackgroundTarget on camera to catch touch events outside of the object.
—
Reply to this email directly or view it on GitHub.
from touchscript.
- Can you add gestures to NGUI objects? Working with TouchManager's events is not good idea since you bypass all gestures logic code. I'm asking because I've never used NGUI so I don't know how it works o.O
- You should put fullscreenbackground on the camera you want to use. And there's indeed a way to specify cameras. Put CameraLayer on the one you want and sort layers on TouchManager.
from touchscript.
Fixed in develop branch.
from touchscript.
the current implementation is the quickest method i could evaluate that works well with ngui's way of
receiving input events. are you interested in adding it to the source?
as the current orbiting script is heavily based on the fingergestures code i can not add it to the codebase.
kind regards, reto
[ Reto Spoerri ]
+41 78 621 65 15
[email protected]
[ Ludic | GmBH in g | Game Development ]
Hardturmstrasse 8
CH-8005 Zürich
http://www.ludic.ch/
Am 25.03.2013 um 12:26 schrieb Valentin Simonov [email protected]:
Can you add gestures to NGUI objects? Working with TouchManager's events is not good idea since you bypass all gestures logic code. I'm asking because I've never used NGUI so I don't know how it works o.O
You should put fullscreenbackground on the camera you want to use. And there's indeed a way to specify cameras. Put CameraLayer on the one you want and sort layers on TouchManager.
—
Reply to this email directly or view it on GitHub.
from touchscript.
Need to check it out. MetaGesture is not a good way to work with touch points. Much better would be to use exhisting gestures like Tap or Pan.
from touchscript.
Ludicch, I'm very interested in your wrapper, could I use it??
from touchscript.
@ludicch : Same here - that wrapper would be tremendously helpful.
@valyard : I can see that the way TouchScript is designed, using the Gestures would be preferable. However, since Unity provides a "Touch-API" and tools like NGUI are based on that, creating a bridge between existing tools based on Unity's way of handling touch input and TouchScript is probably easiest in most cases when using MetaGesture. Using gestures like Tap or Pan would make things unnecessarily complex because recognizing the gestures is built into those tools already so that would just create conflicts. For me, the reason I'm using TouchScript is to have an easy way to use TuioInput and Win7TouchInput ... ATM, the gesture recognition is not something I need (but I will probably use it for some other project) ;-)
from touchscript.
I'm absolutely for combining existing libraries. If someone got working wrapper for NGUI and wants to share it would be cool. I would just want it to fit into what TouchScript is because MetaGesture is considered a hack o.O
from touchscript.
the wrapper:
using UnityEngine;
using System.Collections;
using TouchScript.Events;
using TouchScript.Gestures;
public class TouchScriptNGUI : MonoBehaviour {
UICamera uiCamera;
TouchScript.TouchManager touchManager;
void Start () {
uiCamera = GameObject.FindObjectOfType(typeof(UICamera)) as UICamera;
touchManager = GameObject.FindObjectOfType(typeof(TouchScript.TouchManager)) as TouchScript.TouchManager;
touchManager.TouchesBegan += TouchManagerBegan;
touchManager.TouchesMoved += TouchManagerMoved;
touchManager.TouchesEnded += TouchManagerEnded;
touchManager.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) {
TouchScript.TouchManager gesture = sender as TouchScript.TouchManager;
foreach (TouchScript.TouchPoint touchPoint in eventArgs.TouchPoints) {
UICamera.currentTouchID = uiCamera.allowMultiTouch ? touchPoint.Id : 1;
UICamera.currentTouch = UICamera.GetTouch(UICamera.currentTouchID);
bool pressed = (touchPhase == TouchPhase.Began) || UICamera.currentTouch.touchBegan;
bool unpressed = (touchPhase == TouchPhase.Canceled) || (touchPhase == TouchPhase.Ended);
UICamera.currentTouch.touchBegan = false;
if (pressed) {
UICamera.currentTouch.delta = Vector2.zero;
}
else {
UICamera.currentTouch.delta = touchPoint.PreviousPosition - touchPoint.Position;
}
UICamera.currentTouch.pos = touchPoint.Position;
UICamera.hoveredObject = UICamera.Raycast(UICamera.currentTouch.pos, ref UICamera.lastHit) ? UICamera.lastHit.collider.gameObject : UICamera.fallThrough;
if (UICamera.hoveredObject == null) UICamera.hoveredObject = UICamera.genericEventHandler;
UICamera.currentTouch.current = UICamera.hoveredObject;
UICamera.lastTouchPosition = UICamera.currentTouch.pos;
// We don't want to update the last camera while there is a touch happening
if (pressed) UICamera.currentTouch.pressedCam = UICamera.currentCamera;
else if (UICamera.currentTouch.pressed != null) UICamera.currentCamera = UICamera.currentTouch.pressedCam;
// Double-tap support
// if (input.tapCount > 1) currentTouch.clickTime = Time.realtimeSinceStartup;
// Process the events from this touch
uiCamera.ProcessTouch(pressed, unpressed);
// If the touch has ended, remove it from the list
if (unpressed) UICamera.RemoveTouch(UICamera.currentTouchID);
UICamera.currentTouch = null;
// Don't consider other touches
if (!uiCamera.allowMultiTouch) break;
}
}
}
add this script to the same GameObject as the TouchManager along with the required Input Script.
it i'm not mistaken this should be everything needed to get it running.
from touchscript.
Awesome - that works really smoothly. Thank you!
from touchscript.
Interesting.
Do you mind if I refactor this into the framework at some point?
from touchscript.
i'm fine with that.
from touchscript.
hi ~ any news for NGUI integration ? do you have any plan to write a tutorial about how to setup TouchScript with NGUI?
from touchscript.
if i'm not mistaken (it's a while ago i wrote this) the above script (the wrapper) named as TouchScriptNGUI.cs is all you need to get it functioning. put the script on the same gameobject as the touchmanager and you should be fine.
from touchscript.
unfortunately I don't own ngui and dnon't plan to acquire one. so, ngui integration is still going to be 3rdparty solution.
from touchscript.
@ludicch I copied / pasted the code, added the script to the same game object as the TouchManager but the colliders under the UI elements still get triggered when I click on the UI, is this really everything that needs to be done ?
from touchscript.
Hi, I'm excited about getting TouchScript and NGUI working together... I've copied the code and attached it to my TouchScript game object... however I'm getting the two errors below:
Assets/TouchScriptNGUI.cs(52,59): error CS1502: The best overloaded method match for UICamera.Raycast(UnityEngine.Vector3, out UnityEngine.RaycastHit) has some invalid arguments
Assets/TouchScriptNGUI.cs(52,59): error CS1620: Argument #2 is missing out modifier
Any thoughts would be greatly appreciated.
from touchscript.
The guys at NGUI posted a solution for the errors I posted above.
Hopefully this will help others using the current version of NGUI (3.0.9)
UICamera.Raycast has the following signature in NGUI:
static public bool Raycast (Vector3 inPos, out RaycastHit hit)
The wrapper seems to expect this:
static public GameObject Raycast (Vector3 inPos, ref RaycastHit hit)
I'm not sure which version of NGUI it was written for but it seems it needs to be updated from this:
UICamera.hoveredObject = UICamera.Raycast(UICamera.currentTouch.pos, ref UICamera.lastHit) ? UICamera.lastHit.collider.gameObject : UICamera.fallThrough;
To this:
UICamera.Raycast(UICamera.currentTouch.pos, out UICamera.lastHit);
from touchscript.
Heh, I just started researching this question.
So, with this fix it works?
from touchscript.
It seems to with my current implementation... The application I'm currently working on is at early stages, but I put a build on the PC with the above fix, and yes... I am able to interact with more than one NGUI widget simultaneously. This was the functionality I needed for multi-user interaction... I have not had a chance to test anything beyond that yet.
from touchscript.
I'm going to assume that this no longer works as there doesn't seem to be any form of TouchScript.Events ?? could someone give me some idea on how to get this to work in the current version?
from touchscript.
From TouchScript.Events
namespace you need TouchEventArgs
which is now at TouchScript.TouchEventArgs
. Also touch events instead of for example touchManager.TouchesBagan
are at TouchManager.Instance.TouchesBegan
. Everything else should be fine.
from touchscript.
hum...is the whole good script somewhere guys?
I have a parsing error...
thx
from touchscript.
Well, I just applied suggested changes to make it compile. Then I've added two lines to disable native NGUI input because it seems to conflict obviously. It seems to work, though I didn't test it much.
using UnityEngine;
using System.Collections;
using TouchScript;
using TouchScript.Gestures;
public class TouchScriptNGUI : MonoBehaviour {
UICamera uiCamera;
void Start () {
uiCamera = GameObject.FindObjectOfType(typeof(UICamera)) as UICamera;
// Disable standard NGUI inputs
uiCamera.useMouse = false;
uiCamera.useTouch = false;
TouchManager.Instance.TouchesBegan += TouchManagerBegan;
TouchManager.Instance.TouchesMoved += TouchManagerMoved;
TouchManager.Instance.TouchesEnded += TouchManagerEnded;
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) {
TouchScript.TouchManager gesture = sender as TouchScript.TouchManager;
foreach (TouchScript.ITouch touchPoint in eventArgs.Touches) {
UICamera.currentTouchID = uiCamera.allowMultiTouch ? touchPoint.Id : 1;
UICamera.currentTouch = UICamera.GetTouch(UICamera.currentTouchID);
bool pressed = (touchPhase == TouchPhase.Began) || UICamera.currentTouch.touchBegan;
bool unpressed = (touchPhase == TouchPhase.Canceled) || (touchPhase == TouchPhase.Ended);
UICamera.currentTouch.touchBegan = false;
if (pressed) {
UICamera.currentTouch.delta = Vector2.zero;
}
else {
UICamera.currentTouch.delta = touchPoint.PreviousPosition - touchPoint.Position;
}
UICamera.currentTouch.pos = touchPoint.Position;
UICamera.hoveredObject = UICamera.Raycast(UICamera.currentTouch.pos) ? UICamera.lastHit.collider.gameObject : UICamera.fallThrough;
if (UICamera.hoveredObject == null) UICamera.hoveredObject = UICamera.genericEventHandler;
UICamera.currentTouch.current = UICamera.hoveredObject;
UICamera.lastTouchPosition = UICamera.currentTouch.pos;
// We don't want to update the last camera while there is a touch happening
if (pressed) UICamera.currentTouch.pressedCam = UICamera.currentCamera;
else if (UICamera.currentTouch.pressed != null) UICamera.currentCamera = UICamera.currentTouch.pressedCam;
// Double-tap support
// if (input.tapCount > 1) currentTouch.clickTime = Time.realtimeSinceStartup;
// Process the events from this touch
uiCamera.ProcessTouch(pressed, unpressed);
// If the touch has ended, remove it from the list
if (unpressed) UICamera.RemoveTouch(UICamera.currentTouchID);
UICamera.currentTouch = null;
// Don't consider other touches
if (!uiCamera.allowMultiTouch) break;
}
}
}
from touchscript.
perfect!
like a charme!
tested with Ngui v3.6.8
thx everybody!
n.
from touchscript.
I've reimplemented it as a layer. Place it on NGUI camera. This way you can correctly (I hope) combine NGUI and TouchScript gestures in the same scene and even use gestures on NGUI widgets (not so useful, though). Still didn't tested it much.
using UnityEngine;
using System.Collections;
using TouchScript;
using TouchScript.Layers;
using TouchScript.Hit;
using TouchScript.Utils;
public class NGUICameraTouchLayer : TouchLayer
{
private UICamera uiCamera;
void Start()
{
uiCamera = GetComponent<UICamera>();
uiCamera.allowMultiTouch = true;
}
public override Vector3 WorldProjectionNormal
{
get
{
return uiCamera.transform.forward;
}
}
public override LayerHitResult Hit(Vector2 position, out ITouchHit hit)
{
if (base.Hit(position, out hit) == LayerHitResult.Miss)
{
return LayerHitResult.Miss;
}
if (uiCamera.camera.enabled == false || !uiCamera.camera.gameObject.activeInHierarchy)
{
return LayerHitResult.Miss;
}
if (!uiCamera.camera.pixelRect.Contains(position))
{
return LayerHitResult.Miss;
}
if (!UICamera.Raycast(position))
{
return LayerHitResult.Miss;
}
hit = TouchHitFactory.Instance.GetTouchHit(UICamera.lastHit);
return LayerHitResult.Hit;
}
public override Vector3 ProjectTo(Vector2 screenPosition, Plane projectionPlane)
{
return ProjectionUtils.CameraToPlaneProjection(screenPosition, uiCamera.camera, projectionPlane);
}
protected override void setName()
{
Name = "NGUI Camera";
}
protected override LayerHitResult beginTouch(ITouch touch, out ITouchHit hit)
{
TouchChanged(touch, TouchPhase.Began);
return base.beginTouch(touch, out hit);
}
protected override void moveTouch(ITouch touch)
{
TouchChanged(touch, TouchPhase.Moved);
}
protected override void endTouch(ITouch touch)
{
TouchChanged(touch, TouchPhase.Ended);
}
protected override void cancelTouch(ITouch touch)
{
TouchChanged(touch, TouchPhase.Canceled);
}
private void TouchChanged(ITouch touch, TouchPhase touchPhase)
{
UICamera.currentTouchID = touch.Id;
UICamera.currentTouch = UICamera.GetTouch(UICamera.currentTouchID);
bool pressed = (touchPhase == TouchPhase.Began) || UICamera.currentTouch.touchBegan;
bool unpressed = (touchPhase == TouchPhase.Canceled) || (touchPhase == TouchPhase.Ended);
UICamera.currentTouch.touchBegan = false;
if (pressed)
{
UICamera.currentTouch.delta = Vector2.zero;
}
else
{
UICamera.currentTouch.delta = touch.PreviousPosition - touch.Position;
}
UICamera.currentTouch.pos = touch.Position;
UICamera.hoveredObject = UICamera.Raycast(UICamera.currentTouch.pos) ? UICamera.lastHit.collider.gameObject : UICamera.fallThrough;
if (UICamera.hoveredObject == null)
{
UICamera.hoveredObject = UICamera.genericEventHandler;
}
UICamera.currentTouch.current = UICamera.hoveredObject;
UICamera.lastTouchPosition = UICamera.currentTouch.pos;
// We don't want to update the last camera while there is a touch happening
if (pressed)
{
UICamera.currentTouch.pressedCam = UICamera.currentCamera;
}
else if (UICamera.currentTouch.pressed != null)
{
UICamera.currentCamera = UICamera.currentTouch.pressedCam;
}
// Process the events from this touch
uiCamera.ProcessTouch(pressed, unpressed);
// If the touch has ended, remove it from the list
if (unpressed)
{
UICamera.RemoveTouch(UICamera.currentTouchID);
}
UICamera.currentTouch = null;
}
}
from touchscript.
hum ...i've got a parsing error...with the new script..
from touchscript.
Thank you so much for sharing this! NGUICameraTouchLayer works great, as promised even gestures on ngui widgets are possible! The title of this issue is delusive, found this by accident (http://www.daikonforge.com/forums/threads/windows-7-touch.535/#post-3331
), this script should be part of the package...
from touchscript.
Related Issues (20)
- Camera Control
- Initial touch down on UI Slider sets Slider.value to 0 HOT 1
- Scaling an object
- Tap Gesture Not Working on WebGL (mobile only)
- Update Old Hyperlinks in `Gestures` Wiki article
- Pointers not being removed/cancelled using TUIO input HOT 5
- Triggering overlapping colliders at the same time with one click?
- Pointer.GetOverData(false) return Wrong Target
- Unity Crashes when i click on the TouchManager prefab
- Touch Detection on Multi Display Window Application HOT 1
- I can't touch on surface pro 7
- TouchScript multiple displays with tuio HOT 2
- Transforming an object without the need to touch it beforehand HOT 1
- How to receive only the raw touches that land within an object? HOT 1
- out of virtual finger IDs
- TUIO Input extra poitner issues HOT 1
- Mac osx touchpad support
- The order of the layers
- Touch duplication HOT 2
- Rotation and Scaling not working in Windows build.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from touchscript.