| | |
| | | // 组件引用 |
| | | protected Canvas canvas; |
| | | protected CanvasGroup canvasGroup; |
| | | protected RectTransform _rectTransform; |
| | | protected RectTransform _rectTransform; //界面默认添加根节点用于表现界面开启关闭动画 |
| | | |
| | | // 动画相关 |
| | | protected Vector3 originalPosition; |
| | |
| | | |
| | | private void CreateRootNode() |
| | | { |
| | | if (openAnimationType == UIAnimationType.None && closeAnimationType == UIAnimationType.None) |
| | | return; |
| | | |
| | | List<Transform> children = new List<Transform>(); |
| | | foreach (Transform child in transform) |
| | | { |
| | |
| | | rootNode = new GameObject("WindowRoot"); |
| | | rootNode.transform.SetParent(transform, false); |
| | | rootNode.layer = LayerMask.NameToLayer("UI"); |
| | | _rectTransform = rootNode.AddMissingComponent<RectTransform>(); |
| | | _rectTransform.anchorMin = new Vector2(0.5f, 0.5f); |
| | | _rectTransform.anchorMax = new Vector2(0.5f, 0.5f); |
| | | _rectTransform = rootNode.AddMissingComponent<RectTransform>();
|
| | |
|
| | | //设置成拉伸效果,和父容器保持同样大小自动适配 |
| | | _rectTransform.anchorMin = Vector2.zero; |
| | | _rectTransform.anchorMax = Vector2.one; |
| | | _rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| | | _rectTransform.sizeDelta = new Vector2(750, 1334); // 默认大小,可以根据需要调整 |
| | | _rectTransform.anchoredPosition = Vector2.zero; |
| | | _rectTransform.localScale = Vector3.one; |
| | | _rectTransform.sizeDelta = Vector2.zero; // 设置为0,表示拉伸到父容器大小 |
| | | |
| | | foreach (Transform child in children) |
| | | { |
| | |
| | | } |
| | | |
| | | protected async UniTask ApplySettings() |
| | | { |
| | | await UniTask.DelayFrame(5); |
| | | |
| | | if (null != transform) |
| | | {
|
| | | if (clickEmptySpaceClose) |
| | | { |
| | | if (clickEmptySpaceClose) |
| | | { |
| | | GameObject goBtnESC = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ClickEmptyCloseMask"), transform); |
| | | // Load |
| | | btnClickEmptyClose = goBtnESC.GetComponent<Button>(); |
| | | btnClickEmptyClose.AddListener(CloseWindow); |
| | | btnClickEmptyClose.transform.SetAsFirstSibling(); |
| | | } |
| | | //延迟创建会导致层级在ScreenMask之上 |
| | | GameObject goBtnESC = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ClickEmptyCloseMask"), transform); |
| | | btnClickEmptyClose = goBtnESC.GetComponent<Button>(); |
| | | btnClickEmptyClose.AddListener(CloseWindow); |
| | | btnClickEmptyClose.transform.SetAsFirstSibling(); |
| | | await UniTask.DelayFrame(5);
|
| | |
|
| | | btnClickEmptyClose = goBtnESC.GetComponent<Button>();
|
| | | btnClickEmptyClose.AddListener(CloseWindow); |
| | | } |
| | | } |
| | | |
| | | |
| | | protected async void ExecuteNextFrame(Action _action) |
| | | { |
| | |
| | | if (canvasGroup != null) |
| | | { |
| | | canvasGroup.alpha = 1f; |
| | | canvasGroup.interactable = false; |
| | | canvasGroup.blocksRaycasts = false; |
| | | canvasGroup.interactable = true; |
| | | canvasGroup.blocksRaycasts = true; |
| | | } |
| | | if (canvasScaler != null) |
| | | { |