Files
FueraDeEscala/Assets/Game Kit Controller/Scripts/Menu/resetScrollRectOnEnable.cs

66 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class resetScrollRectOnEnable : MonoBehaviour
{
2026-03-29 23:03:14 -07:00
[Header ("Main Settings")]
[Space]
2026-03-29 23:03:14 -07:00
public bool resetEnabled = true;
public bool useVerticalPosition;
2026-03-29 23:03:14 -07:00
public float positionValue;
2026-03-29 23:03:14 -07:00
[Space]
[Header ("Debug")]
[Space]
2026-03-29 23:03:14 -07:00
public bool showDebugPrint;
2026-03-29 23:03:14 -07:00
[Space]
[Header ("Components")]
[Space]
2026-03-29 23:03:14 -07:00
public RectTransform mainRectTransform;
public ScrollRect mainScrollRect;
2026-03-29 23:03:14 -07:00
void OnEnable ()
{
if (resetEnabled) {
resetRectTransform ();
}
}
2026-03-29 23:03:14 -07:00
public void resetRectTransform ()
{
if (gameObject.activeInHierarchy) {
StartCoroutine (resetRectTransformCoroutine ());
}
}
2026-03-29 23:03:14 -07:00
IEnumerator resetRectTransformCoroutine ()
{
if (showDebugPrint) {
print ("reseting rect transform");
}
2026-03-29 23:03:14 -07:00
if (mainRectTransform != null) {
LayoutRebuilder.ForceRebuildLayoutImmediate (mainRectTransform);
}
2026-03-29 23:03:14 -07:00
yield return new WaitForEndOfFrame ();
yield return new WaitForEndOfFrame ();
2026-03-29 23:03:14 -07:00
if (mainScrollRect != null) {
if (useVerticalPosition) {
mainScrollRect.verticalNormalizedPosition = positionValue;
} else {
mainScrollRect.horizontalNormalizedPosition = positionValue;
}
}
}
}