You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.6 KiB
33 lines
1.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Scrollable : MonoBehaviour {
|
|
public int ignoreElements = 0;
|
|
public bool horizontal = false;
|
|
void Start() {
|
|
Reload();
|
|
}
|
|
|
|
public void Reload() {
|
|
var size = 0f;
|
|
if (horizontal) {
|
|
size = (transform.childCount - ignoreElements) * ((transform.GetChild(0).GetComponent<RectTransform>().sizeDelta.x * transform.GetChild(0).localScale.x) + GetComponent<HorizontalLayoutGroup>().spacing);
|
|
} else {
|
|
size = (transform.childCount - ignoreElements) * (transform.GetChild(0).GetComponent<RectTransform>().sizeDelta.y + GetComponent<VerticalLayoutGroup>().spacing);
|
|
}
|
|
if (horizontal) {
|
|
GetComponent<RectTransform>().offsetMin = Vector2.zero;
|
|
}else {
|
|
GetComponent<RectTransform>().offsetMax = Vector2.zero;
|
|
}
|
|
if (horizontal) {
|
|
GetComponent<RectTransform>().offsetMax = new Vector2(-(transform.parent.GetComponent<RectTransform>().sizeDelta.x > size ? 0 : -size + transform.parent.GetComponent<RectTransform>().sizeDelta.x + GetComponent<HorizontalLayoutGroup>().spacing), GetComponent<RectTransform>().offsetMax.y);
|
|
} else {
|
|
GetComponent<RectTransform>().offsetMin = new Vector2(GetComponent<RectTransform>().offsetMin.x, transform.parent.GetComponent<RectTransform>().sizeDelta.y > size ? 0 : -size + transform.parent.GetComponent<RectTransform>().sizeDelta.y + GetComponent<VerticalLayoutGroup>().spacing);
|
|
}
|
|
}
|
|
|
|
void Update() {}
|
|
}
|
|
|