154 lines
3.8 KiB
C#
154 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
using TH1_UI.Controller.Base;
|
|
using TH1_UI.View.Base;
|
|
using UnityEngine;
|
|
|
|
public interface ViewControllerSubInterface
|
|
{
|
|
// 是否默认打开
|
|
public bool DefaultOpen { get; }
|
|
// 是否控制显示
|
|
void Start(string path, IViewControllerInterface parent);
|
|
public void OnWindowLoadNotify(GameObject windowObj);
|
|
public List<string> GetLoadAtlas();
|
|
public void PreLoad();
|
|
public void Open();
|
|
public void Close();
|
|
public void Destroy();
|
|
}
|
|
|
|
public class ViewControllerSub<T> : ViewControllerSubInterface where T : ViewSub
|
|
{
|
|
public bool DefaultOpen { get; protected set; } = true;
|
|
//
|
|
protected bool ControlActive { get; set; } = false;
|
|
//
|
|
protected T WindowScript { get { return _script; } }
|
|
//
|
|
public GameObject WindowObj { get { return _windowObj; } }
|
|
//
|
|
public IViewControllerInterface Parent { get { return _parent; } }
|
|
//
|
|
public virtual void Start(string path, IViewControllerInterface parent)
|
|
{
|
|
_path = path;
|
|
_parent = parent;
|
|
}
|
|
//
|
|
public virtual bool IsShow()
|
|
{
|
|
if (_script == null)
|
|
{
|
|
return false;
|
|
}
|
|
return _script.IsShow();
|
|
}
|
|
//
|
|
public virtual void Open()
|
|
{
|
|
if (IsShow())
|
|
{
|
|
OnOpen();
|
|
return;
|
|
}
|
|
//
|
|
_TrueOpen();
|
|
}
|
|
//
|
|
public virtual void Close()
|
|
{
|
|
if (!IsShow())
|
|
{
|
|
return;
|
|
}
|
|
//
|
|
_TrueClose();
|
|
}
|
|
//
|
|
public void OnWindowLoadNotify(GameObject windowObj)
|
|
{
|
|
var windowProperty = windowObj.GetComponent<UIWindowProperty>();
|
|
_windowObj = windowProperty.GetGameObject(_path);
|
|
ViDebuger.AssertError(_windowObj != null, $"ViewControllerSub Error! window obj can not be null!! parent = {windowObj.name}, path = {_path}");
|
|
//
|
|
UIWindowProperty propertyScript = _windowObj.GetComponentInChildren<UIWindowProperty>();
|
|
ViDebuger.AssertError(propertyScript != null, $"ViewControllerSub Error! window property can not be null!! parent = {windowObj.name}, path = {_path}");
|
|
//
|
|
_script = UnityAssisstant.CreateComponent<T>(_windowObj);
|
|
var parentCanvas = windowObj.GetComponent<Canvas>();
|
|
_script.Initialize(propertyScript, parentCanvas);
|
|
//
|
|
OnLoaded();
|
|
}
|
|
//
|
|
void _TrueOpen()
|
|
{
|
|
if (_script != null)
|
|
{
|
|
_script.Show();
|
|
//
|
|
if (ControlActive)
|
|
{
|
|
_windowObj.SetActive(true);
|
|
}
|
|
}
|
|
//
|
|
RegisterEventCallback();
|
|
OnOpen();
|
|
}
|
|
//
|
|
void _TrueClose()
|
|
{
|
|
UnregisterEventCallback();
|
|
OnClose();
|
|
//
|
|
if (_script != null)
|
|
{
|
|
_script.Hide();
|
|
//
|
|
if (ControlActive)
|
|
{
|
|
_windowObj.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
//
|
|
protected void AddLoadAtlas(string name)
|
|
{
|
|
if (!_atlasLoadList.Contains(name))
|
|
{
|
|
_atlasLoadList.Add(name);
|
|
}
|
|
}
|
|
public List<string> GetLoadAtlas()
|
|
{
|
|
return _atlasLoadList;
|
|
}
|
|
//
|
|
public virtual void PreLoad() { }
|
|
//
|
|
protected virtual void OnLoaded() { }
|
|
//
|
|
protected virtual void OnOpen() { }
|
|
//
|
|
protected virtual void RegisterEventCallback() { }
|
|
//
|
|
protected virtual void UnregisterEventCallback() { }
|
|
//
|
|
protected virtual void OnClose() { }
|
|
//
|
|
public virtual void Destroy()
|
|
{
|
|
_atlasLoadList.Clear();
|
|
_script = null;
|
|
_windowObj = null;
|
|
}
|
|
//
|
|
string _path;
|
|
IViewControllerInterface _parent;
|
|
//
|
|
T _script;
|
|
GameObject _windowObj;
|
|
List<string> _atlasLoadList = new List<string>();
|
|
}
|