zoukankan      html  css  js  c++  java
  • 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);
    }
    }
    }
    }

  • 相关阅读:
    python开发mysql:索引
    学习笔记之English
    本周学习小结(25/03
    本周学习小结(18/03
    本周学习小结(11/03
    学习笔记之Machine Learning Crash Course | Google Developers
    本周学习小结
    学习笔记之Fluent Python
    Leetcode 4. Median of Two Sorted Arrays
    学习笔记之Python爬虫
  • 原文地址:https://www.cnblogs.com/rexzhao/p/8358431.html
Copyright © 2011-2022 走看看