411 lines
11 KiB
C#
411 lines
11 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Xml.Linq;
|
|||
|
|
using Unity.VisualScripting;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Events;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
using UnityEngine.Rendering.PostProcessing;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// UI<55><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class UIManager : MBSingletonManager<UIManager>
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// UI<55>ڵ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private Transform uiNode;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// UI<55><49><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
[HideInInspector]public Camera uICamera;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI<55><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private CanvasGroup allUICG;
|
|||
|
|
|
|||
|
|
public PostProcessVolume postProcessVolume;
|
|||
|
|
public PostProcessLayer processLayer;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// UI<55>б<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public List<UIBaseClass> uIList = new List<UIBaseClass>();
|
|||
|
|
|
|||
|
|
private void Awake()
|
|||
|
|
{
|
|||
|
|
Init();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ʼ<EFBFBD><CABC>
|
|||
|
|
/// </summary>
|
|||
|
|
private void Init()
|
|||
|
|
{
|
|||
|
|
uiNode = transform.Find("UINode");
|
|||
|
|
uICamera = transform.Find("UICamera").GetComponent<Camera>();
|
|||
|
|
allUICG=GetComponent<CanvasGroup>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>첽չʾUI
|
|||
|
|
/// </summary>
|
|||
|
|
public void AsynShowUI<T>(UnityAction<T> callback = null) where T : UIBaseClass
|
|||
|
|
{
|
|||
|
|
string uIName = typeof(T).Name;
|
|||
|
|
T uI;
|
|||
|
|
uI = GetUI<T>();
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.gameObject.SetActive(true);
|
|||
|
|
uI.ShowPanelAnimation();
|
|||
|
|
uI.OnShow();
|
|||
|
|
callback?.Invoke(uI);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
AsynGenerateUI<T>(uIName, (uIBaseClass) =>
|
|||
|
|
{
|
|||
|
|
uI = uIBaseClass;
|
|||
|
|
UICorrection(uI.transform, uIName);
|
|||
|
|
uI.ShowPanelAnimation();
|
|||
|
|
uI.OnShow();
|
|||
|
|
uIList.Add(uI);
|
|||
|
|
callback?.Invoke(uI);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Resources<65><73><EFBFBD><EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="T"></typeparam>
|
|||
|
|
/// <param name="callback"></param>
|
|||
|
|
public void ResourcesShowUI<T>(UnityAction<T> callback = null) where T : UIBaseClass
|
|||
|
|
{
|
|||
|
|
string uIName = typeof(T).Name;
|
|||
|
|
T uI;
|
|||
|
|
uI = GetUI<T>();
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.gameObject.SetActive(true);
|
|||
|
|
uI.ShowPanelAnimation();
|
|||
|
|
uI.OnShow();
|
|||
|
|
callback?.Invoke(uI);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
uI = Instantiate(Resources.Load<GameObject>(uIName)).GetComponent<T>();
|
|||
|
|
UICorrection(uI.transform, uIName);
|
|||
|
|
uI.ShowPanelAnimation();
|
|||
|
|
uI.OnShow();
|
|||
|
|
uIList.Add(uI);
|
|||
|
|
callback?.Invoke(uI);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>첽չʾUI
|
|||
|
|
/// </summary>
|
|||
|
|
public void AsynShowUI(string uIName,UnityAction<UIBaseClass> callback)
|
|||
|
|
{
|
|||
|
|
UIBaseClass uI = uIList.Find(s => s.name == uIName);
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.gameObject.SetActive(true);
|
|||
|
|
uI.ShowPanelAnimation();
|
|||
|
|
uI.OnShow();
|
|||
|
|
callback?.Invoke(uI);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
AsynGenerateUI<UIBaseClass>(uIName, (uIBaseClass) =>
|
|||
|
|
{
|
|||
|
|
uI = uIBaseClass;
|
|||
|
|
UICorrection(uI.transform, uIName);
|
|||
|
|
uI.ShowPanelAnimation();
|
|||
|
|
uI.OnShow();
|
|||
|
|
uIList.Add(uI);
|
|||
|
|
callback?.Invoke(uI);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ԥ<><D4A4><EFBFBD><EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
public void PreloadedUI<T>()where T : UIBaseClass
|
|||
|
|
{
|
|||
|
|
string uIName = typeof(T).Name;
|
|||
|
|
T uI;
|
|||
|
|
AsynGenerateUI<T>(uIName, (uiObj) =>
|
|||
|
|
{
|
|||
|
|
uI = uiObj;
|
|||
|
|
UICorrection(uI.transform, uIName);
|
|||
|
|
uI.gameObject.SetActive(false);
|
|||
|
|
uI.OnShow();
|
|||
|
|
uIList.Add(uI);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ر<EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
public void HideUI<T>() where T : UIBaseClass
|
|||
|
|
{
|
|||
|
|
UIBaseClass uI;
|
|||
|
|
uI = GetUI<T>();
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.OnHide();
|
|||
|
|
uI.HidePanel(() =>
|
|||
|
|
{
|
|||
|
|
uI.gameObject.SetActive(false);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogError("<22>ر<EFBFBD>_û<5F><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI:" + name);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ر<EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
public void HideUI(string uIName)
|
|||
|
|
{
|
|||
|
|
UIBaseClass uI = uIList.Find(s => s.name == uIName);
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.OnHide();
|
|||
|
|
uI.HidePanel(() =>
|
|||
|
|
{
|
|||
|
|
uI.gameObject.SetActive(false);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogError("<22>ر<EFBFBD>_û<5F><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI:" + name);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="retainUI"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI</param>
|
|||
|
|
public void HideAll(List<string> retainUI)
|
|||
|
|
{
|
|||
|
|
bool shouldRetain=false;
|
|||
|
|
for (int i = uIList.Count - 1; i >= 0; i--)
|
|||
|
|
{
|
|||
|
|
if (retainUI != null && retainUI.Contains(uIList[i].name))
|
|||
|
|
{
|
|||
|
|
shouldRetain = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!shouldRetain)
|
|||
|
|
{
|
|||
|
|
uIList[i].HidePanel(() =>
|
|||
|
|
{
|
|||
|
|
uIList[i].gameObject.SetActive(false);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ɾ<><C9BE>UI
|
|||
|
|
/// </summary>
|
|||
|
|
public void DeleteUI<T>() where T : UIBaseClass
|
|||
|
|
{
|
|||
|
|
UIBaseClass uI;
|
|||
|
|
uI = GetUI<T>();
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.OnDelete();
|
|||
|
|
if (uI.gameObject.activeInHierarchy)
|
|||
|
|
{
|
|||
|
|
uI.HidePanel(() =>
|
|||
|
|
{
|
|||
|
|
uIList.Remove(uI);
|
|||
|
|
Destroy(uI.gameObject);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
uIList.Remove(uI);
|
|||
|
|
Destroy(uI.gameObject);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ɾ<><C9BE>UI
|
|||
|
|
/// </summary>
|
|||
|
|
public void DeleteUI(string uIName)
|
|||
|
|
{
|
|||
|
|
UIBaseClass uI= uIList.Find(s => s.name == uIName);
|
|||
|
|
if (uI != null)
|
|||
|
|
{
|
|||
|
|
uI.OnDelete();
|
|||
|
|
if (uI.gameObject.activeInHierarchy)
|
|||
|
|
{
|
|||
|
|
uI.HidePanel(() =>
|
|||
|
|
{
|
|||
|
|
uIList.Remove(uI);
|
|||
|
|
Destroy(uI.gameObject);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
uIList.Remove(uI);
|
|||
|
|
Destroy(uI.gameObject);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogError("ɾ<><C9BE>_û<5F><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI:" + name);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="retainUI"><3E><><EFBFBD><EFBFBD>UI</param>
|
|||
|
|
public void DestroyAll(List<string> retainUI)
|
|||
|
|
{
|
|||
|
|
bool shouldRetain;
|
|||
|
|
for (int i = uIList.Count - 1; i >= 0; i--)
|
|||
|
|
{
|
|||
|
|
shouldRetain = retainUI.Contains(uIList[i].name);
|
|||
|
|
|
|||
|
|
if (!shouldRetain)
|
|||
|
|
{
|
|||
|
|
uIList[i].HidePanel(() =>
|
|||
|
|
{
|
|||
|
|
Destroy(uIList[i].gameObject);
|
|||
|
|
uIList.RemoveAt(i);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>õ<EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
public T GetUI<T>() where T : UIBaseClass
|
|||
|
|
{
|
|||
|
|
string uIName = typeof(T).Name;
|
|||
|
|
for (int i = 0; i < uIList.Count; i++)
|
|||
|
|
{
|
|||
|
|
if (uIName == uIList[i].name)
|
|||
|
|
{
|
|||
|
|
return uIList[i] as T;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>첽<EFBFBD><ECB2BD><EFBFBD><EFBFBD>UI
|
|||
|
|
/// </summary>
|
|||
|
|
private void AsynGenerateUI<T>(string name, UnityAction<T> callback)
|
|||
|
|
{
|
|||
|
|
YooAssetManager.Instance.LoadAssetAsync<GameObject>(PackagesName.GameData, name, (uiObj) =>
|
|||
|
|
{
|
|||
|
|
T uiBaseClass = Instantiate(uiObj).GetComponent<T>();
|
|||
|
|
callback(uiBaseClass);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///<2F><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="control"><3E>ؼ<EFBFBD></param>
|
|||
|
|
/// <param name="type"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="callBack"><3E>ص<EFBFBD></param>
|
|||
|
|
public void AddCustomEventListener(UIBehaviour control,EventTriggerType type,UnityAction<BaseEventData> callBack)
|
|||
|
|
{
|
|||
|
|
EventTrigger trigger = control.GetComponent<EventTrigger>();
|
|||
|
|
if(trigger==null)
|
|||
|
|
{
|
|||
|
|
trigger = control.gameObject.AddComponent<EventTrigger>();
|
|||
|
|
}
|
|||
|
|
EventTrigger.Entry entry = new EventTrigger.Entry();
|
|||
|
|
entry.eventID = type;
|
|||
|
|
entry.callback.AddListener(callBack);
|
|||
|
|
trigger.triggers.Add(entry);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƴ<EFBFBD><C6B3>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="control"><3E>ؼ<EFBFBD></param>
|
|||
|
|
/// <param name="type"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="callBack"><3E>ص<EFBFBD></param>
|
|||
|
|
public void RemoveCustomEventListener(UIBehaviour control, EventTriggerType type)
|
|||
|
|
{
|
|||
|
|
EventTrigger trigger = control.GetComponent<EventTrigger>();
|
|||
|
|
if (trigger != null)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
foreach (var entry in trigger.triggers)
|
|||
|
|
{
|
|||
|
|
if (entry.eventID == type)
|
|||
|
|
{
|
|||
|
|
// <20>Ƴ<EFBFBD><C6B3>ص<EFBFBD>
|
|||
|
|
entry.callback.RemoveAllListeners();
|
|||
|
|
// <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>Ŀ
|
|||
|
|
if (entry.callback.GetPersistentEventCount() == 0)
|
|||
|
|
{
|
|||
|
|
trigger.triggers.Remove(entry);
|
|||
|
|
break; // һ<><D2BB><EFBFBD>Ƴ<EFBFBD><C6B3>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// UI<55><49><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private void UICorrection(Transform uI, string uIName)
|
|||
|
|
{
|
|||
|
|
uI.name = uIName;
|
|||
|
|
uI.transform.SetParent(uiNode);
|
|||
|
|
uI.transform.localPosition = Vector3.zero;
|
|||
|
|
uI.transform.localScale = Vector3.one;
|
|||
|
|
(uI.transform as RectTransform).offsetMax = Vector3.zero;
|
|||
|
|
(uI.transform as RectTransform).offsetMin = Vector3.zero;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ȫ<><C8AB>ʧЧ<CAA7><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void AllLapseInitiate(bool isAllLapse)
|
|||
|
|
{
|
|||
|
|
allUICG.alpha = isAllLapse==true?1:0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>Voluem
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="isShow"></param>
|
|||
|
|
public void SetPostProcessVolume(bool isShow)
|
|||
|
|
{
|
|||
|
|
postProcessVolume.isGlobal = isShow;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void DesProcess()
|
|||
|
|
{
|
|||
|
|
Destroy(postProcessVolume);
|
|||
|
|
Destroy(processLayer);
|
|||
|
|
}
|
|||
|
|
}
|