using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
/** 
 | 
这是新的二级界面加载器 
 | 
*/ 
 | 
  
 | 
public enum FrameSize 
 | 
{ 
 | 
    Free, 
 | 
    XLarge, 
 | 
    Large, 
 | 
    Medium, 
 | 
    Small, 
 | 
} 
 | 
  
 | 
[ExecuteAlways] 
 | 
public class SecondFrameLoader2 : UIPrefabLoader 
 | 
{ 
 | 
    [SerializeField] public FrameSize frameSize; 
 | 
  
 | 
    [SerializeField] public Vector2 size; 
 | 
  
 | 
    public string m_TitleKey; 
 | 
  
 | 
    public override string prefabName { get { return "SecondFrame"; } } 
 | 
  
 | 
    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<UIBase>(); 
 | 
        button.AddListener(() =>//关闭按钮 
 | 
        { 
 | 
            Debug.Log("关闭窗口"); 
 | 
            window.CloseWindow(); 
 | 
        }); 
 | 
        var text = this.GetComponentInChildren<Text>(); 
 | 
        if (text != null) 
 | 
        { 
 | 
            if (Application.isPlaying) 
 | 
            { 
 | 
                text.fontSize = 24; 
 | 
                text.resizeTextForBestFit = false; 
 | 
                text.rectTransform.sizeDelta = new Vector2(24, 141); 
 | 
                if (!string.IsNullOrEmpty(m_TitleKey)) 
 | 
                    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); 
 | 
    } 
 | 
  
 | 
} 
 |