Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hex
ygopro2
Commits
3e267a81
Commit
3e267a81
authored
Jul 19, 2025
by
hex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized GameTextureManager
parent
a992169d
Pipeline
#39190
failed
Changes
5
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
538 additions
and
928 deletions
+538
-928
Assets/SibylSystem/Program.cs
Assets/SibylSystem/Program.cs
+53
-1
Assets/SibylSystem/ResourceManagers/GameTextureManager.cs
Assets/SibylSystem/ResourceManagers/GameTextureManager.cs
+465
-885
Assets/SibylSystem/ResourceManagers/GameTextureManagerRunner.cs
.../SibylSystem/ResourceManagers/GameTextureManagerRunner.cs
+0
-23
Assets/SibylSystem/ResourceManagers/GameTextureManagerRunner.cs.meta
...lSystem/ResourceManagers/GameTextureManagerRunner.cs.meta
+0
-11
Assets/SibylSystem/ResourceManagers/UnityFileDownloader.cs
Assets/SibylSystem/ResourceManagers/UnityFileDownloader.cs
+20
-8
No files found.
Assets/SibylSystem/Program.cs
View file @
3e267a81
...
@@ -367,7 +367,13 @@ public class Program : MonoBehaviour
...
@@ -367,7 +367,13 @@ public class Program : MonoBehaviour
InterString
.
initialize
(
"config/translation.conf"
);
InterString
.
initialize
(
"config/translation.conf"
);
// 显示一个简单的加载提示
// 显示一个简单的加载提示
PrintToChat
(
InterString
.
Get
(
"正在加载本地数据..."
));
PrintToChat
(
InterString
.
Get
(
"正在加载本地数据..."
));
// GameTextureManager.initialize();
if
(!
GameTextureManager
.
IsInitialized
)
{
GameTextureManager
.
InitializeAssets
();
// 1. 同步加载核心资源
GameTextureManager
.
StartBackgroundThread
();
// 2. 启动后台图片加载线程
}
Config
.
initialize
(
"config/config.conf"
);
Config
.
initialize
(
"config/config.conf"
);
// [新增] 封装文件加载逻辑,避免重复检查
// [新增] 封装文件加载逻辑,避免重复检查
...
@@ -1205,6 +1211,39 @@ public class Program : MonoBehaviour
...
@@ -1205,6 +1211,39 @@ public class Program : MonoBehaviour
Resources
.
UnloadUnusedAssets
();
Resources
.
UnloadUnusedAssets
();
onRESIZED
();
onRESIZED
();
}
}
if
(
GameTextureManager
.
IsInitialized
)
{
// 1. 检查并处理下载请求
if
(
GameTextureManager
.
HasDownloadRequests
())
{
var
request
=
GameTextureManager
.
GetNextDownloadRequest
();
if
(!
string
.
IsNullOrEmpty
(
request
.
Url
))
{
// Program 自身就是 MonoBehaviour,所以可以直接启动协程
StartCoroutine
(
DownloadAndProcessFile
(
request
));
}
}
// 2. 检查并处理纹理创建任务 (分帧处理避免卡顿)
int
tasksProcessedThisFrame
=
0
;
int
maxTasksPerFrame
=
5
;
while
(
GameTextureManager
.
HasMainThreadTasks
()
&&
tasksProcessedThisFrame
<
maxTasksPerFrame
)
{
var
resource
=
GameTextureManager
.
GetNextMainThreadTask
();
if
(
resource
!=
null
)
{
GameTextureManager
.
CreateTextureFromResource
(
resource
);
tasksProcessedThisFrame
++;
}
else
{
break
;
}
}
}
fixALLcamerasPreFrame
();
fixALLcamerasPreFrame
();
wheelValue
=
UICamera
.
GetAxis
(
"Mouse ScrollWheel"
)
*
50
;
wheelValue
=
UICamera
.
GetAxis
(
"Mouse ScrollWheel"
)
*
50
;
pointedGameObject
=
null
;
pointedGameObject
=
null
;
...
@@ -1269,6 +1308,15 @@ public class Program : MonoBehaviour
...
@@ -1269,6 +1308,15 @@ public class Program : MonoBehaviour
}
}
}
}
// NEW: 这个辅助协程也从 Runner 移到了这里
private
static
IEnumerator
DownloadAndProcessFile
(
GameTextureManager
.
DownloadRequest
request
)
{
yield
return
UnityFileDownloader
.
DownloadFileAsync
(
request
.
Url
,
request
.
FilePath
,
(
success
)
=>
{
GameTextureManager
.
OnDownloadComplete
(
success
,
request
);
});
}
private
void
onRESIZED
()
private
void
onRESIZED
()
{
{
preWid
=
Screen
.
width
;
preWid
=
Screen
.
width
;
...
@@ -1330,6 +1378,10 @@ public class Program : MonoBehaviour
...
@@ -1330,6 +1378,10 @@ public class Program : MonoBehaviour
{
{
servants
[
i
].
OnQuit
();
servants
[
i
].
OnQuit
();
}
}
// 在应用退出时,优雅地关闭 GameTextureManager 的后台线程
GameTextureManager
.
Shutdown
();
Running
=
false
;
Running
=
false
;
try
try
{
{
...
...
Assets/SibylSystem/ResourceManagers/GameTextureManager.cs
View file @
3e267a81
This diff is collapsed.
Click to expand it.
Assets/SibylSystem/ResourceManagers/GameTextureManagerRunner.cs
deleted
100644 → 0
View file @
a992169d
using
System.Collections
;
using
UnityEngine
;
/// <summary>
/// 这是一个 MonoBehaviour 帮助器,专为静态的 GameTextureManager 服务。
/// 它的职责是在主线程上执行任务,例如轮询下载队列和启动协程。
/// 这个类的实例由 GameTextureManager 通过 [RuntimeInitializeOnLoadMethod] 自动创建。
/// </summary>
public
class
GameTextureManagerRunner
:
MonoBehaviour
{
void
Update
()
{
// 在主线程的每一帧检查是否有待处理的下载请求
if
(
GameTextureManager
.
HasDownloadRequests
())
{
// 从 GameTextureManager 获取一个请求
var
request
=
GameTextureManager
.
GetNextDownloadRequest
();
// 使用这个 MonoBehaviour 实例来启动下载协程
StartCoroutine
(
GameTextureManager
.
DownloadAndProcessFile
(
request
));
}
}
}
Assets/SibylSystem/ResourceManagers/GameTextureManagerRunner.cs.meta
deleted
100644 → 0
View file @
a992169d
fileFormatVersion: 2
guid: cb7d20dd5a7074bc089a6c75c87e34da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/SibylSystem/ResourceManagers/UnityFileDownloader.cs
View file @
3e267a81
...
@@ -16,10 +16,20 @@ public class UnityFileDownloader
...
@@ -16,10 +16,20 @@ public class UnityFileDownloader
Action
<
float
>
onProgress
=
null
Action
<
float
>
onProgress
=
null
)
)
{
{
string
directoryPath
=
Path
.
GetDirectoryName
(
filePath
);
// 确保目录存在
if
(!
Directory
.
Exists
(
directoryPath
))
try
{
{
Directory
.
CreateDirectory
(
directoryPath
);
string
directoryPath
=
Path
.
GetDirectoryName
(
filePath
);
if
(!
Directory
.
Exists
(
directoryPath
))
{
Directory
.
CreateDirectory
(
directoryPath
);
}
}
catch
(
Exception
e
)
{
Debug
.
LogError
(
"Failed to create directory for "
+
filePath
+
". Error: "
+
e
.
Message
);
if
(
onComplete
!=
null
)
onComplete
.
Invoke
(
false
);
yield
break
;
// 提前退出协程
}
}
string
tempFilePath
=
filePath
+
".tmp"
;
string
tempFilePath
=
filePath
+
".tmp"
;
...
@@ -28,6 +38,8 @@ public class UnityFileDownloader
...
@@ -28,6 +38,8 @@ public class UnityFileDownloader
File
.
Delete
(
tempFilePath
);
File
.
Delete
(
tempFilePath
);
}
}
Debug
.
Log
(
string
.
Format
(
"Downloading: {0} -> {1}"
,
url
,
filePath
));
using
(
UnityWebRequest
uwr
=
new
UnityWebRequest
(
url
,
UnityWebRequest
.
kHttpVerbGET
))
using
(
UnityWebRequest
uwr
=
new
UnityWebRequest
(
url
,
UnityWebRequest
.
kHttpVerbGET
))
{
{
uwr
.
downloadHandler
=
new
DownloadHandlerFile
(
tempFilePath
);
uwr
.
downloadHandler
=
new
DownloadHandlerFile
(
tempFilePath
);
...
@@ -80,15 +92,15 @@ public class UnityFileDownloader
...
@@ -80,15 +92,15 @@ public class UnityFileDownloader
switch
(
extension
)
switch
(
extension
)
{
{
case
".png"
:
case
".png"
:
return
2
0
;
return
4
0
;
case
".jpg"
:
case
".jpg"
:
return
2
0
;
return
4
0
;
case
".cdb"
:
case
".cdb"
:
return
5
0
;
return
8
0
;
case
".conf"
:
case
".conf"
:
return
2
0
;
return
4
0
;
default
:
default
:
return
2
0
;
return
4
0
;
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment