ngui 适配iphone x
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(UIPanel))]
public class FixedUIRect : MonoBehaviour
{
public enum SAVE_AREA
{
FULL_SCREEN,
SAVE_AREA_WITH_BOTTOM,
SAVE_AREA,
}
public SAVE_AREA type = SAVE_AREA.FULL_SCREEN;
public float IPHONE_X_SAVE_RASIO = 0.965f;
private UIPanel panel;
void OnEnable ()
{
FixClipRegion ();
}
void Start ()
{
FixClipRegion ();
}
private bool IsIphoneX()
{
return true;
// return NativeManager.inst.IsIPHONEX ();
}
private void FixClipRegion ()
{
panel = GetComponent<UIPanel> ();
UIRoot rt = panel.root;
if (panel != null && IsIphoneX() && rt != null) {
panel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
if (type == SAVE_AREA.SAVE_AREA_WITH_BOTTOM)
{
panel.baseClipRegion = new Vector4 (0, 0, panel.root.manualHeight * (757 / 375f), panel.root.manualHeight);
}
else if (type == SAVE_AREA.SAVE_AREA)
{
panel.baseClipRegion = new Vector4(0, 0, panel.root.manualHeight * (785 / 375f), panel.root.manualHeight);
float offsetY = (1 - IPHONE_X_SAVE_RASIO) * panel.root.manualHeight / 2;
gameObject.transform.localPosition = new Vector3(0,offsetY);
float scale = IPHONE_X_SAVE_RASIO;
gameObject.transform.localScale = scale * Vector3.one;
}
else
{
panel.baseClipRegion = new Vector4 (0, 0, panel.root.manualHeight * (812 / 375f), panel.root.manualHeight);
}
}
}
}