Commit 83c2db9b authored by hex's avatar hex

fix and optimized

parent fe25df28
Pipeline #39467 failed
fileFormatVersion: 2
guid: 745afe00a5dc744c0aaee8cdbf659869
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ca93caf9d884c4ed18893f754c92c0ff
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 22c203805f36244f6bde871e8a9ec34c
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 0fa7efcef48b5442bacfb0a0d1a615e2
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: db507f597770e41d5bc8e78dcb375710
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7f387acc3d549427a8d0012693471c9c
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
......@@ -339,12 +339,36 @@ public class Program : MonoBehaviour
System.IO.Directory.SetCurrentDirectory(ANDROID_GAME_PATH);
#elif UNITY_IPHONE //iPhone
// string GamePaths = Application.persistentDataPath + "/ygopro2/";
// if (!File.Exists(GamePaths + "updates/version-1.036.2-TCube.txt"))
// {
// string filePath = Application.streamingAssetsPath + "/ygopro2-data.zip";
// ExtractZipFile(System.IO.File.ReadAllBytes(filePath), GamePaths);
// }
// Environment.CurrentDirectory = GamePaths;
// System.IO.Directory.SetCurrentDirectory(GamePaths);
string GamePaths = Application.persistentDataPath + "/ygopro2/";
if (!File.Exists(GamePaths + "updates/version-1.036.2-TCube.txt"))
// iOS文件权限检查
if (!Directory.Exists(GamePaths))
{
Directory.CreateDirectory(GamePaths);
}
// 优化版本检查 - 使用PlayerPrefs而非文件检查
string currentVersion = "1.036.2";
string installedVersion = PlayerPrefs.GetString("InstalledVersion", "");
if (installedVersion != currentVersion)
{
string filePath = Application.streamingAssetsPath + "/ygopro2-data.zip";
ExtractZipFile(System.IO.File.ReadAllBytes(filePath), GamePaths);
if (File.Exists(filePath))
{
ExtractZipFile(System.IO.File.ReadAllBytes(filePath), GamePaths);
PlayerPrefs.SetString("InstalledVersion", currentVersion);
PlayerPrefs.Save();
}
}
Environment.CurrentDirectory = GamePaths;
System.IO.Directory.SetCurrentDirectory(GamePaths);
#endif
......@@ -1137,6 +1161,10 @@ public class Program : MonoBehaviour
private float m_FPS = 0;
// [新增] 用于下载限流的变量
private int _activeDownloads = 0;
private const int MAX_CONCURRENT_DOWNLOADS = 8;
void Start()
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN //编译器、Windows
......@@ -1196,6 +1224,7 @@ public class Program : MonoBehaviour
GUI.Label(new Rect(10, 5, 200, 200), "[Ver 1.036.2-TCube] " + "FPS: " + FPS);
}
void Update()
{
FrameUpdate++;
......@@ -1214,20 +1243,25 @@ public class Program : MonoBehaviour
if (GameTextureManager.IsInitialized)
{
// 1. 检查并处理下载请求
if (GameTextureManager.HasDownloadRequests())
// 1. 实现下载限流
// 只要当前活跃的下载数小于最大限制,并且队列里有待下载的任务,就启动新的下载。
while (_activeDownloads < MAX_CONCURRENT_DOWNLOADS && GameTextureManager.HasDownloadRequests())
{
var request = GameTextureManager.GetNextDownloadRequest();
if (!string.IsNullOrEmpty(request.Url))
{
// Program 自身就是 MonoBehaviour,所以可以直接启动协程
StartCoroutine(DownloadAndProcessFile(request));
_activeDownloads++; // 增加活跃下载计数
// 启动下载协程,并传入一个回调,用于在下载结束后减少计数
StartCoroutine(DownloadAndProcessFile(request, () =>
{
_activeDownloads--;
}));
}
}
// 2. 检查并处理纹理创建任务 (分帧处理避免卡顿)
int tasksProcessedThisFrame = 0;
int maxTasksPerFrame = 5;
int maxTasksPerFrame = 5; // 每帧最多创建5个纹理,防止卡顿
while (GameTextureManager.HasMainThreadTasks() && tasksProcessedThisFrame < maxTasksPerFrame)
{
......@@ -1308,15 +1342,28 @@ public class Program : MonoBehaviour
}
}
// NEW: 这个辅助协程也从 Runner 移到了这里
private static IEnumerator DownloadAndProcessFile(GameTextureManager.DownloadRequest request)
private static IEnumerator DownloadAndProcessFile(GameTextureManager.DownloadRequest request, Action onComplete)
{
yield return UnityFileDownloader.DownloadFileAsync(request.Url, request.FilePath, (success) =>
try
{
// 使用 yield return 等待下载协程完成
yield return UnityFileDownloader.DownloadFileAsync(request.Url, request.FilePath, (success) =>
{
// UnityFileDownloader的回调会通知GameTextureManager
GameTextureManager.OnDownloadComplete(success, request);
});
}
finally
{
GameTextureManager.OnDownloadComplete(success, request);
});
// 无论下载成功或失败,最后都必须调用 onComplete 回调来减少活跃下载计数
if (onComplete != null)
{
onComplete.Invoke();
}
}
}
private void onRESIZED()
{
preWid = Screen.width;
......
......@@ -190,13 +190,13 @@ public class UnityFileDownloader
switch (extension)
{
case ".png":
return 40;
return 100;
case ".jpg":
return 40;
return 100;
case ".cdb":
return 80;
return 120;
case ".conf":
return 40;
return 50;
default:
return 40;
}
......
......@@ -119,10 +119,6 @@ public class Setting : WindowServant2D
fps = int.Parse(setting.LimFPS.value);
}
Application.targetFrameRate = fps;
if (fps == 120)
{
QualitySettings.vSyncCount = 0;
}
}
private void readVales()
......
<?xml version="1.0" encoding="utf-8"?>
<linker>
<assembly fullname="mscorlib">
<namespace fullname="System.Security.Cryptography" preserve="all"/>
</assembly>
<assembly fullname="System">
<namespace fullname="System.Security.Cryptography" preserve="all"/>
</assembly>
<assembly fullname="I18N" preserve="all" />
<assembly fullname="I18N.CJK" preserve="all" />
<assembly fullname="I18N.MidEast" preserve="all" />
<assembly fullname="I18N.Other" preserve="all" />
<assembly fullname="I18N.Rare" preserve="all" />
<assembly fullname="I18N.West" preserve="all" />
</linker>
\ No newline at end of file
fileFormatVersion: 2
guid: 81319183752bb400c84cf0db173f6360
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -777,7 +777,7 @@ PlayerSettings:
WebGL: 1
Windows Store Apps: 1
XboxOne: 1
iPhone: 2
iPhone: 1
tvOS: 1
incrementalIl2cppBuild:
iPhone: 0
......
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