// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-01-30
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace G
{
///
/// UI
///
public class UIHelper : MonoBehaviour
{
#region Field
#endregion
#region Method
public void SetSafeRatio(float ratio)
{
var sy = KPlatform.Instance.safeAreaTop * ratio;
if (sy > 16f)
for (int i = 0; i < transform.childCount; i++)
{
var child = transform.GetChild(i) as RectTransform;
if (child && child.name != "Guide")
{
child.offsetMax = new Vector2(0, 16f - sy);
}
}
}
public void SetSafeRatio(int y, float ratio)
{
var sy = y * ratio;
if (sy > 16f)
for (int i = 0; i < transform.childCount; i++)
{
var child = transform.GetChild(i) as RectTransform;
if (child && child.name != "Guide")
{
child.offsetMax = new Vector2(0, 16f - sy);
}
}
}
#endregion
#region Unity
public static UIHelper Instance;
// Use this for initialization
private void Start()
{
Instance = this;
Debug.Log("safeAreaTop " + KPlatform.Instance.safeAreaTop);
if (PlayerPrefs.GetInt("screen_f", 1) != 0)
{
SetSafeRatio(KPlatform.Instance.safeAreaTop, 1f);
}
var canvasScaler = GetComponent();
if (canvasScaler)
{
var cRatio = Screen.height / (float)Screen.width;
var tRatio = 1920f / 1080f;
if (tRatio > cRatio)
{
canvasScaler.matchWidthOrHeight = 1f;
}
else
{
canvasScaler.matchWidthOrHeight = 0f;
}
}
#if !UNITY_EDITOR && SDK_WECHAT_WASM
UnityEngine.EventSystems.EventSystem.current.gameObject.AddComponent();
#endif
}
#endregion
}
}