100 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using UnityEngine.Events;
 | |
| 
 | |
| namespace MMO
 | |
| {
 | |
|     public class MMOUIBase : MonoBehaviour
 | |
|     {
 | |
|         public Action DelClose;
 | |
| 
 | |
|         public bool IsOpened => gameObject.activeSelf;
 | |
|         public bool IsStack = true;
 | |
|         public bool AdaptIphoneX = true;
 | |
| 
 | |
|         protected RectTransform mRect;
 | |
| 
 | |
|         private float mOffsetY = 80;
 | |
| 
 | |
|         private void Awake()
 | |
|         {
 | |
|             if (AdaptIphoneX)
 | |
|             {
 | |
|                 mRect = GetComponent<RectTransform>();
 | |
|                 if (mRect != null)
 | |
|                 {
 | |
|                     if (IsIphoneX)
 | |
|                     {
 | |
|                         mRect.offsetMax = new Vector2(mRect.offsetMax.x, -mOffsetY);
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             OnInit();
 | |
|         }
 | |
| 
 | |
|         protected virtual void OnInit()
 | |
|         {
 | |
| 
 | |
|         }
 | |
| 
 | |
|         public virtual void OnOpen()
 | |
|         {
 | |
| 
 | |
|         }
 | |
| 
 | |
|         public virtual void OnClose()
 | |
|         {
 | |
|             DelClose?.Invoke();
 | |
|         }
 | |
| 
 | |
|         public virtual void OnFocus(bool pFocus)
 | |
|         {
 | |
| 
 | |
|         }
 | |
| 
 | |
|         public void Close()
 | |
|         {
 | |
|             MMOModule.Instance.UIMgr.CloseUI(this);
 | |
|         }
 | |
| 
 | |
|         protected void BindBtn(Button pBtn, UnityAction pDel)
 | |
|         {
 | |
|             pBtn.onClick.AddListener(pDel);
 | |
|         }
 | |
| 
 | |
|         private bool IsIphoneX
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 string tModelStr = SystemInfo.deviceModel;
 | |
| 
 | |
|                 if (tModelStr.Contains("iPhone"))
 | |
|                 {
 | |
|                     string[] tNumStrs = tModelStr.Replace("iPhone", "").Split(',');
 | |
|                     int tNumber1 = 0, tNumber2 = 0;
 | |
| 
 | |
|                     if (int.TryParse(tNumStrs[0], out tNumber1) && int.TryParse(tNumStrs[1], out tNumber2))
 | |
|                     {
 | |
|                         if (tNumber1 == 10 && (tNumber2 == 3 || tNumber2 == 6))//Include iPhoneX
 | |
|                             return true;
 | |
| 
 | |
|                         if (tNumber1 == 12 && tNumber2 == 8)//Exclude iPhoneSE2
 | |
|                             return false;
 | |
| 
 | |
|                         if (tNumber1 >= 11)
 | |
|                             return true;
 | |
|                     }
 | |
|                 }
 | |
| 
 | |
|                 if (Mathf.Abs((float)Screen.height / Screen.width - 2436 / 1125f) <= 0.01f)
 | |
|                     return true;
 | |
| 
 | |
|                 return false;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| } |