Author Topic: Dimension with UI and Icon blocked by finger  (Read 15433 times)

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #15 on: April 07, 2014, 09:37:02 AM »
Right and my previous reply stands. Use a script on the generic event handler.

I repeatly try to understand how UICamera.genericEventHandler work in this specific case but eventually unsuccessful.
I even do not know what the steps should I follow to fullfill this purpose.

Even if I get a gamebobject and set(this.gameobject = UICamera.genericEventHandler) this object be UICamera.genericEventHandler, what is the following? Do something in Ondragover() ? I can change icon inside this function?

Also, UICamera.genericEventHandler can be set on any object? Because I have a lot confusing on how to use these specific coding to get my job done. I really hope that you can explain to me in detail.

Maybe one of example appear to tell me when I drag one icon and this icon would change something continously and accordingly base on the different surface on screen, so I can take out my confusing.

Please! This is not because my scripting is not good. It is because I don't know how to use your script to mix on my other scripts.
I know how to change icon. I know how to use raycast to check what I touch. But I don't know how to do on dragging with certain situation.
Sorry, I hope this probelm would not disturb you a lot too. Thanks and hopefully you would use some time to help me solve this probelm.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #16 on: April 07, 2014, 10:11:20 PM »
Why are you assigning the script's game object to be the generic event handler? You have it backwards. It should be:
  1. UICamera.genericEventHandler = targetGameObject;
...where 'targetGameObject' is the game object that has your custom script attached. So if you're doing it from your custom script, then it would be:
  1. UICamera.genericEventhandler = gameObject;
Inside this script have your OnDragOver function:
  1. void OnDragOver (GameObject dragged)
  2. {
  3.     Debug.Log("Dragged " + dragged.name + " over " + name);
  4. }

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #17 on: April 11, 2014, 09:31:13 AM »
Why are you assigning the script's game object to be the generic event handler? You have it backwards. It should be:
  1. UICamera.genericEventHandler = targetGameObject;
...where 'targetGameObject' is the game object that has your custom script attached. So if you're doing it from your custom script, then it would be:
  1. UICamera.genericEventhandler = gameObject;
Inside this script have your OnDragOver function:
  1. void OnDragOver (GameObject dragged)
  2. {
  3.     Debug.Log("Dragged " + dragged.name + " over " + name);
  4. }
Foreword
As you said and so, I simply write a script and put it on the surface(cube) inside "Example dragdropitem" scene that you gave in the package.
And here is my script below I want to try
  1. void Start()
  2.         {
  3.                 UICamera.genericEventHandler = gameObject;
  4.         }
  5.  
  6.         void OnDragOver (GameObject dragged)
  7.         {
  8.                 Debug.Log("Dragged " + dragged.name + " over " + name);
  9.         }
  10.  
However, it has no any "Debug.Log" messages appear when I drag an item on the cube...
Main
Actually the main problem is not the above things. I believe that you know what I want to do on GUI. When I drag an item, some function would automatically run to detect the location is valid or not for me to drop the item on.

Simply I want to ask is if I want to return false when I drag an item on invalid surface and return true when I drag an item on valid surface in one boolean. What should I do? In my custom script?

Sorry because I still have a lot of questions on using this dragdrop system and cobining my custom script. I always ask me why I can't do this with one simple way. I hope you can help me with details. Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #18 on: April 12, 2014, 04:22:25 AM »
Quote
When I drag an item, some function would automatically run to detect the location is valid or not for me to drop the item on.
Place this on your dragged object:
  1. void OnDrag (Vector2 delta)
  2. {
  3.     Debug.Log("Currently over " + UICamera.currentTouch.current.name);
  4. }
Replace the Debug.Log with something else, like GetComponent<UIWidget>().color = valid? Color.green : Color.red;

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #19 on: April 13, 2014, 11:47:58 AM »
Place this on your dragged object:
  1. void OnDrag (Vector2 delta)
  2. {
  3.     Debug.Log("Currently over " + UICamera.currentTouch.current.name);
  4. }
Replace the Debug.Log with something else, like GetComponent<UIWidget>().color = valid? Color.green : Color.red;

UICamera.currentTouch.current.name is only return the objects on UI layer but not the gameobjects in the scene.
I need to check the location is valid or not for me to drop the item on. If valid, return true, else return false. And this checking start on dragging and end on release.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #20 on: April 14, 2014, 02:55:47 AM »
If you put a UICamera script on your main camera as well, it will return both.

UICamera is what does raycasts, and which camera you place it on determines which objects will be hittable. So be sure to place a UICamera on every camera who's objects you want to respond to events.