Commit 6df1b893 authored by gaorui's avatar gaorui
Browse files

Merge branch 'feat-dev-fixui' into 'feat-preserv'

feat(app): 修复动态 ui日志文字滚动问题,解决提示 purchasing 报错问题

See merge request !21
parents d95ddb07 8a58d58a
...@@ -3989,7 +3989,7 @@ RectTransform: ...@@ -3989,7 +3989,7 @@ RectTransform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1562069058} m_GameObject: {fileID: 1562069058}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 50} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
......
...@@ -78,39 +78,56 @@ public class LogViewer : MonoBehaviour ...@@ -78,39 +78,56 @@ public class LogViewer : MonoBehaviour
logText.text = sb.ToString(); logText.text = sb.ToString();
// ✅ 动态计算 Text 实际高度 // 动态设置尺寸
float preferredHeight = CalculateTextHeight(logText.text, logText); RectTransform textRect = logText.GetComponent<RectTransform>();
RectTransform contentRect = logText.GetComponent<RectTransform>().parent as RectTransform; RectTransform contentRect = scrollRect.content;
if (contentRect != null) RectTransform viewportRect = scrollRect.viewport;
if (textRect != null && contentRect != null && viewportRect != null)
{ {
contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, Mathf.Max(preferredHeight, 500)); // 设置 Text 和 Content 的宽度等于 Viewport 宽度
float viewportWidth = viewportRect.rect.width;
textRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, viewportWidth);
contentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, viewportWidth);
// 计算文本内容的实际高度
float textHeight = CalculateTextHeight(logText.text, logText, viewportWidth);
// 设置 Content 的高度
contentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, textHeight);
// 强制更新布局
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
Canvas.ForceUpdateCanvases();
} }
// 自动滚动到底部 // 自动滚动到底部
if (autoScroll) if (autoScroll)
{ {
Canvas.ForceUpdateCanvases(); ScrollToBottomNow();
StartCoroutine(ScrollToBottom());
} }
} }
// ✅ 计算 Text 实际高度 // 计算文本内容的实际高度
[Preserve] [Preserve]
float CalculateTextHeight(string text, Text textComponent) float CalculateTextHeight(string text, Text textComponent, float width)
{ {
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
return 0; return 100;
// 创建生成设置
var settings = textComponent.GetGenerationSettings(new Vector2(width, 0));
// 获取文本的首选高度
float height = textComponent.cachedTextGenerator.GetPreferredHeight(text, settings);
var style = textComponent.GetGenerationSettings(textComponent.rectTransform.rect.size);
var height = textComponent.cachedTextGenerator.GetPreferredHeight(text, style);
return height / textComponent.pixelsPerUnit; return height / textComponent.pixelsPerUnit;
} }
[Preserve] [Preserve]
IEnumerator ScrollToBottom() void ScrollToBottomNow()
{ {
yield return null; // 等待一帧 // 滚动到底部
scrollRect.verticalNormalizedPosition = 0f; scrollRect.verticalNormalizedPosition = 0f;
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
"com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.vscode": "1.2.5", "com.unity.ide.vscode": "1.2.5",
"com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.purchasing": "4.11.0",
"com.unity.test-framework": "1.1.33", "com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.7", "com.unity.textmeshpro": "3.0.7",
"com.unity.timeline": "1.7.7", "com.unity.timeline": "1.7.7",
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
"dependencies": { "dependencies": {
"com.unity.ugui": "1.0.0" "com.unity.ugui": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.ai.navigation": { "com.unity.ai.navigation": {
"version": "1.1.6", "version": "1.1.6",
...@@ -31,38 +31,38 @@ ...@@ -31,38 +31,38 @@
"dependencies": { "dependencies": {
"com.unity.modules.ai": "1.0.0" "com.unity.modules.ai": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.analytics": { "com.unity.analytics": {
"version": "3.8.1", "version": "3.8.1",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.services.analytics": "1.0.4", "com.unity.ugui": "1.0.0",
"com.unity.ugui": "1.0.0" "com.unity.services.analytics": "1.0.4"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.collab-proxy": { "com.unity.collab-proxy": {
"version": "2.10.0", "version": "2.10.0",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.editorcoroutines": { "com.unity.editorcoroutines": {
"version": "1.0.0", "version": "1.0.0",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.ext.nunit": { "com.unity.ext.nunit": {
"version": "1.0.6", "version": "1.0.6",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.feature.development": { "com.unity.feature.development": {
"version": "1.0.1", "version": "1.0.1",
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"dependencies": { "dependencies": {
"com.unity.ext.nunit": "1.0.6" "com.unity.ext.nunit": "1.0.6"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.ide.visualstudio": { "com.unity.ide.visualstudio": {
"version": "2.0.22", "version": "2.0.22",
...@@ -94,41 +94,28 @@ ...@@ -94,41 +94,28 @@
"dependencies": { "dependencies": {
"com.unity.test-framework": "1.1.9" "com.unity.test-framework": "1.1.9"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.ide.vscode": { "com.unity.ide.vscode": {
"version": "1.2.5", "version": "1.2.5",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.nuget.newtonsoft-json": { "com.unity.nuget.newtonsoft-json": {
"version": "3.2.1", "version": "3.2.1",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.performance.profile-analyzer": { "com.unity.performance.profile-analyzer": {
"version": "1.2.3", "version": "1.2.3",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
},
"com.unity.purchasing": {
"version": "4.11.0",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.services.core": "1.8.2"
},
"url": "https://packages.unity.cn"
}, },
"com.unity.services.analytics": { "com.unity.services.analytics": {
"version": "6.0.3", "version": "6.0.3",
...@@ -139,25 +126,25 @@ ...@@ -139,25 +126,25 @@
"com.unity.services.core": "1.12.4", "com.unity.services.core": "1.12.4",
"com.unity.modules.jsonserialize": "1.0.0" "com.unity.modules.jsonserialize": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.services.core": { "com.unity.services.core": {
"version": "1.14.0", "version": "1.14.0",
"depth": 1, "depth": 2,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.modules.androidjni": "1.0.0", "com.unity.modules.androidjni": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.modules.unitywebrequest": "1.0.0" "com.unity.modules.unitywebrequest": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.settings-manager": { "com.unity.settings-manager": {
"version": "2.1.0", "version": "2.1.0",
"depth": 2, "depth": 2,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.test-framework": { "com.unity.test-framework": {
"version": "1.1.33", "version": "1.1.33",
...@@ -168,7 +155,7 @@ ...@@ -168,7 +155,7 @@
"com.unity.modules.imgui": "1.0.0", "com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0" "com.unity.modules.jsonserialize": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.testtools.codecoverage": { "com.unity.testtools.codecoverage": {
"version": "1.2.6", "version": "1.2.6",
...@@ -178,7 +165,7 @@ ...@@ -178,7 +165,7 @@
"com.unity.test-framework": "1.0.16", "com.unity.test-framework": "1.0.16",
"com.unity.settings-manager": "1.0.1" "com.unity.settings-manager": "1.0.1"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.textmeshpro": { "com.unity.textmeshpro": {
"version": "3.0.7", "version": "3.0.7",
...@@ -187,7 +174,7 @@ ...@@ -187,7 +174,7 @@
"dependencies": { "dependencies": {
"com.unity.ugui": "1.0.0" "com.unity.ugui": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.timeline": { "com.unity.timeline": {
"version": "1.7.7", "version": "1.7.7",
...@@ -199,7 +186,7 @@ ...@@ -199,7 +186,7 @@
"com.unity.modules.animation": "1.0.0", "com.unity.modules.animation": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0" "com.unity.modules.particlesystem": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.ugui": { "com.unity.ugui": {
"version": "1.0.0", "version": "1.0.0",
...@@ -218,7 +205,7 @@ ...@@ -218,7 +205,7 @@
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0" "com.unity.modules.jsonserialize": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.xr.legacyinputhelpers": { "com.unity.xr.legacyinputhelpers": {
"version": "2.1.12", "version": "2.1.12",
...@@ -228,7 +215,7 @@ ...@@ -228,7 +215,7 @@
"com.unity.modules.vr": "1.0.0", "com.unity.modules.vr": "1.0.0",
"com.unity.modules.xr": "1.0.0" "com.unity.modules.xr": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.com"
}, },
"com.unity.modules.ai": { "com.unity.modules.ai": {
"version": "1.0.0", "version": "1.0.0",
......
...@@ -21,7 +21,7 @@ MonoBehaviour: ...@@ -21,7 +21,7 @@ MonoBehaviour:
m_Registries: m_Registries:
- m_Id: main - m_Id: main
m_Name: m_Name:
m_Url: https://packages.unity.cn m_Url: https://packages.unity.com
m_Scopes: [] m_Scopes: []
m_IsDefault: 1 m_IsDefault: 1
m_Capabilities: 7 m_Capabilities: 7
...@@ -31,6 +31,6 @@ MonoBehaviour: ...@@ -31,6 +31,6 @@ MonoBehaviour:
m_RegistryInfoDraft: m_RegistryInfoDraft:
m_Modified: 0 m_Modified: 0
m_ErrorMessage: m_ErrorMessage:
m_UserModificationsInstanceId: -836 m_UserModificationsInstanceId: -834
m_OriginalInstanceId: -838 m_OriginalInstanceId: -836
m_LoadAssets: 0 m_LoadAssets: 0
...@@ -266,8 +266,8 @@ PlayerSettings: ...@@ -266,8 +266,8 @@ PlayerSettings:
useCustomProguardFile: 1 useCustomProguardFile: 1
AndroidTargetArchitectures: 2 AndroidTargetArchitectures: 2
AndroidTargetDevices: 0 AndroidTargetDevices: 0
AndroidSplashScreenScale: 0 AndroidSplashScreenScale: 2
androidSplashScreen: {fileID: 0} androidSplashScreen: {fileID: 2800000, guid: 17c350171f7a3ca479f830547c66d187, type: 3}
AndroidKeystoreName: '{dedicated}: sds.keystore' AndroidKeystoreName: '{dedicated}: sds.keystore'
AndroidKeyaliasName: ft AndroidKeyaliasName: ft
AndroidEnableArmv9SecurityFeatures: 0 AndroidEnableArmv9SecurityFeatures: 0
......
...@@ -10,8 +10,6 @@ UnityConnectSettings: ...@@ -10,8 +10,6 @@ UnityConnectSettings:
m_EventUrl: https://cdp.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
m_ConfigUrl: https://config.uca.cloud.unity3d.com m_ConfigUrl: https://config.uca.cloud.unity3d.com
m_DashboardUrl: https://dashboard.unity3d.com m_DashboardUrl: https://dashboard.unity3d.com
m_CNEventUrl: https://cdp.cloud.unity.cn/v1/events
m_CNConfigUrl: https://cdp.cloud.unity.cn/config
m_TestInitMode: 0 m_TestInitMode: 0
CrashReportingSettings: CrashReportingSettings:
m_EventUrl: https://perf-events.cloud.unity.cn m_EventUrl: https://perf-events.cloud.unity.cn
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment