using System.Collections; using System.Collections.Generic; using UnityEngine; [ExecuteInEditMode] public class MyUIWidgetAdjustWidth : MonoBehaviour { public UIWidget widget; public int offset = 0; public float sizeAdjust = 1; // Start is called before the first frame update void Start() { init(); } public void init() { if (widget == null) { widget = GetComponent(); } UIRoot root = UIRoot.list[0]; sizeAdjust = (root != null) ? root.pixelSizeAdjustment : 1f; sizeAdjust = sizeAdjust < 0.001f ? 1 : sizeAdjust; OnEnable(); } private void Awake() { init(); } #if UNITY_EDITOR private void Update() { OnEnable(); } #endif void OnEnable() { if (widget) { widget.width = (int)(Screen.width * sizeAdjust - offset * 2); } } }