Files
tianrunCRM/Assets/trCRM/Scripts/ui/MyUIWidgetAdjustWidth.cs
2020-07-04 14:41:25 +08:00

49 lines
945 B
C#

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