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);
    }
    }
    }
    }

  • 相关阅读:
    研究生
    linux下C++开发工具
    GCC and G++ install
    linux yum命令详解
    OpenCV:SURF算法浅析
    linux内核(kernel)版本号的意义
    常见排序算法
    bash:command not found
    C++ 面向对象(数据封装)
    HTML5 script 标签的 crossorigin 和integrity属性的作用
  • 原文地址:https://www.cnblogs.com/rexzhao/p/8358431.html
Copyright © 2011-2022 走看看