Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Disastercake on July 11, 2012, 08:27:34 PM

Title: Adding prefabs of UIDragPanelContents is too large when Instantiated to scene
Post by: Disastercake on July 11, 2012, 08:27:34 PM
When I instantiate a UIDragPanelContents it comes in as a ridiculous size.  This also happens if I drag it directly to the scene, but not if I drag it directly to the UIGrid.

How can I maintain the original size of the prefab when adding it to the UIDragPanel via scripting?
Title: Re: Adding prefabs of UIDragPanelContents is too large when Instantiated to scene
Post by: simon129 on July 11, 2012, 10:23:48 PM
Everything NGUI should be under UIRoot, and their scale should be based on pixel.

you can box ur sprits with an empty gameobject with local scale (1,1,1), and after u instantiate and parent it to UIRoot/Anchor/UIPanel/,  make sure it's local scale is (1,1,1)
Title: Re: Adding prefabs of UIDragPanelContents is too large when Instantiated to scene
Post by: Disastercake on July 12, 2012, 02:45:58 AM
I'm doing exactly this from what I can tell.  Here is my code that instantiates the prefab then parent's it:

  1. GameObject newItem = (GameObject)Instantiate(Prefab);
  2. newItem.transform.parent = theUIGrid.transform;
  3.  

Is there something else that should be done in this case?  Because it's not sizing it correctly, while if I directly drag the prefab to the UIGrid in the heirarchy, it sizes correctly, but dragging the prefab to the scene un-parented makes it abnormally large like the code above causes.
Title: Re: Adding prefabs of UIDragPanelContents is too large when Instantiated to scene
Post by: ArenMook on July 12, 2012, 04:39:54 AM
You should be using NGUITools.AddChild instead of Instantiate.

Instantiate brings everything in with whatever scale you have it on the prefab.