-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutElementUtil.cs
32 lines (28 loc) · 1.03 KB
/
LayoutElementUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using UnityEngine;
using UnityEngine.UI;
namespace InfinityScroll
{
public static class LayoutElementUtil
{
public static float GetMinSize(GameObject go, int axis)
{
return GetLayoutElementSize(go, element => axis == 0 ? element.minWidth : element.minHeight);
}
public static float GetPreferredSize(GameObject go, int axis)
{
return GetLayoutElementSize(go, element => axis == 0 ? element.preferredWidth : element.preferredHeight);
}
public static float GetFlexibleSize(GameObject go, int axis)
{
return GetLayoutElementSize(go, element => axis == 0 ? element.flexibleWidth : element.flexibleHeight);
}
private static float GetLayoutElementSize(GameObject go, Func<LayoutElement, float> func)
{
if (!go) return -1;
var layoutElement = go.GetComponent<LayoutElement>();
if (!layoutElement) return -1;
return func(layoutElement);
}
}
}