Author Topic: DragItemView re positioning and Tween lag  (Read 2502 times)

DarthIwan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
DragItemView re positioning and Tween lag
« on: April 10, 2014, 10:06:15 AM »
Hello,

I have two questions.

I've made a playing card scroll view and I want to drag and drop a card into a card slot. I'm using UIDragDropContainer component on my slot.
I have also my custom UICardSlot component on the slot. It contains only one function so far:

  1.  
  2. void OnDrop(GameObject drag)
  3.     {
  4.         // Delete scroll view binding
  5.         drag.GetComponent<UIDragScrollView>().scrollView = null;
  6.        
  7.         // Center the position of the card to this slot
  8.         drag.transform.localPosition = transform.localPosition;
  9.  
  10.         drag.GetComponent<UIDragDropItem>().restriction = UIDragDropItem.Restriction.None;
  11.  
  12.  
  13.         // Play scale animation after placing the card and scale to the size of the current slot
  14.         TweenScale.Begin(drag, .01f, new Vector3(.4f, .4f));
  15.     }
  16.  


Dragging from the scroll view into the slot works fine, but I have two problems here. The first problem is, then I drag the card outside the slot and drop it anywhere outside the slot, it stays on the current place and don't jump back like it does with UIGrid or UITable. But I want the card to return to the slot, if the drop was invalid. How can i achieve this?
Second problem is, the TweenScale starts playing sometime at once sometime after 2-4 seconds delay. Any idea where this delay coming from?

Thanks in advance
« Last Edit: April 10, 2014, 02:05:13 PM by DarthIwan »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DragItemView re positioning and Tween lag
« Reply #1 on: April 11, 2014, 06:57:03 AM »
Look at ExampleDragDropItem script. It handles your first question inside. If it's released over the surface, one thing happens. If it's not, another thing happens.

No idea about your tween. I suggest adding a Debug.Log into the tween to see where it's being called from.

DarthIwan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: DragItemView re positioning and Tween lag
« Reply #2 on: April 11, 2014, 07:29:45 AM »
Thank you very much! I will look into the Log for the Tween problem.

But unfortunately I get two null reference errors if I use inheritance of UIDragDropItem:

NullReferenceException
UIDragDropItem.OnDragDropStart () (at Assets/NGUI/Scripts/Interaction/UIDragDropItem.cs:148)
UIDragDropItem.OnDragStart () (at Assets/NGUI/Scripts/Interaction/UIDragDropItem.cs:110)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:823)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1411)
UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:1111)
UICamera:ProcessTouches() (at Assets/NGUI/Scripts/UI/UICamera.cs:1181)
UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:971)

and

NullReferenceException: Object reference not set to an instance of an object
UIDragDropItem.OnDrag (Vector2 delta) (at Assets/NGUI/Scripts/Interaction/UIDragDropItem.cs:120)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:823)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1420)
UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:1111)
UICamera:ProcessTouches() (at Assets/NGUI/Scripts/UI/UICamera.cs:1181)
UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:971)

Any idea what I'm doing wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DragItemView re positioning and Tween lag
« Reply #3 on: April 11, 2014, 07:51:34 AM »
You overwrote the "Start" function and didn't call base.Start().

DarthIwan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: DragItemView re positioning and Tween lag
« Reply #4 on: April 11, 2014, 08:11:23 AM »
Oh, shame on me!  :o

Thank you very much! :)

DarthIwan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: DragItemView re positioning and Tween lag
« Reply #5 on: April 11, 2014, 10:05:34 AM »
I put Debug.Log in TweenScale and UITweener classes. Strange thing is, UITweener calls many times the Update function without playing the animation. I cant figure out why the animation starts playing after 20-100 Update-Function calls.

Have you any ideas?


EDIT: Ok, I've found the problem. I'm playing the scale animation while moving cards from deck to the hand. Every card gets own delay and I do not reset the TweenScale component on the card.  ::)
« Last Edit: April 11, 2014, 10:19:27 AM by DarthIwan »