add
This commit is contained in:
48
Assets/trCRM/Scripts/ui/MyUIWidgetAdjustWidth.cs
Normal file
48
Assets/trCRM/Scripts/ui/MyUIWidgetAdjustWidth.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user