2023-08-22 19:08:45 +08:00
|
|
|
|
using System;
|
2024-04-28 14:45:31 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-11-21 13:31:06 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2024-08-12 19:31:50 +08:00
|
|
|
|
using DG.Tweening;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Framework;
|
|
|
|
|
|
using PhxhSDK;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
using Object = System.Object;
|
2024-05-10 19:18:40 +08:00
|
|
|
|
using UniTask = Cysharp.Threading.Tasks.UniTask;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
public abstract class UIWindow
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-01-26 16:06:42 +08:00
|
|
|
|
public GameObject gameObject;
|
|
|
|
|
|
public Transform transform;
|
|
|
|
|
|
public RectTransform rectTransform;
|
|
|
|
|
|
public string name;
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-21 13:31:06 +08:00
|
|
|
|
private const string DEFAULT_SHOW_ANIM = "show";
|
|
|
|
|
|
private const string DEFAULT_HIDE_ANIM = "hide";
|
2023-08-22 19:08:45 +08:00
|
|
|
|
private string mWindowName;
|
2023-12-05 19:27:56 +08:00
|
|
|
|
private ScreenOrientation _lastOrientation;
|
|
|
|
|
|
private Vector2 _offsets; //x,y代表左右的偏移量
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
2024-08-28 15:08:46 +08:00
|
|
|
|
public delegate void OnBgClose();
|
|
|
|
|
|
|
|
|
|
|
|
private OnBgClose _onBgCloseFunc;
|
|
|
|
|
|
|
2024-05-08 12:44:22 +08:00
|
|
|
|
protected Dictionary<string, int> AsyncLoadedAssetList = new ();
|
2024-04-28 14:45:31 +08:00
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
private bool _isNeedScreenAdaption;
|
2024-08-08 12:19:32 +08:00
|
|
|
|
private bool _bDoNotSetMainCamera = false; //不设置主相机
|
|
|
|
|
|
|
2024-10-21 19:55:05 +08:00
|
|
|
|
public bool IsNotSetMainCamera
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _bDoNotSetMainCamera; }
|
|
|
|
|
|
set { _bDoNotSetMainCamera = value; }
|
|
|
|
|
|
}
|
2024-01-26 16:06:42 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
// 是否播放默认的打开对话框的声音
|
|
|
|
|
|
public bool isPlayDefaultOpenAudio = true;
|
|
|
|
|
|
// 是否播放默认的关闭对话框的声音
|
|
|
|
|
|
public bool isPlayDefaultCloseAudio = true;
|
|
|
|
|
|
|
2024-08-12 19:31:50 +08:00
|
|
|
|
private bool _isPlayingOpenAnim;
|
|
|
|
|
|
|
2024-10-21 19:55:05 +08:00
|
|
|
|
protected Sequence _openAnimSeq;
|
2024-08-12 19:31:50 +08:00
|
|
|
|
public bool IsShowOpenAnim;
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public string WindowName
|
|
|
|
|
|
{
|
|
|
|
|
|
set { mWindowName = value; }
|
|
|
|
|
|
get { return mWindowName; }
|
|
|
|
|
|
}
|
2023-11-21 13:31:06 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
[HideInInspector]
|
|
|
|
|
|
public UIWindowLayer uiWindowLayer;
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
[HideInInspector]
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
2024-06-03 17:06:54 +08:00
|
|
|
|
protected bool isCreated = false;
|
2024-04-29 15:39:46 +08:00
|
|
|
|
|
2024-06-03 17:06:54 +08:00
|
|
|
|
protected bool _isShow = false;
|
|
|
|
|
|
protected bool _isHide = false;
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
protected void RegisterScreenAdaption()
|
2023-12-05 19:27:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
_lastOrientation = Screen.orientation;
|
|
|
|
|
|
InitScreenUIOffset();
|
|
|
|
|
|
UpdateScreenAdaption();
|
2024-01-26 16:06:42 +08:00
|
|
|
|
_isNeedScreenAdaption = true;
|
2023-12-05 19:27:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-08 16:16:50 +08:00
|
|
|
|
public async UniTask<T> LoadAssetAsync<T>(string path) where T : UnityEngine.Object
|
2024-04-28 14:45:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
var asset = await AssetManager.Instance.LoadAssetAsync<T>(path);
|
2024-05-08 12:44:22 +08:00
|
|
|
|
if (!AsyncLoadedAssetList.ContainsKey(path))
|
2024-04-28 14:45:31 +08:00
|
|
|
|
{
|
2024-05-08 12:44:22 +08:00
|
|
|
|
AsyncLoadedAssetList.Add(path, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
AsyncLoadedAssetList[path]++ ;
|
2024-04-28 14:45:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
return asset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-08 16:16:50 +08:00
|
|
|
|
public T LoadAsset<T>(string path) where T : UnityEngine.Object
|
2024-04-28 14:45:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
var asset = AssetManager.Instance.LoadAsset<T>(path);
|
|
|
|
|
|
return asset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-14 17:32:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 异步预加载
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
|
public async UniTask PostPreload<T>(string path) where T : UnityEngine.Object
|
|
|
|
|
|
{
|
|
|
|
|
|
await AssetManager.Instance.PostPreload<T>(path);
|
|
|
|
|
|
if (!AsyncLoadedAssetList.ContainsKey(path))
|
|
|
|
|
|
AsyncLoadedAssetList.Add(path, 1);
|
|
|
|
|
|
else
|
|
|
|
|
|
AsyncLoadedAssetList[path]++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T GetPreLoadResult<T>(string path) where T : UnityEngine.Object
|
|
|
|
|
|
{
|
|
|
|
|
|
return AssetManager.Instance.GetPreLoadResult<T>(path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-28 14:45:31 +08:00
|
|
|
|
protected void UnLoad()
|
|
|
|
|
|
{
|
2024-05-08 12:44:22 +08:00
|
|
|
|
foreach (var asset in AsyncLoadedAssetList)
|
2024-04-28 14:45:31 +08:00
|
|
|
|
{
|
2024-05-08 12:44:22 +08:00
|
|
|
|
var path = asset.Key;
|
|
|
|
|
|
var count = asset.Value;
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
AssetManager.Instance.Unload(path);
|
|
|
|
|
|
}
|
2024-04-28 14:45:31 +08:00
|
|
|
|
}
|
2024-05-08 12:44:22 +08:00
|
|
|
|
|
2024-04-28 15:47:12 +08:00
|
|
|
|
AsyncLoadedAssetList.Clear();
|
2024-04-28 14:45:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
protected virtual void OnUpdate()
|
2023-12-05 19:27:56 +08:00
|
|
|
|
{
|
2024-01-26 16:06:42 +08:00
|
|
|
|
if (_isNeedScreenAdaption && _lastOrientation != Screen.orientation)
|
2023-12-05 19:27:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
// Add your orientation-specific actions here
|
|
|
|
|
|
// Update the last orientation for the next frame
|
|
|
|
|
|
_lastOrientation = Screen.orientation;
|
|
|
|
|
|
UpdateScreenAdaption();
|
|
|
|
|
|
//左右分别找到指定节点移动,当前的方案
|
|
|
|
|
|
//刘海屏适配
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
public void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
OnUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region MonoBehaviour Methods Override
|
|
|
|
|
|
|
|
|
|
|
|
protected void Destroy(GameObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object.Destroy(obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void DestroyImmediate(GameObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void Destroy(Component cmp)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object.Destroy(cmp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void DestroyImmediate(Component cmp)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(cmp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected GameObject Instantiate(GameObject prefab)
|
|
|
|
|
|
{
|
|
|
|
|
|
return UnityEngine.Object.Instantiate(prefab, transform);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected GameObject Instantiate(GameObject prefab, Transform trans)
|
|
|
|
|
|
{
|
|
|
|
|
|
return UnityEngine.Object.Instantiate(prefab, trans);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-01-24 15:42:01 +08:00
|
|
|
|
#region #ScreenAdaption
|
2023-12-05 19:27:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 屏幕适配,目前方案是左右固定名称的节点下的各个物体需要适配,其他的不管
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected void UpdateScreenAdaption()
|
|
|
|
|
|
{
|
2023-12-29 18:22:22 +08:00
|
|
|
|
var goLeft = transform.Find("UI_LiuHaiLeft")?.gameObject;
|
|
|
|
|
|
var goRight = transform.Find("UI_LiuHaiRight")?.gameObject;
|
2023-12-05 19:27:56 +08:00
|
|
|
|
if (goLeft)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rectTrans = goLeft.GetComponent<RectTransform>();
|
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
|
rectTrans.anchoredPosition = new Vector2(_offsets.x, originPos.y);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (goRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rectTrans = goRight.GetComponent<RectTransform>();
|
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
|
rectTrans.anchoredPosition = new Vector2(_offsets.y, originPos.y);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void SetScreenOffsets(Vector2 offset)
|
|
|
|
|
|
{
|
|
|
|
|
|
_offsets = offset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void InitScreenUIOffset()
|
|
|
|
|
|
{
|
|
|
|
|
|
var offset = DeviceHelper.GetWidthOffset();
|
2023-12-29 18:22:22 +08:00
|
|
|
|
var goLeft = transform.Find("UI_LiuHaiLeft")?.gameObject;
|
2023-12-05 19:27:56 +08:00
|
|
|
|
if (goLeft)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rectTrans = goLeft.GetComponent<RectTransform>();
|
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
|
SetScreenOffsets(new Vector2(originPos.x + offset.x, 0));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 18:22:22 +08:00
|
|
|
|
GameObject goRight = transform.Find("UI_LiuHaiRight")?.gameObject;
|
2023-12-05 19:27:56 +08:00
|
|
|
|
if (goRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rectTrans = goRight.GetComponent<RectTransform>();
|
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
|
SetScreenOffsets(new Vector2(_offsets.x, originPos.x - offset.y));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2023-12-05 19:27:56 +08:00
|
|
|
|
|
2024-05-09 14:37:29 +08:00
|
|
|
|
#region Window Life
|
|
|
|
|
|
|
2024-08-28 15:08:46 +08:00
|
|
|
|
private void _TryBindBgClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
var trans = transform.Find("BgClose");
|
|
|
|
|
|
if (trans)
|
|
|
|
|
|
{
|
|
|
|
|
|
var btn = trans.GetComponent<Button>();
|
|
|
|
|
|
if (btn)
|
|
|
|
|
|
{
|
|
|
|
|
|
BindButton(btn, () =>
|
|
|
|
|
|
{
|
2024-10-08 16:59:48 +08:00
|
|
|
|
var clickAudio = btn.GetComponent<ClickAudio>();
|
|
|
|
|
|
if (clickAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
AudioManager.Instance.PlayAudio(clickAudio.AudioKey);
|
|
|
|
|
|
}
|
2024-08-29 14:31:45 +08:00
|
|
|
|
if (_onBgCloseFunc == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseWindow();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-08-28 15:08:46 +08:00
|
|
|
|
_onBgCloseFunc?.Invoke();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-08 12:19:32 +08:00
|
|
|
|
public void CreateWindow(object data = null, bool isNotSetCamera = false)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-08-08 12:19:32 +08:00
|
|
|
|
_bDoNotSetMainCamera = isNotSetCamera;
|
2024-02-22 19:47:07 +08:00
|
|
|
|
PreLoad(data);
|
2024-01-24 17:11:15 +08:00
|
|
|
|
|
2024-05-10 19:14:47 +08:00
|
|
|
|
if (!isCreated)
|
2024-01-24 17:11:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
OnInit();
|
2024-09-02 15:26:15 +08:00
|
|
|
|
RegisterScreenAdaption();
|
2024-08-28 15:08:46 +08:00
|
|
|
|
_TryBindBgClose();
|
2024-05-10 19:14:47 +08:00
|
|
|
|
isCreated = true;
|
2024-01-24 17:11:15 +08:00
|
|
|
|
}
|
2024-05-16 12:40:15 +08:00
|
|
|
|
|
|
|
|
|
|
_isShow = false;
|
|
|
|
|
|
_isHide = false;
|
2024-08-12 19:31:50 +08:00
|
|
|
|
|
|
|
|
|
|
IsShowOpenAnim = UIManager.Instance.GetIsAutoPlayAnim(WindowName);
|
2023-11-29 19:23:27 +08:00
|
|
|
|
Show(data);
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (isPlayDefaultOpenAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
//AudioManager3.Instance.PlaySound("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-21 19:55:05 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
2024-08-12 19:31:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关闭窗口
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="closeType"></param>
|
|
|
|
|
|
/// <param name="forceShowAnim"></param>强制设置动画,0不管,1强制开,-1强制不开
|
|
|
|
|
|
/// <param name="isOpenMainCamera"></param>
|
|
|
|
|
|
public async void CloseWindow(UIWindowCloseType closeType = UIWindowCloseType.HideAndDestroy, int forceShowAnim = 0,
|
|
|
|
|
|
bool isOpenMainCamera = true)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-08-08 12:19:32 +08:00
|
|
|
|
// if (UIManager.Instance.CheckWindowIsFullScreen(this))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// CameraManager.Instance.SetMainCameraActive(isOpenMainCamera);
|
|
|
|
|
|
// }
|
|
|
|
|
|
if (UIManager.Instance.CheckWindowIsFullScreen(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_bDoNotSetMainCamera)
|
|
|
|
|
|
{
|
|
|
|
|
|
CameraManager.Instance.SetMainCameraActive(isOpenMainCamera);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-10 19:14:47 +08:00
|
|
|
|
if (isPlayDefaultCloseAudio && isCreated)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
//AudioManager3.Instance.PlaySound("");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-21 13:31:06 +08:00
|
|
|
|
if (closeType == UIWindowCloseType.HideAndDestroy)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-01-24 15:42:01 +08:00
|
|
|
|
var last = UIManager.Instance.GetLast();
|
|
|
|
|
|
if (last == this)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.PopWindow();
|
|
|
|
|
|
}
|
2024-08-12 19:31:50 +08:00
|
|
|
|
|
|
|
|
|
|
bool isShowCloseAnim = IsShowOpenAnim;
|
|
|
|
|
|
if (forceShowAnim > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
isShowCloseAnim = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (forceShowAnim < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
isShowCloseAnim = false;
|
|
|
|
|
|
}
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
|
|
|
|
|
_OnClose();
|
2024-08-12 19:31:50 +08:00
|
|
|
|
if (isShowCloseAnim)
|
|
|
|
|
|
{
|
2024-08-30 15:57:33 +08:00
|
|
|
|
UIManager.Instance.OnClick(true);
|
2024-08-12 19:31:50 +08:00
|
|
|
|
await AnimHide(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyWindow();
|
|
|
|
|
|
UIManager.Instance.RemoveWindow(mWindowName);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyWindow();
|
|
|
|
|
|
UIManager.Instance.RemoveWindow(mWindowName);
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2024-01-15 15:33:10 +08:00
|
|
|
|
else if(closeType == UIWindowCloseType.OnlyHide)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
}
|
2024-01-24 15:42:01 +08:00
|
|
|
|
else if(closeType == UIWindowCloseType.HideAndPush)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
Hide();
|
2024-01-24 15:42:01 +08:00
|
|
|
|
//UIManager.Instance.PushWindow(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//强制清除所有界面时使用
|
2024-01-26 16:06:42 +08:00
|
|
|
|
DestroyWindow();
|
2024-01-24 15:42:01 +08:00
|
|
|
|
UIManager.Instance.RemoveWindow(mWindowName);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-27 16:47:42 +08:00
|
|
|
|
|
2024-03-27 17:07:43 +08:00
|
|
|
|
public virtual async UniTask<bool> OnBack(object data = null)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-03-27 16:51:46 +08:00
|
|
|
|
if (UIManager.Instance.GetLast() != null)
|
2023-12-14 14:47:14 +08:00
|
|
|
|
{
|
2024-03-27 16:51:46 +08:00
|
|
|
|
OnDirectBack();
|
2024-03-27 17:07:43 +08:00
|
|
|
|
return true;
|
2023-12-14 14:47:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-27 16:51:46 +08:00
|
|
|
|
await OnBackApp();
|
2024-05-08 14:26:30 +08:00
|
|
|
|
|
2024-03-27 17:07:43 +08:00
|
|
|
|
return true;
|
2024-03-27 16:51:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void OnDirectBack()
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected async UniTask OnBackApp()
|
|
|
|
|
|
{
|
2024-05-16 12:40:15 +08:00
|
|
|
|
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UIBackReturn);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public void ReloadWindow(object data)
|
|
|
|
|
|
{
|
2024-05-10 19:14:47 +08:00
|
|
|
|
if (isCreated)
|
2024-01-15 16:19:09 +08:00
|
|
|
|
{
|
|
|
|
|
|
OnReloadWindow(data);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-29 19:23:27 +08:00
|
|
|
|
Show(data);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
OnReloadWindow(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 19:14:47 +08:00
|
|
|
|
public bool IsCreated()
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-05-10 19:14:47 +08:00
|
|
|
|
return isCreated;
|
2023-11-29 19:23:27 +08:00
|
|
|
|
}
|
2024-05-16 12:40:15 +08:00
|
|
|
|
|
|
|
|
|
|
public bool IsShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _isShow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsHide()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _isHide;
|
|
|
|
|
|
}
|
2023-11-29 19:23:27 +08:00
|
|
|
|
|
2024-08-12 19:31:50 +08:00
|
|
|
|
private async void Show(object data)
|
2023-11-29 19:23:27 +08:00
|
|
|
|
{
|
2024-05-10 19:14:47 +08:00
|
|
|
|
// var toTrue = (isCreated == false);
|
|
|
|
|
|
// isCreated = true;
|
2024-01-25 17:52:04 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (gameObject == null)
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
DebugUtil.Log("UI已被销毁:{0}", WindowName);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-08-12 19:31:50 +08:00
|
|
|
|
if (IsShowOpenAnim)
|
|
|
|
|
|
{
|
|
|
|
|
|
var canvasGroup = gameObject.GetComponent<CanvasGroup>();
|
|
|
|
|
|
if (!canvasGroup)
|
|
|
|
|
|
{
|
|
|
|
|
|
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
canvasGroup.alpha = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
gameObject.SetActive(true);
|
2024-08-12 19:31:50 +08:00
|
|
|
|
if (IsShowOpenAnim)
|
|
|
|
|
|
{
|
|
|
|
|
|
await AnimShow();
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-11-29 19:23:27 +08:00
|
|
|
|
|
2024-01-25 17:52:04 +08:00
|
|
|
|
// if (toTrue)
|
|
|
|
|
|
// {
|
2024-04-28 14:45:31 +08:00
|
|
|
|
if (UIManager.Instance.WindowInfos.TryGetValue(WindowName, out var windowInfo))
|
|
|
|
|
|
{
|
2024-08-08 12:19:32 +08:00
|
|
|
|
// if (windowInfo.UIOpenType == UIOpenType.FullScreen)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (CameraManager.Instance.CheckMainCameraIsActive())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// CameraManager.Instance.SetMainCameraActive(false);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
if (CameraManager.Instance.CheckMainCameraIsActive())
|
2024-04-28 14:45:31 +08:00
|
|
|
|
{
|
2024-08-08 12:19:32 +08:00
|
|
|
|
if (windowInfo.UIOpenType == UIOpenType.FullScreen)
|
2024-04-28 14:45:31 +08:00
|
|
|
|
{
|
2024-08-08 12:19:32 +08:00
|
|
|
|
//特殊处理主界面
|
|
|
|
|
|
if (!_bDoNotSetMainCamera && WindowName != UINameConst.UI_MainPanel)
|
|
|
|
|
|
{
|
|
|
|
|
|
CameraManager.Instance.SetMainCameraActive(false);
|
|
|
|
|
|
}
|
2024-04-28 14:45:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnShowWindow(data);
|
2024-05-16 12:40:15 +08:00
|
|
|
|
_isShow = true;
|
|
|
|
|
|
_isHide = false;
|
2024-01-25 17:52:04 +08:00
|
|
|
|
//}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 15:03:59 +08:00
|
|
|
|
private void ShowAgain()
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-02-26 18:19:36 +08:00
|
|
|
|
if (gameObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
|
|
}
|
2024-01-24 16:32:38 +08:00
|
|
|
|
//OnShow();
|
2023-12-29 15:03:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Hide(bool isOnlyHide = false)
|
|
|
|
|
|
{
|
2024-04-28 18:54:12 +08:00
|
|
|
|
gameObject?.SetActive(false);
|
2024-05-10 19:14:47 +08:00
|
|
|
|
//isOpen = false;
|
2024-01-25 17:52:04 +08:00
|
|
|
|
if (!isOnlyHide)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnHideWindow();
|
2024-05-16 12:40:15 +08:00
|
|
|
|
_isHide = true;
|
|
|
|
|
|
_isShow = false;
|
2024-04-28 14:45:31 +08:00
|
|
|
|
if (UIManager.Instance.WindowInfos.TryGetValue(WindowName, out var windowInfo))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (windowInfo.UIOpenType == UIOpenType.FullScreen)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!CameraManager.Instance.CheckMainCameraIsActive())
|
|
|
|
|
|
{
|
|
|
|
|
|
CameraManager.Instance.SetMainCameraActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-25 17:52:04 +08:00
|
|
|
|
}
|
2024-01-15 15:33:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-24 15:42:01 +08:00
|
|
|
|
private void _OnClose()
|
2024-01-15 15:33:10 +08:00
|
|
|
|
{
|
2024-01-24 15:42:01 +08:00
|
|
|
|
if (UIManager.Instance.UiWindowStack.Count <= 0)
|
2023-11-29 19:23:27 +08:00
|
|
|
|
{
|
2024-01-24 15:42:01 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (UIManager.Instance.CheckWindowIsFullScreen(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
var window = UIManager.Instance.GetLastFullScreen();
|
|
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
if (window != null && window != this)
|
2024-01-24 15:42:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (UIManager.Instance.CheckIsWindowInStack(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.ForceRemoveWindow(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = UIManager.Instance.UiWindowStack.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
var latestWindow = UIManager.Instance.UiWindowStack[i];
|
2024-06-19 13:42:19 +08:00
|
|
|
|
latestWindow.ShowWindow();
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
|
|
|
|
|
if (UIManager.Instance.CheckWindowIsFullScreen(latestWindow))
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.ForceRemoveWindow(this);
|
2023-11-29 19:23:27 +08:00
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
private void DestroyWindow()
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-05-10 19:14:47 +08:00
|
|
|
|
OnHideWindow();
|
2024-04-29 15:39:46 +08:00
|
|
|
|
|
2024-05-10 19:14:47 +08:00
|
|
|
|
if (isCreated)
|
2024-04-29 15:39:46 +08:00
|
|
|
|
{
|
2024-01-24 15:42:01 +08:00
|
|
|
|
OnRelease();
|
2024-05-10 19:14:47 +08:00
|
|
|
|
isCreated = false;
|
2023-11-29 19:23:27 +08:00
|
|
|
|
}
|
2024-04-29 15:39:46 +08:00
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
UIManager.Instance.UIWindowObjDic.Remove(gameObject);
|
2024-01-26 16:06:42 +08:00
|
|
|
|
UnityEngine.Object.Destroy(gameObject);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
AssetManager.Instance.Unload(string.Format(UIManager.UI_PREFAB_PATH, mWindowName));
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2024-05-09 14:37:29 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
2024-05-09 14:37:29 +08:00
|
|
|
|
#region Framework
|
|
|
|
|
|
|
2024-01-24 15:42:01 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///预加载,传入参数,不能添加监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void PreLoad(object data = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-08 18:41:26 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打开界面时调用
|
|
|
|
|
|
/// </summary>
|
2023-10-19 15:00:19 +08:00
|
|
|
|
/// <param name="data"></param>
|
2024-05-28 13:40:44 +08:00
|
|
|
|
protected virtual void OnShowWindow(object data)
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.UIOpen, WindowName);
|
|
|
|
|
|
}
|
2024-01-23 12:25:47 +08:00
|
|
|
|
//protected virtual void OnOpenWindow() { }
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关闭界面时调用
|
|
|
|
|
|
/// </summary>
|
2024-05-28 13:40:44 +08:00
|
|
|
|
protected virtual void OnHideWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.UIClose, WindowName);
|
|
|
|
|
|
}
|
2024-01-15 15:12:51 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 重新加载界面时调用
|
|
|
|
|
|
/// </summary>
|
2023-10-19 15:00:19 +08:00
|
|
|
|
protected virtual void OnReloadWindow(object data) { }
|
2023-08-22 19:08:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 私有Awake方法,会在基类Awake执行后调用
|
|
|
|
|
|
/// </summary>
|
2024-01-23 12:25:47 +08:00
|
|
|
|
public abstract void OnInit();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
2024-01-24 15:42:01 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对应OnInit,在销毁掉界面时调用
|
|
|
|
|
|
/// </summary>
|
2024-04-28 14:45:31 +08:00
|
|
|
|
public virtual void OnRelease()
|
|
|
|
|
|
{
|
|
|
|
|
|
UnLoad();
|
2024-08-12 19:31:50 +08:00
|
|
|
|
_openAnimSeq?.Kill();
|
2024-04-28 14:45:31 +08:00
|
|
|
|
}
|
2024-01-24 15:42:01 +08:00
|
|
|
|
|
|
|
|
|
|
#region #Bind Component
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public GameObject BindButton(string target, Action action, bool playAudio = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject obj = transform.Find(target)?.gameObject;
|
|
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Button button = obj.GetComponent<Button>();
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener
|
|
|
|
|
|
(
|
|
|
|
|
|
delegate ()
|
|
|
|
|
|
{
|
2024-08-29 13:11:40 +08:00
|
|
|
|
if (UIManager.IsClickDisabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
UIManager.Instance.OnClick();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (playAudio)
|
|
|
|
|
|
{
|
2024-10-08 16:59:48 +08:00
|
|
|
|
var clickAudio = button.GetComponent<ClickAudio>();
|
|
|
|
|
|
if (clickAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
AudioManager.Instance.PlayAudio(clickAudio.AudioKey);
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
DebugUtil.LogError("未找到 {0}/{1}", gameObject.name, target);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//增加一个可绑定对应变量的点击事件
|
|
|
|
|
|
//传入GameObject
|
|
|
|
|
|
public GameObject BindButton(GameObject obj, Action action, bool playAudio = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Button button = obj.GetComponent<Button>();
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener
|
|
|
|
|
|
(
|
|
|
|
|
|
delegate ()
|
|
|
|
|
|
{
|
2024-08-28 19:07:32 +08:00
|
|
|
|
if (UIManager.IsClickDisabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
UIManager.Instance.OnClick();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (playAudio)
|
|
|
|
|
|
{
|
2024-10-08 16:59:48 +08:00
|
|
|
|
var clickAudio = button.GetComponent<ClickAudio>();
|
|
|
|
|
|
if (clickAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
AudioManager.Instance.PlayAudio(clickAudio.AudioKey);
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
DebugUtil.LogError("未找到 {0}/{1}", gameObject.name, obj.name);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//传入参数
|
|
|
|
|
|
public GameObject BindButton<T>(GameObject obj, Action<T> action, T parameter, bool playAudio = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Button button = obj.GetComponent<Button>();
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener
|
|
|
|
|
|
(
|
|
|
|
|
|
delegate ()
|
|
|
|
|
|
{
|
2024-08-28 19:07:32 +08:00
|
|
|
|
if (UIManager.IsClickDisabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
UIManager.Instance.OnClick();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (playAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
|
|
|
|
|
|
}
|
|
|
|
|
|
action?.Invoke(parameter);
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
DebugUtil.LogError("未找到 {0}/{1}", gameObject.name, obj.name);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//直接绑按钮
|
|
|
|
|
|
public GameObject BindButton(Button button, Action action, bool playAudio = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Button button = button.GetComponent<Button>();
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener
|
|
|
|
|
|
(
|
|
|
|
|
|
delegate ()
|
|
|
|
|
|
{
|
2024-08-28 19:07:32 +08:00
|
|
|
|
if (UIManager.IsClickDisabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
UIManager.Instance.OnClick();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (playAudio)
|
|
|
|
|
|
{
|
2024-10-08 16:59:48 +08:00
|
|
|
|
var clickAudio = button.GetComponent<ClickAudio>();
|
|
|
|
|
|
if (clickAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
AudioManager.Instance.PlayAudio(clickAudio.AudioKey);
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
|
|
|
|
|
|
}
|
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("传入按钮为空,请检查按钮绑定参数!!!");
|
|
|
|
|
|
//DebugUtil.LogError($"未找到 {gameObject.name}/{button.name}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return button.gameObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//可传入参数
|
|
|
|
|
|
public GameObject BindButton<T>(Button button, Action<T> action, T parameter, bool playAudio = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Button button = obj.GetComponent<Button>();
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener
|
|
|
|
|
|
(
|
|
|
|
|
|
delegate ()
|
|
|
|
|
|
{
|
2024-08-28 19:07:32 +08:00
|
|
|
|
if (UIManager.IsClickDisabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
UIManager.Instance.OnClick();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (playAudio)
|
|
|
|
|
|
{
|
|
|
|
|
|
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (parameter == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("=== 传入参数为空! ===");
|
|
|
|
|
|
}
|
|
|
|
|
|
action?.Invoke(parameter);
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("传入按钮为空,请检查按钮绑定参数!!!");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return button.gameObject;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
public void ClearBind(Button button)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.RemoveAllListeners();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ClearBind(GameObject go)
|
|
|
|
|
|
{
|
|
|
|
|
|
var button = go.GetComponent<Button>();
|
|
|
|
|
|
if (button != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.RemoveAllListeners();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
public GameObject FindObj(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject obj = transform.Find(path)?.gameObject;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (obj == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("{0}未找到 {1}/{2}", mWindowName, gameObject.name, path);
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-26 16:06:42 +08:00
|
|
|
|
public T GetComponent<T>(string path = "") where T : Behaviour
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
var component = transform.Find(path)?.GetComponent<T>();
|
|
|
|
|
|
if (component == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("{0}未找到组件{1}: {2}", mWindowName, typeof(T).Name, path);
|
|
|
|
|
|
}
|
|
|
|
|
|
return component;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2024-01-24 15:42:01 +08:00
|
|
|
|
#endregion
|
2023-12-29 15:03:59 +08:00
|
|
|
|
public void HideWindow(bool isOnlyHide = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hide(isOnlyHide);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-16 12:40:15 +08:00
|
|
|
|
public void ShowWindowActive()
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-12-29 15:03:59 +08:00
|
|
|
|
ShowAgain();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-16 12:40:15 +08:00
|
|
|
|
public void ShowWindow(object data = null)
|
2024-04-07 12:53:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
Show(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-28 15:08:46 +08:00
|
|
|
|
protected void AddBgClose(OnBgClose onBgCloseFunc)
|
|
|
|
|
|
{
|
|
|
|
|
|
_onBgCloseFunc += onBgCloseFunc;
|
|
|
|
|
|
}
|
2024-10-08 16:59:48 +08:00
|
|
|
|
|
|
|
|
|
|
protected virtual void OnCloseClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-09 14:37:29 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-24 15:42:01 +08:00
|
|
|
|
#region #Anim
|
2024-08-20 13:58:29 +08:00
|
|
|
|
public virtual async UniTask PlayAnimation(bool isShow, Action callBack = null)
|
2023-11-21 13:31:06 +08:00
|
|
|
|
{
|
2024-08-12 19:31:50 +08:00
|
|
|
|
var canvasGroup = gameObject.GetComponent<CanvasGroup>();
|
|
|
|
|
|
if (!canvasGroup)
|
|
|
|
|
|
{
|
|
|
|
|
|
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var time = 0.3f;
|
|
|
|
|
|
_isPlayingOpenAnim = true;
|
|
|
|
|
|
_openAnimSeq = DOTween.Sequence();
|
|
|
|
|
|
|
|
|
|
|
|
if (isShow)
|
|
|
|
|
|
{
|
|
|
|
|
|
canvasGroup.alpha = 0;
|
|
|
|
|
|
var tw0 = canvasGroup.DOFade(1, time);
|
|
|
|
|
|
_openAnimSeq.Append(tw0);
|
|
|
|
|
|
_openAnimSeq.AppendCallback(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
_isPlayingOpenAnim = false;
|
|
|
|
|
|
callBack?.Invoke();
|
|
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
canvasGroup.alpha = 1;
|
|
|
|
|
|
var tw1 = canvasGroup.DOFade(0, time);
|
|
|
|
|
|
_openAnimSeq.Append(tw1);
|
|
|
|
|
|
_openAnimSeq.AppendCallback(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
_isPlayingOpenAnim = false;
|
|
|
|
|
|
callBack?.Invoke();
|
|
|
|
|
|
});
|
2023-11-21 13:31:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-20 13:58:29 +08:00
|
|
|
|
public virtual async UniTask AnimShow(Action callBack = null)
|
2023-11-21 15:12:51 +08:00
|
|
|
|
{
|
2024-08-12 19:31:50 +08:00
|
|
|
|
await PlayAnimation(true, callBack);
|
2023-11-21 13:31:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-20 13:58:29 +08:00
|
|
|
|
public virtual async UniTask AnimHide(Action callBack = null)
|
2023-11-21 13:31:06 +08:00
|
|
|
|
{
|
2024-08-12 19:31:50 +08:00
|
|
|
|
await PlayAnimation(false, callBack);
|
2023-11-21 13:31:06 +08:00
|
|
|
|
}
|
2024-01-24 15:42:01 +08:00
|
|
|
|
#endregion
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|