using UnityEngine;
|
using UnityEngine.UI;
|
/**
|
这是新的二级界面加载器
|
*/
|
namespace vnxbqy.UI
|
{
|
|
[ExecuteAlways]
|
public class SecondFrameLoader3 : UIPrefabLoader
|
{
|
[SerializeField] public FrameSize frameSize;
|
|
[SerializeField] public Vector2 size;
|
|
public string m_TitleKey;
|
|
public override string prefabName { get { return "SecondFrameNew"; } }
|
|
public override void Create()
|
{
|
base.Create();
|
UpdateSize();
|
InitUI();
|
}
|
|
private void Update()
|
{
|
if (Application.isPlaying)
|
return;
|
UpdateSize();
|
}
|
|
public void InitUI()
|
{
|
var button = this.GetComponentInChildren<ButtonEx>();
|
var window = this.GetComponentInParent<Window>();
|
button.AddListener(() =>//关闭按钮
|
{
|
DebugEx.Log("关闭窗口");
|
window.Close();
|
});
|
if (!string.IsNullOrEmpty(m_TitleKey))
|
{
|
var text = this.GetComponentInChildren<Text>();
|
if (text != null)
|
{
|
if (Application.isPlaying)
|
text.text = Language.Get(m_TitleKey);
|
else
|
text.text = "当前标题";
|
}
|
}
|
}
|
|
public void UpdateSize()
|
{
|
if (instance == null)
|
return;
|
switch (frameSize)
|
{
|
case FrameSize.XLarge:
|
{
|
SetSize(1000, 650);
|
break;
|
}
|
case FrameSize.Large:
|
{
|
SetSize(800, 650);
|
break;
|
}
|
case FrameSize.Medium:
|
{
|
SetSize(650, 650);
|
break;
|
}
|
case FrameSize.Small:
|
{
|
SetSize(550, 650);
|
break;
|
}
|
case FrameSize.Free:
|
{
|
SetSize(size.x, size.y);
|
break;
|
}
|
}
|
}
|
|
private void SetSize(float width, float height)
|
{
|
if (instance == null)
|
return;
|
(instance.transform as RectTransform).sizeDelta = new Vector2(width, height);
|
}
|
|
}
|
|
}
|