59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using NEG.UI.Area;
 | |
| using NEG.UI.UnityUi.Buttons;
 | |
| using NEG.UI.UnityUi.WindowSlot;
 | |
| using NEG.UI.Window;
 | |
| using NEG.UI.WindowSlot;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| namespace NEG.UI.UnityUi.Window
 | |
| {
 | |
|     public class MonoWindow : MonoBehaviour, IWindow
 | |
|     {
 | |
|         public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
 | |
|         public IWindowSlot Parent { get; private set; }
 | |
| 
 | |
|         public bool IsMainWindow { get; private set; }
 | |
|         
 | |
|         private IWindowSlot DefaultWindowSlot => windowSlots[0];
 | |
|         
 | |
|         [SerializeField] private List<MonoWindowSlot> windowSlots;
 | |
|         [SerializeField] private WindowController controller;
 | |
| 
 | |
|         public void SetOpenedState(IWindowSlot parentSlot)
 | |
|         {
 | |
|             gameObject.SetActive(true);
 | |
|             Parent = parentSlot;
 | |
|             if (controller != null) 
 | |
|                 controller.OnOpened();
 | |
|         }
 | |
| 
 | |
|         public void SetData(object data)
 | |
|         {
 | |
|             if (controller != null) 
 | |
|                 controller.SetData(data);
 | |
|         }
 | |
| 
 | |
|         public void SetClosedState()
 | |
|         {
 | |
|             gameObject.SetActive(false);
 | |
|             Parent = null;
 | |
|             ((ISlotsHolder)this).CloseAllWindows();
 | |
|         }
 | |
| 
 | |
|         private void Awake() => ((IWindow)this).SetClosedState();
 | |
| 
 | |
|         private void OnValidate()
 | |
|         {
 | |
|             if (controller == null)
 | |
|                 controller = GetComponent<WindowController>();
 | |
|         }
 | |
| 
 | |
|         public void OpenWindow(IWindow window, object data = null)
 | |
|         {
 | |
|             DefaultWindowSlot.AttachWindow(window);
 | |
|             window.SetData(data);
 | |
|         }
 | |
|     }
 | |
| } |