标签: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