Tanoda
pb_GridLayoutGroup.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
3using System.Collections;
4
5namespace GILES.Interface
6{
10 public class pb_GridLayoutGroup : GridLayoutGroup, pb_IOnResizeHandler
11 {
12#if UNITY_WEBGL
13 private Vector2 elementSize = new Vector2(93f, 93f);
14#else
15 private Vector2 elementSize = new Vector2(233f, 74f);
16#endif
17
18 public bool maintainAspectRatio = true;
19
20 protected override void Start()
21 {
22 base.Start();
23
24 OnResize();
25 }
26
27 public void OnResize()
28 {
29 float width = (rectTransform.rect.width - spacing.x);
30 float grid = elementSize.x + spacing.x;
31
32 if(width <= grid)
33 return;
34
35 Vector2 cell = Vector2.zero;
36
37 cell.x = elementSize.x + (width % grid) / (float)(((int)width) / ((int)grid));
38
40 cell.y = elementSize.y * (cell.x / elementSize.x);
41
42 cellSize = cell;
43 }
44 }
45}