Last active
April 13, 2021 22:09
-
-
Save Tymski/162f3d2210270ef8dec61da07f0521b4 to your computer and use it in GitHub Desktop.
When you put an AspectRatioFitter inside a LayoutGroup, it breaks your layout. This is a fix for this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
[RequireComponent(typeof(AspectRatioFitter))] | |
[RequireComponent(typeof(RectTransform))] | |
[ExecuteInEditMode] | |
public class WorkingAspectRatioFitter : MonoBehaviour | |
{ | |
AspectRatioFitter aspectRatioFitter; | |
RectTransform rectTransform; | |
private void Awake() | |
{ | |
aspectRatioFitter = GetComponent<AspectRatioFitter>(); | |
aspectRatioFitter.enabled = false; | |
rectTransform = GetComponent<RectTransform>(); | |
} | |
private void Update() | |
{ | |
aspectRatioFitter.enabled = true; | |
aspectRatioFitter.SetLayoutHorizontal(); | |
aspectRatioFitter.SetLayoutVertical(); | |
aspectRatioFitter.SetLayoutHorizontal(); | |
aspectRatioFitter.enabled = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment