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

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Dimension with UI and Icon blocked by finger
« on: March 26, 2014, 06:25:36 AM »
1. About the Dimension problem, it is realised that I cannot control the dimension of the UISprite and UITexture based on the screen resolution( Based on both width and height to decide the dimension). So they could be more clear on tablet and enough clear on mobile. Could it be done?

2. About the Icon blocked by finger : When I drag an item using my finger, it seems that the icon I am dragging is totally blocked by my finger and so I cannot see the icon clearly. I suggest putting the icon always above the finger position when dragging. Could it be done too?

3, I also suggest that when I drag the items on screen, if I cannot drop them on certain surface, some changes or notices would appear ,let say, a cross on the icon to remind the user not available to drop the items on that point. Could it be done as well?

Thanks for the help for above few things!

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #1 on: March 26, 2014, 08:45:58 AM »
1. Not sure what you mean by the Dimension problem, but I assume you need Atlas Switching (SD, HD, UD). Look http://www.tasharen.com/forum/index.php?topic=832 or http://www.tasharen.com/forum/index.php?topic=8575.0

2. In OnDragStart() offset the sprite to wherever you like.

3. Use UICamera.hoveredObject in OnDrag(Vector2 delta)/OnDragEnd() to see if it intersects with a valid container and change the icon accordingly.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #2 on: March 26, 2014, 10:26:52 AM »
Thanks for your help!

Although I've tried to understand what you said, I still cannot understand enough because I'm not good at scripting for now.

So, I would be happy if you would tell me more in detail on what I actually need to do, for the above three things. 

Thank you very much . Please forgive my stupidity.

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 #3 on: March 26, 2014, 07:43:14 PM »
Well, how can we help if you're not good at scripting, and this requires scripting? We can't just write a custom solution for you here. This is a forum for NGUI questions, not scripting help. Uncle's answer is exactly what I would give as well. UIDragDropItem has a function, OnDragStart -- which is an NGUI event -- and it begins the drag operation there. When you derive a script from UIDragDropItem, you can overwrite functions such as OnDragDropMove, and specify your offset there. When you are dragging your finger, objects underneath your finger will be receiving OnDragOver and OnDragOut notifications. This is where you would do your checks to see if something can be dropped or not.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #4 on: March 26, 2014, 09:35:44 PM »
Okay, I would like to try the above things on myself.

A little question is that I want to , what you gave me, to set the offset of the sprite. So I change some coding in UIdragdropItem script.

  1. public Vector3 Offset = new Vector3(0,10,0);

and

  1. protected virtual void OnDragDropStart ()
  2.         {
  3.                 ...
  4.                 Vector3 pos = mTrans.localPosition;
  5.                 pos = pos + Offset;
  6.                 pos.z = 0f;
  7.                 mTrans.localPosition = pos;
  8.                 ...
  9.         }
  10.  

However, it was nothing to change. Did I do something wrong?

Updated:
i discover that if I enlarge the number of offset , it worked!
« Last Edit: March 27, 2014, 12:47:25 AM by Tomleung »

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #5 on: March 31, 2014, 11:23:24 PM »
1. Not sure what you mean by the Dimension problem, but I assume you need Atlas Switching (SD, HD, UD). Look http://www.tasharen.com/forum/index.php?topic=832 or http://www.tasharen.com/forum/index.php?topic=8575.0

2. In OnDragStart() offset the sprite to wherever you like.

3. Use UICamera.hoveredObject in OnDrag(Vector2 delta)/OnDragEnd() to see if it intersects with a valid container and change the icon accordingly.

I wonder that how could I check the intersection occured and so change the icon. I've tried to Debug.Log(UICamera.hoveredObject) in dragging icons but it always not identify the icon dragged. Is there any some or other variables I need to use in this case?

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 #6 on: April 01, 2014, 08:09:28 AM »
I don't understand what you mean.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #7 on: April 01, 2014, 10:25:05 AM »

I try to explain clearly. Sorry for my poor English.

UncleAcid said "Use UICamera.hoveredObject in OnDrag(Vector2 delta)/OnDragEnd() to see if it intersects with a valid container and change the icon accordingly." So I try to know more about how UICamera.hoveredObject would really do in this case.

In my coding, I may try to use UICamera.hoveredObject to check the container are invalid or not. If valid, the icon certainly keep  unchanged.
If invalid, I should use mTrans(?) , which is the variable of the item dragged in runtime, to change the sprite in UIsprite script?

Above scripts would be added in OnDrag(Vector2 delta) inside UIDragDropitem.

Are these on the correct way? Or any more simple way to do?

Any advice would be greatly appreciated.
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 #8 on: April 01, 2014, 10:48:25 AM »
UICamera.currentTouch.dragged tells you what's being dragged. So to check what's being dragged you can use this example:
  1. void OnDragOver (GameObject drag)
  2. {
  3.     Debug.Log("Dragged " + drag.name + " over " + name);
  4. }
http://www.tasharen.com/forum/index.php?topic=8828.0
« Last Edit: April 07, 2014, 10:12:43 PM by ArenMook »

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #9 on: April 05, 2014, 06:24:27 AM »
UICamera.currentTouch.dragged tells you what's being dragged. So to check what's being dragged you can use this example:
  1. void OnDragOver ()
  2. {
  3.     Debug.Log("Dragged " + UICamera.currentTouch.dragged.name + " over " + name);
  4. }
http://www.tasharen.com/forum/index.php?topic=8828.0

Thank you. Now I can catch the item dragged variable.
But I still could not check if the dragdrop surface is vaild or not then change the icon.
Such as UIcamera.hoveredObject or UIdragdropsurface still could not help me to do it.
I hope that there is a simple and direct way to do this. 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 #10 on: April 05, 2014, 11:47:54 AM »
OnDragOver is going to be triggered on your surface object.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #11 on: April 06, 2014, 12:24:08 AM »
OnDragOver is going to be triggered on your surface object.

The problem is that now I want when dragging the icon, if there are some invalid dragdrop surface and then change icon to remind user : you cannot drop the item on that surface. If valid, the icon would keep original and remind user : you can drop the item on that surface.

OnDragOver() is although telling me something when dragging item on valid surface, how about when dragging item on invalid surface then do something? I may think that it should be possible to do something on GUI to do this.

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 #12 on: April 06, 2014, 02:57:14 AM »
What's an "invalid surface"? If it's still an object of any kind, you will still get the same OnDragOver. But if you don't want to attach scripts to surfaces, then you can always just set up a UICamera.genericEventHandler to some object, and add a script to this object with OnDragOver on it. Generic event handler will receive a copy of all the NGUI events, whether they were handled or not. So if you wanted a single place to set your on drag over logic, this would be the way to do it.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Dimension with UI and Icon blocked by finger
« Reply #13 on: April 06, 2014, 09:02:06 AM »
What's an "invalid surface"? If it's still an object of any kind, you will still get the same OnDragOver. But if you don't want to attach scripts to surfaces, then you can always just set up a UICamera.genericEventHandler to some object, and add a script to this object with OnDragOver on it. Generic event handler will receive a copy of all the NGUI events, whether they were handled or not. So if you wanted a single place to set your on drag over logic, this would be the way to do it.

In order to make you understand my situation and my question, here is my objective:

Soucre: http://imgbox.com/D4l9Qmvs

I hope that you can understand my work above and I believe that it may possible to do something on GUI.
Thanks for your help!

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 #14 on: April 06, 2014, 01:34:25 PM »
Right and my previous reply stands. Use a script on the generic event handler.