Land Explorer in HomeCamp with boot loading, journal UI, and CDN publish tooling.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AOT.UI
|
||||
{
|
||||
/// <summary>Fill the screen without stretching the portrait illustration.</summary>
|
||||
[RequireComponent(typeof(Image))]
|
||||
public sealed class BootArtworkCover : MonoBehaviour
|
||||
{
|
||||
void OnEnable() => Fit();
|
||||
void LateUpdate() => Fit();
|
||||
void OnRectTransformDimensionsChange() => Fit();
|
||||
|
||||
void Fit()
|
||||
{
|
||||
var image = GetComponent<Image>();
|
||||
if (image == null || image.sprite == null || transform.parent == null) return;
|
||||
var parent = transform.parent as RectTransform;
|
||||
if (parent == null || parent.rect.width <= 0 || parent.rect.height <= 0) return;
|
||||
var rect = (RectTransform)transform;
|
||||
float aspect = image.sprite.rect.width / image.sprite.rect.height;
|
||||
float width = Mathf.Max(parent.rect.width, parent.rect.height * aspect);
|
||||
Vector2 size = new Vector2(width, width / aspect);
|
||||
rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(.5f, .5f);
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
if ((rect.sizeDelta - size).sqrMagnitude > .01f) rect.sizeDelta = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user