You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			154 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
		
		
			
		
	
	
			154 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
| 
											2 years ago
										 | using System; | ||
|  | using System.Collections.Generic; | ||
|  | using UnityEngine; | ||
|  | using FairyGUI; | ||
|  | using Articy.Unity; | ||
|  | 
 | ||
|  | namespace Game | ||
|  | { | ||
|  |     public interface IUIPageBase | ||
|  |     { | ||
|  |         void Update(); | ||
|  |         void FixedUpdate(); | ||
|  |         void Destroy(); | ||
|  |         void Create(EuiPage pageType); | ||
|  |         void Open(params object[] values); | ||
|  |         void Close(); | ||
|  |         bool IsActive(); | ||
|  |         bool IsFullPage(); | ||
|  |         List<EuiPage> GetSubPages(); | ||
|  |         void AddSubPage(EuiPage subPage); | ||
|  |         void RemoveSubPage(EuiPage subPage); | ||
|  |         void RemoveSubPageAll(); | ||
|  |     } | ||
|  | 
 | ||
|  |     public class UIPageBase<T> : MetaDataHandler, IUIPageBase where T : GComponent, new() | ||
|  |     { | ||
|  |         protected T View; | ||
|  |         private EuiPage _mPageType; | ||
|  |         private bool _isFullScreenUI; | ||
|  |         private readonly List<EuiPage> _subPageList; | ||
|  | 
 | ||
|  |         protected UIPageBase() | ||
|  |         { | ||
|  |             _subPageList = new List<EuiPage>(); | ||
|  |         } | ||
|  | 
 | ||
|  |         public virtual void Update() | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         public virtual void FixedUpdate() | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         public bool IsActive() | ||
|  |         { | ||
|  |             return View.visible; | ||
|  |         } | ||
|  | 
 | ||
|  |         public bool IsFullPage() | ||
|  |         { | ||
|  |             return _isFullScreenUI; | ||
|  |         } | ||
|  | 
 | ||
|  |         protected virtual void OnInput(PPlayerInput context) | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         protected virtual void OnDestroy() | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         protected virtual void OnCreate() | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         protected virtual void OnOpen() | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         protected virtual void OnOpen(params object[] values) | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         protected virtual void OnClose() | ||
|  |         { | ||
|  |         } | ||
|  | 
 | ||
|  |         public void Create(EuiPage pageType) | ||
|  |         { | ||
|  |             _mPageType = pageType; | ||
|  |             OnCreate(); | ||
|  |         } | ||
|  | 
 | ||
|  |         public void Destroy() | ||
|  |         { | ||
|  |             OnDestroy(); | ||
|  |         } | ||
|  | 
 | ||
|  |         public void Open(params object[] values) | ||
|  |         { | ||
|  |             View.visible = true; | ||
|  |             EventManager.Instance.AddEvent<PPlayerInput>(EEvent.PlayerInput, OnInput); | ||
|  |             if (values.Length > 0) | ||
|  |             { | ||
|  |                 OnOpen(values); | ||
|  |             } | ||
|  |             else | ||
|  |             { | ||
|  |                 OnOpen(); | ||
|  |             } | ||
|  |             CreateBind(); | ||
|  |         } | ||
|  | 
 | ||
|  |         public void Close() | ||
|  |         { | ||
|  |             View.visible = false; | ||
|  |             EventManager.Instance.RemoveEvent<PPlayerInput>(EEvent.PlayerInput, OnInput); | ||
|  |             ClearBind(); | ||
|  |             OnClose(); | ||
|  |         } | ||
|  | 
 | ||
|  |         protected void CreateUI(bool isFull = false) | ||
|  |         { | ||
|  |             View = (T)typeof(T).GetMethod("CreateInstance")?.Invoke(null, null); | ||
|  |             if (View == null) return; | ||
|  |             View.sortingOrder = (int)_mPageType; | ||
|  |             View.fairyBatching = true; | ||
|  |             _isFullScreenUI = isFull; | ||
|  |             GRoot.inst.AddChild(View); | ||
|  |         } | ||
|  | 
 | ||
|  |         public List<EuiPage> GetSubPages() | ||
|  |         { | ||
|  |             return _subPageList; | ||
|  |         } | ||
|  | 
 | ||
|  |         public void AddSubPage(EuiPage subPage) | ||
|  |         { | ||
|  |             _subPageList.Add(subPage); | ||
|  |         } | ||
|  | 
 | ||
|  |         public void RemoveSubPage(EuiPage subPage) | ||
|  |         { | ||
|  |             _subPageList.Remove(subPage); | ||
|  |         } | ||
|  | 
 | ||
|  |         public void RemoveSubPageAll() | ||
|  |         { | ||
|  |             _subPageList.Clear(); | ||
|  |         } | ||
|  | 
 | ||
|  |         protected Vector3 GetScreenPos(Vector3 pos) | ||
|  |         { | ||
|  |             return CameraManager.Instance.GetScreenPos(pos); | ||
|  |         } | ||
|  | 
 | ||
|  |         protected NTexture Texture(ArticyObject icon) | ||
|  |         { | ||
|  |             var texture = Util.LoadDraft<Texture2D>(icon); | ||
|  |             return new NTexture(texture); | ||
|  |         } | ||
|  |     } | ||
|  | } |