码迷,mamicode.com
首页 > 其他好文 > 详细

流海屏适配

时间:2020-05-21 11:55:21      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:ddl   tor   dev   reac   float   move   ali   cas   als   

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum AnchorPreSet
{
    MIDDLE,
    TOP,
    BUTTOM,
}
[System.Serializable]
public class UIAdapt{
    public AnchorPreSet uiPosition;
    public Transform transform;
    [Header("移动距离要大于等于零")]
    public float moveDistance = 100;
    public bool enableAdaptHeight = false;
    public float adaptHeight;
}
public class UIAutoFix : MonoBehaviour
{
    public List<UIAdapt> UIAdaptList;
    private float devHeigth = 1920;
    private float devWidgth = 1080;
    
    public void Awake()
    {
        if(UIAdaptList == null || UIAdaptList.Count <= 0)
        {
            return;
        }
        if(Screen.height / (float)Screen.width > (devHeigth / devWidgth) && Screen.height != 1334 && Screen.width != 750)
        {
            foreach(UIAdapt uiAdpat in UIAdaptList)
            {
                AnchorPreSet uiPosition = uiAdpat.uiPosition;
                switch (uiPosition)
                {
                    case AnchorPreSet.TOP:
                        uiAdpat.transform.position -= Vector3.up * uiAdpat.moveDistance;
                        break;
                    case AnchorPreSet.MIDDLE:
                        if(uiAdpat.transform.localPosition.y > 0)
                        {
                            uiAdpat.transform.position += Vector3.up * uiAdpat.moveDistance;

                        }else if(uiAdpat.transform.localPosition.y < 0)
                        {
                            uiAdpat.transform.localPosition -= Vector3.up * uiAdpat.moveDistance;
                        }
                        break;
                    case AnchorPreSet.BUTTOM:
                        uiAdpat.transform.position -= Vector3.up * uiAdpat.moveDistance;
                        break;
                }
                if (uiAdpat.enableAdaptHeight)
                {
                    RectTransform rect = uiAdpat.transform.gameObject.GetComponent<RectTransform>();
                    rect.sizeDelta = new Vector2(rect.sizeDelta.x, rect.sizeDelta.y + uiAdpat.adaptHeight);
                }
            }
           
        }
        
    }
}

 

流海屏适配

标签:ddl   tor   dev   reac   float   move   ali   cas   als   

原文地址:https://www.cnblogs.com/sy-liu/p/12929600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!