Author Topic: Tweens are being added at runtime? Why? Help!  (Read 2434 times)

SuperTalesNat

  • Guest
Tweens are being added at runtime? Why? Help!
« on: May 04, 2013, 10:51:22 PM »
I'm using NGUITool.AddChild to create multiple GameObjects that are then children of a UIDragpanel/Grid.

I've been seeing an issue where the Gameobject is created properly, but for some odd reason has a tweenposition added to it (where the original GameObject doesnt have any) with the 'from' position is set to the proper place in the grid, and the 'to' is set to 0,0,0, so when i hover over it in the editor build, or click on it (its a button), it jumps back to position 1 in the grid.

Even more odd is the fact that no matter how many items i dynamically add into the grid, the first and last object dont have this problem, just ALL of the gameobjects in-between.

Has anyone seen anything like this, or know why/how this is happening? I've tried hard to fix it, but its like something is happening in a black box and i have zero visibility into how/why.

Thanks in advance, looking forward to any/all help.

Here's the code thats creating the gallery items based on images in a directory:

  1.         DirectoryInfo dir = new DirectoryInfo(filePath);       
  2.                 FileInfo[] m_galleryList = dir.GetFiles("*.jpg");
  3.                 int NumGallery = m_galleryList.GetLength(0);
  4.                
  5.                 Debug.Log("You have " + NumGallery + " Movie Files in your Gallery");
  6.                
  7.                 foreach (FileInfo f in m_galleryList)
  8.                 {
  9.                         string fileName = System.IO.Path.GetFileNameWithoutExtension(f.Name);
  10.                         string fullFile = ("file:"+f.FullName);
  11.                        
  12.                         WWW www = new WWW(fullFile);
  13.                                
  14.                         yield return www;
  15.                                                                        
  16.                         GalleryUITexture.name = ("tex_"+ fileName);
  17.                         GalleryUITexture.material = new Material(Shader.Find("Unlit/Transparent Colored"));
  18.                         GalleryUITexture.material.name = ("mat_"+fileName);
  19.                         GalleryUITexture.material.mainTexture = www.texture;
  20.                         GalleryTemplate.name = ("gallery_"+fileName);
  21.                                                
  22.                         GameObject galleryObj = NGUITools.AddChild(Grid.gameObject, GalleryTemplate);
  23.                         galleryObj.name = fileName;                    
  24.                 }
  25.                 Grid.Reposition();             
  26.  





SuperTalesNat

  • Guest
Re: Tweens are being added at runtime? Why? Help!
« Reply #1 on: May 05, 2013, 11:12:43 PM »
Anyone? I'm quite stuck at this point, and have zero clue why this behavior is occurring.

The AddChild code seems to be right, and the instanced GameObjects seem to be just fine, until i hover or click on them, when they suddenly have a runtime TweenPosition and TweenScale attached and executed, sending the GameObject back to 0,0,0 in the grid. How is this even possible without a script on the object telling it to add those components, and then execute them??

Nathaniel Hunter
SuperTales Inc.

maoguo.zhang

  • Guest
Re: Tweens are being added at runtime? Why? Help!
« Reply #2 on: May 06, 2013, 12:39:27 AM »
It seems that the item prefab must be created and modified under the grid's gameobject otherwise there may be something wrong with the grid.

SuperTalesNat

  • Guest
Re: Tweens are being added at runtime? Why? Help!
« Reply #3 on: May 06, 2013, 01:41:01 AM »
Figured it out.

The UIButtonOffset on hover event is by default, set to 0,0,0, and click is by default set to 2,-2,0, which obviously when touched, hovered, etc, will send the Button back to the root of the grid.

Solution is to parent the button to a game object, and use the parent GameObject in the script, not the button.

So simple rule for anyone reading this, don't instantiate a button into a grid without a parent object.