Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Genhain on May 13, 2014, 03:21:12 AM

Title: UIGrid get most recent element added.
Post by: Genhain on May 13, 2014, 03:21:12 AM
I have inherited from UIGrid and i was wondering if there is a way to...when any element get's added there is perhaps a callback method that fires and also providing the element that was just added in the parameters? I know you could could just iterate through the children but that could end up requiring a lot of if statements to find out if it's the one you want.

Is there a method or functionality that allows this?

Cheers.
Title: Re: UIGrid get most recent element added.
Post by: Genhain on May 13, 2014, 07:41:05 AM
I Came up with a solution that requires quite a bit of extension on top of the NGUI classes, luckily most of them seem to be setup to allow this.

First i have my own base class

  1. public class MyGrid : UIGrid
  2. {
  3.         // Use this for initialization
  4.         protected override void Start()
  5.         {
  6.                 base.Start();
  7.         }
  8.        
  9.         // Update is called once per frame
  10.         protected override void Update ()
  11.         {
  12.                 base.Update();
  13.         }
  14.  
  15.         public virtual void CardDroppedIntoGrid(GameObject gObject)
  16.         {
  17.  
  18.         }
  19. }
  20.  

and I have a few other grid types that inherit from this and override CardDroppedIntoGrid.

Then I have an extension for UIDragDropItem

  1. public class MyDragDropItemSelection : UIDragDropItem
  2. {
  3.         protected override void OnDragDropRelease (GameObject surface)
  4.         {
  5.                 base.OnDragDropRelease (surface);
  6.  
  7.                 //message grid
  8.                 WCGrid grid =(WCGrid)mGrid;
  9.                 grid.CardDroppedIntoGrid(gameObject);
  10.         }
  11. }
  12.  

and that does the trick