Author Topic: Drag Border  (Read 2328 times)

jimbo999

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Drag Border
« on: November 06, 2014, 06:35:32 PM »
Hello, i have an drag drop item and a texture below.

I want the texture to be something like a border box for the drop item.
Whenever after dragging the item is released outside the texture it should be placed back to the place before dragging.
If it is released inside the texture, it should stay there.

I could'nt managed to get this working. My Texture has an bool which tells if the mousebutton is released on it
  1. public class TextureScript : MonoBehaviour
  2. {
  3.     public bool IsMouseOver = false;
  4.     // Use this for initialization
  5.     private void OnHover(bool isOver)
  6.     {
  7.         switch (isOver)
  8.         {
  9.             case true:
  10.                 IsMouseOver = true;
  11.                 Debug.Log("MouseIsOver");
  12.                 break;
  13.             case false:
  14.                 IsMouseOver = false;
  15.                 break;
  16.         }
  17.     }
  18. }
  19.  

The drag item has some code where it creates a child.
  1.     void OnDragStart()
  2.     {
  3.        Debug.Log("Drop");
  4.        ButtonTemp = NGUITools.AddChild(gameObject.transform.parent.gameObject, gameObject);
  5.        NGUITools.SetActive(ButtonTemp, true);
  6.  
  7.     }
  8.  

How to notify the Item about the bool IsMousOver from the Texture ?
Or is there a better way ?

Thx in advance

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Border
« Reply #1 on: November 07, 2014, 02:38:42 PM »
OnDragOver tells you when you dragged something over an object. OnDrop is called when you release the drag. OnHover is just that -- hovering over. It has nothing to do with drag.

jimbo999

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Drag Border
« Reply #2 on: November 07, 2014, 03:42:04 PM »
Yeah, i wanted to have some check if the drag item has released outside the texture but couldn't find a way.
Could you point me to the right direction how to have a drag border for my drag item ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Border
« Reply #3 on: November 07, 2014, 04:07:18 PM »
How to have a drag border for your drag item? I don't understand what you mean.

Check UICamera's list of events. Two that may interest you:

* OnDragEnd () is sent to a dragged object when the drag event finishes.
* OnDrop(dragged GameObject) is sent to the object under the dragged one when drag event finishes.

jimbo999

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Drag Border
« Reply #4 on: November 07, 2014, 07:14:03 PM »
Thx for the reply, to make it short:

I want to have a drag item inside a drag area, lets say a rectangle sprite. If the drag item is dropped inside the sprite, its okay.
If its dropped outside, it should be placed back to the position before the drag. That was what i meant with drag border.
Tried many things, still no success. Guess it should be easy.

Edit:
The solution was the UICamera.hoveredObject. This can be calles from everwhere and so i can test it in the drag item script.
So the Problem is solved.
« Last Edit: November 07, 2014, 07:45:10 PM by jimbo999 »