51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using Sirenix.OdinInspector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class CutsceneIpadScaler : MonoBehaviour
|
|
{
|
|
private const float cutsceneWidth = 1280f, cutsceneHeight = 720f;
|
|
private const float SetDelay = 1f;
|
|
|
|
[SerializeField]
|
|
private RectTransform canva, sizeCanva;
|
|
|
|
private bool isSet = false;
|
|
|
|
// Start is called before the first frame update
|
|
private void OnEnable()
|
|
{
|
|
if (!isSet)
|
|
{
|
|
StartCoroutine(SetSizeCoroutine());
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
private IEnumerator SetSizeCoroutine()
|
|
{
|
|
yield return new WaitForSeconds(SetDelay);
|
|
isSet = true;
|
|
|
|
float cutsceneRatio = cutsceneWidth / cutsceneHeight;
|
|
float ratio = sizeCanva.sizeDelta.x / sizeCanva.sizeDelta.y;
|
|
if (ratio > cutsceneRatio)
|
|
{
|
|
//means device is wider than the cutscene, meaning we should have black bar on left and right, fitting screen height
|
|
float widthMultiplier = sizeCanva.sizeDelta.y / cutsceneHeight;
|
|
Vector2 size = new Vector2(widthMultiplier * cutsceneWidth, sizeCanva.sizeDelta.y);
|
|
canva.sizeDelta = size;
|
|
}
|
|
else
|
|
{
|
|
//black bars at top and bottom
|
|
float heightMultiplier = sizeCanva.sizeDelta.x / cutsceneWidth;
|
|
Vector2 size = new Vector2(sizeCanva.sizeDelta.x, heightMultiplier * cutsceneHeight);
|
|
canva.sizeDelta = size;
|
|
}
|
|
}
|
|
}
|
|
} |