Author Topic: New anchoring system and prefabs  (Read 4616 times)

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
New anchoring system and prefabs
« on: December 11, 2013, 03:53:28 PM »
Hi,

I have a background sprite that i want to be stretched to fill the screen and I can't't seem to get it to function properly from a prefab (if in the editor it will adjust to the proper size after hitting ctrl+s twice)

Game Resolution : 800 x 480
UIRoot : Fixed Size - 720
Hierarchy:
UIRoot
-Camera
--Levels Container
---Level (Clone) (UIPanel, no anchoring)
----Background Sprite (UISprite, Unified Anchor (0,0,0,0) Target: Level (Clone))

Background Original Dimensions : 1024 x 576
Background In Game Dimensions : 800 x 480 (whatever the game resolution is)

I'm using Screen.width * UIRoot.GetPixelSizeAdjustment to calculate where to instantiate my level so it can slide in and that reports the correct dimensions (in this case 1080 x 720).

Included in the level prefab are a few sprites with colliders and auto-adjust collider set, the colliders get made very tiny when the prefab is instantiated, if I click off and on the auto-adjust checkbox it sets it to the right size.

I assume these issues are related.

Also I have a few elements that are anchored but also need to be dragged around, I used to just tell the UIAnchor to run once and that worked fine, now that option is not available (or at least I can't find the equivalent).

How do I go about these issues ?
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New anchoring system and prefabs
« Reply #1 on: December 12, 2013, 01:48:04 AM »
Prefabs don't exist in the scene, so there is no UIRoot to use when considering their dimensions. Once the prefab is in the scene, it should work properly.

Draggable objects should not be anchored. I'm not sure how you were using the "run once" option. If you want to anchor something draggable, anchor its parent. Make a UIWidget, anchor it. Make whatever you want draggable a child of it, and don't anchor it.