| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的InitComponentInternal报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的InitComponentInternal报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | |
| | | try |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的InitComponent报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的InitComponent报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | |
| | | // 保存原始值用于动画 |
| | |
| | | { |
| | | if (Screen.height / Screen.width > 1.8)//宽屏需要适配 |
| | | { |
| | | //上下各间隔SafeWidth |
| | | _rectTransform.offsetMax = new Vector2(0, -SafeHeightUp); //上 |
| | | _rectTransform.offsetMin = new Vector2(0, SafeHeightDown); //下 |
| | | _rectTransform.offsetMax = new Vector2(0, -SafeHeightUp); //上 |
| | | _rectTransform.offsetMin = new Vector2(0, SafeHeightDown); //下 |
| | | } |
| | | originalPosition = _rectTransform.anchoredPosition; |
| | | } |
| | |
| | | |
| | | btnClickEmptyClose.enabled = false; |
| | | } |
| | | |
| | | |
| | | protected async void ExecuteNextFrame(Action _action) |
| | | { |
| | |
| | | // 设置UI层级 |
| | | public void SetSortingOrder(int order) |
| | | { |
| | | canvas.sortingOrder = order; |
| | | if (canvas == null) |
| | | canvas = GetComponent<Canvas>(); |
| | | if (canvas != null) |
| | | canvas.sortingOrder = order; |
| | | } |
| | | |
| | | protected virtual void OnPreOpen() |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的OnPreOpen报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的OnPreOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | |
| | | StopCurrentAnimation(); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的OnOpen报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的OnOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | |
| | | ApplyClickEmptySpaceClose(); |
| | | ApplyClickEmptySpaceClose().Forget(); |
| | | |
| | | #if UNITY_WEBGL |
| | | // WebGL 诊断:检测 Image 组件的 sprite 是否为 null |
| | | DiagCheckImageSprites(); |
| | | #endif |
| | | |
| | | ExecuteNextFrame(() => |
| | | { |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的NextFrameAfterOpen报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的NextFrameAfterOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | }); |
| | | } |
| | |
| | | { |
| | | |
| | | } |
| | | |
| | | #if UNITY_WEBGL |
| | | /// <summary> |
| | | /// WebGL 诊断:检测所有 Image 子组件的 sprite 状态。 |
| | | /// 用于排查 WebGL 构建中 Image 资源丢失的问题。 |
| | | /// </summary> |
| | | private void DiagCheckImageSprites() |
| | | { |
| | | var images = GetComponentsInChildren<Image>(true); |
| | | int nullCount = 0; |
| | | int totalCount = images.Length; |
| | | var sb = new System.Text.StringBuilder(); |
| | | |
| | | foreach (var img in images) |
| | | { |
| | | if (img.sprite == null && img.overrideSprite == null) |
| | | { |
| | | // 跳过 Color-only 或 mask 用途的 Image(无需 sprite) |
| | | if (img.type == Image.Type.Simple && img.color.a < 0.01f) |
| | | continue; |
| | | |
| | | nullCount++; |
| | | string path = GetTransformPath(img.transform); |
| | | sb.AppendLine($" [NULL sprite] {path} (type={img.type}, raycast={img.raycastTarget})"); |
| | | } |
| | | } |
| | | |
| | | var rawImages = GetComponentsInChildren<RawImage>(true); |
| | | int rawNullCount = 0; |
| | | foreach (var ri in rawImages) |
| | | { |
| | | if (ri.texture == null) |
| | | { |
| | | rawNullCount++; |
| | | string path = GetTransformPath(ri.transform); |
| | | sb.AppendLine($" [NULL texture] RawImage: {path}"); |
| | | } |
| | | } |
| | | |
| | | if (nullCount > 0 || rawNullCount > 0) |
| | | { |
| | | Debug.LogWarning($"[UIBase][SpriteDiag] {uiName}: {nullCount}/{totalCount} Image sprites NULL, {rawNullCount} RawImage textures NULL\n{sb}"); |
| | | } |
| | | else |
| | | { |
| | | Debug.Log($"[UIBase][SpriteDiag] {uiName}: All {totalCount} Image sprites OK"); |
| | | } |
| | | |
| | | // 检查 Canvas 状态 |
| | | if (canvas != null) |
| | | { |
| | | Debug.Log($"[UIBase][SpriteDiag] {uiName} Canvas: renderMode={canvas.renderMode}, worldCamera={(canvas.worldCamera != null ? canvas.worldCamera.name : "NULL")}, sortingOrder={canvas.sortingOrder}"); |
| | | } |
| | | } |
| | | |
| | | private string GetTransformPath(Transform t) |
| | | { |
| | | string path = t.name; |
| | | Transform parent = t.parent; |
| | | int depth = 0; |
| | | while (parent != null && parent != transform && depth < 10) |
| | | { |
| | | path = parent.name + "/" + path; |
| | | parent = parent.parent; |
| | | depth++; |
| | | } |
| | | return path; |
| | | } |
| | | #endif |
| | | |
| | | // 关闭UI - 修改后的方法 |
| | | public void HandleClose() |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的OnPreClose报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的OnPreClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | |
| | | StopCurrentAnimation(); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的OnClose报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的OnClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | |
| | | if (closeAnimationType == UIAnimationType.None) |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的CompleteClose报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的CompleteClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | } |
| | | // 否则在动画完成后禁用游戏对象(在PlayCloseAnimation中处理) |
| | |
| | | } |
| | | catch (System.Exception e) |
| | | { |
| | | Debug.LogError($"播放打开动画时出错: {e.StackTrace}"); |
| | | Debug.LogError($"播放打开动画时出错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | |
| | | // 出错时确保UI可见并可交互 |
| | | if (canvasGroup != null) |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Debug.LogError($"{uiName}界面的CompleteClose报错: {e.StackTrace}"); |
| | | Debug.LogError($"{uiName}界面的CompleteClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | } |
| | | } |
| | | }); |
| | |
| | | } |
| | | catch (System.Exception e) |
| | | { |
| | | Debug.LogError($"播放关闭动画时出错: {e.StackTrace}"); |
| | | Debug.LogError($"播放关闭动画时出错: message: {e.Message} \nStackTrace: {e.StackTrace}"); |
| | | |
| | | // 出错时直接完成关闭 |
| | | isAnimating = false; |