Author Topic: Adding prefabs of UIDragPanelContents is too large when Instantiated to scene  (Read 5197 times)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
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?
« Last Edit: July 11, 2012, 08:30:11 PM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

simon129

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 20
    • View Profile
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)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
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.
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You should be using NGUITools.AddChild instead of Instantiate.

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