| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using UnityEngine.UI; | 
					
						
							|  |  |  |  | using DG.Tweening; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace MMO | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public class MMOUILoading : MMOUIBase | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         public Action DelInitOver; | 
					
						
							|  |  |  |  |         public Action DelLoadOver; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         [SerializeField] GameObject mGobFirstSign; | 
					
						
							|  |  |  |  |         [SerializeField] Text mTxtProgress; | 
					
						
							|  |  |  |  |         [SerializeField] Image mImgProgress; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  |         private Text mTxtTip; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         private Tweener mTween; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  |         private bool mIsInitHanging = false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private void Awake() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTxtTip = mGobFirstSign.GetComponent<Text>(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         public override void OnOpen() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             base.OnOpen(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             mGobFirstSign.SetActive(!MMOUserData.Instance.HasFirstLoaded); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             mImgProgress.fillAmount = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             mTween = mImgProgress.DOFillAmount(UnityEngine.Random.Range(0.93f, 0.97f), MMOUserData.Instance.HasFirstLoaded ? 1 : 10); | 
					
						
							|  |  |  |  |             mTween.onUpdate = UpdateText; | 
					
						
							|  |  |  |  |             mTween.onComplete = OnInitOver; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         public void FinishRest() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (mTween != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mTween.onUpdate = null; | 
					
						
							|  |  |  |  |                 mTween.onComplete = null; | 
					
						
							|  |  |  |  |                 mTween.Kill(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             mTween = mImgProgress.DOFillAmount(1, 0.5f); | 
					
						
							|  |  |  |  |             mTween.onUpdate = UpdateText; | 
					
						
							|  |  |  |  |             mTween.onComplete = OnLoadOver; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private void UpdateText() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTxtProgress.text = string.Format("LOADING...{0:f0}%", Mathf.Clamp(mImgProgress.fillAmount * 100, 0, 100)); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private void OnInitOver() | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  |             if (Application.internetReachability == NetworkReachability.NotReachable) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mGobFirstSign.SetActive(true); | 
					
						
							|  |  |  |  |                 mTxtTip.text = "Loading failed, please check the network"; | 
					
						
							|  |  |  |  |                 mIsInitHanging = true; | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             DelInitOver?.Invoke(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private void OnLoadOver() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             DelLoadOver?.Invoke(); | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  |             Close(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         public void NotifyInitOver() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (IsOpened && mIsInitHanging) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mGobFirstSign.SetActive(false); | 
					
						
							|  |  |  |  |                 DelInitOver?.Invoke(); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |