Author Topic: Panel Anchor  (Read 2337 times)

rookie_coder

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 14
    • View Profile
Panel Anchor
« on: March 17, 2014, 09:45:22 PM »
I am working on a Match-3 game. I dynamically create a grid of prefabs (the Grid gameobject) within a Panel. For now, I would like to do the following. Please advise as to the best practice.

1. Anchor the panel to the UIRoot, so that size of the panel changes proportionally for mobile.

2. Base the size of the Grid on the size of the Panel as determined in 1. Currently I am hard-coding the cell size as follows. I want it to be based on the Panel size dynamically.

instance.transform.localPosition = new Vector3(x * cellWidth, y * -cellHeight, 0f);

3. Position the Grid starting at the upper left hand corner of the Panel. Basically I want the grid to resize dynamically based on the panel size.

This is my hierarchy:

Main Camera
UIRoot
   Camera
   Panel
      Grid

Thanks in advance

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Panel Anchor
« Reply #1 on: March 18, 2014, 09:53:58 PM »
Panels simply collect widgets and create draw calls. They have no size, so they can't be anchored.

Only if you enable clipping, turning them into scroll views, do they actually gain a rectangle to work with -- and along with it the anchoring capability.

To position the content in the top left corner of the scroll view, change the scroll view's Origin point.