Instantiate Gesture with Began state

Random discussions.

Instantiate Gesture with Began state

Postby roberto_sc » Tue Sep 27, 2016 11:20 am

Hi,

Is there a way to instantiate a game object with a Gesture component while using the current gesture to feed it?

To exemplify, I'll explain what I'm trying to achieve:

I currently have a toolbar with buttons, when I click a button it instantiates a respective 3D object in the middle of the screen. This object has a PanGesture script that is used to drag it around.

I want to change this behaviour so the when the user drags the button in the tool bar it creates the 3D object in the button's position and the user can drag the 3D object around within the same gesture (that is, without releasing and starting another movement).

I'm using an EventTrigger with EventTriggerType.BeginDrag to detect the gesture in the button, close the toolbar and call my instantiate method that creates the 3D object. The problem is that I have to start a new gesture (release finger, drag again) to start dragging the 3D object.

I tried to set IsMoving in the PanGesture component and also tried to call CancelTouch/EndTouch for the current touches followed by a TouchManager.Instance.BeginTouch(Input.mousePosition) without success.

Thank you!
Last edited by roberto_sc on Fri Oct 07, 2016 12:52 am, edited 1 time in total.
roberto_sc
 
Posts: 2
Joined: Tue Sep 27, 2016 11:01 am

Re: Instantiate Gesture with Began state

Postby roberto_sc » Wed Oct 05, 2016 2:06 pm

Please Valentin, can you help me on this?

Perhaps I should explain my problem better?
roberto_sc
 
Posts: 2
Joined: Tue Sep 27, 2016 11:01 am

Re: Instantiate Gesture with Began state

Postby fbontin » Thu Jul 20, 2017 3:45 pm

I am having a problem which is pretty similar, so I thought that I could revive this thread. Maybe it is possible now that Touchscript has been updated.

This is what I am trying to make happen:
1. UI button is pressed
2. A 3d-object appears at the position of the touch
3. Focus of the gesture/press is switched to the 3d-object.
4. The 3d-object can be dragged/scaled/rotated using TransformGesture

Right now I have a UI button which when is pressed, spawns a cube behind it. But I would like to be able to move it directly, without releasing my finger and then pressing the cube.

roberto_sc, did you ever find a solution?

Or does anyone else have any tips? :-)
fbontin
 
Posts: 5
Joined: Thu Jul 20, 2017 3:33 pm

Re: Instantiate Gesture with Began state

Postby valyard » Thu Jul 20, 2017 11:49 pm

It is possible with TouchScript 9.
Take a look at Colors example, it is almost what you are asking for.

But in your case there has to be a slight modification to be able to capture the cube, not the UI button.
So, basically:
1. The button is pressed.
2. You do TouchManager.Instance.CancelPointer(id, true) to cancel it immediately and return to the system at the same position.
3. But before this you need to either disable your button or set StandardLayer.HitWorldSpaceUI and StandardLayer.HitScreenSpaceUI to false so the 3D object will be hit.
4. The gestures on the object will start automatically.
valyard
Site Admin
 
Posts: 435
Joined: Mon Sep 08, 2014 11:57 pm

Re: Instantiate Gesture with Began state

Postby fbontin » Fri Jul 21, 2017 11:14 am

Thank you for the quick and elaborate answer! I will try this :-)

EDIT: It works, thanks again! Code below:

Code: Select all
//disable scrollview which includes the buttons
GameObject.Find("Scroll View").SetActive(false);

//cancel pointer/touch
var tm = TouchManager.Instance;
var firstPointerId = tm.PressedPointers[0].Id;
tm.CancelPointer(firstPointerId, true);
fbontin
 
Posts: 5
Joined: Thu Jul 20, 2017 3:33 pm

Re: Instantiate Gesture with Began state

Postby valyard » Sun Jul 30, 2017 3:54 pm

9.0 has a more reliable way of doing this. Check Portal example.
https://github.com/TouchScript/TouchScr ... es/tag/9.0
valyard
Site Admin
 
Posts: 435
Joined: Mon Sep 08, 2014 11:57 pm

Re: Instantiate Gesture with Began state

Postby fbontin » Thu Aug 03, 2017 12:43 pm

I tried doing it the way it is done in the Portal example, but I can't get it to work as smooth as it was before. This way I would have to do two presses, but before it was just one continuous press. It cancels the gesture, but the transform gesture does not start directly after without pressing again.

Here's my code:
Code: Select all
//disable scrollview which includes the buttons
GameObject.Find("Scroll View").SetActive(false);

//cancel pointer/touch
var gesture = GetComponent<PressGesture>();
if (gesture != null) gesture.Cancel();


Maybe I missed something?
fbontin
 
Posts: 5
Joined: Thu Jul 20, 2017 3:33 pm

Re: Instantiate Gesture with Began state

Postby valyard » Thu Aug 03, 2017 1:10 pm

I'd say you are missing the SetExclusive part.

Code: Select all
var target = Instantiate(Prefab, Position.parent);
target.position = Position.position;
LayerManager.Instance.SetExclusive(target);
press.Cancel(true, true);
LayerManager.Instance.ClearExclusive();
valyard
Site Admin
 
Posts: 435
Joined: Mon Sep 08, 2014 11:57 pm

Re: Instantiate Gesture with Began state

Postby fbontin » Wed Aug 09, 2017 3:47 pm

I tried that, but couldn't get it working. But nevermind, it works when doing it the way I did before. Thank you!
fbontin
 
Posts: 5
Joined: Thu Jul 20, 2017 3:33 pm


Return to General Discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest