@@ -103,18 +103,19 @@ public string LocalPath
103
103
#region 构造函数
104
104
public ResourceManager ( )
105
105
{
106
- //自动监听图集请求,并异步加载图集资源
107
- SpriteAtlasManager . atlasRequested += ( tag , callback ) => {
108
- string assetPath = Asset . AllAssetPaths . Find ( x => x . EndsWith ( $ "{ tag . ToLower ( ) } .spriteatlas") ) ;
109
- if ( ! string . IsNullOrEmpty ( assetPath ) )
110
- {
111
- Asset . LoadAsset < SpriteAtlas > ( assetPath , callback ) ;
112
- }
113
- else
114
- {
115
- throw new GameException ( $ "The path to the SpriteAtlas file could not be found. { tag } ") ;
116
- }
117
- } ;
106
+ ////自动监听图集请求,并异步加载图集资源
107
+ //SpriteAtlasManager.atlasRequested += (tag, callback) =>
108
+ //{
109
+ // string assetPath = Resource.Asset.AllAssetPaths.Find(x => x.EndsWith($"{tag.ToLower()}.spriteatlas"));
110
+ // if (!string.IsNullOrEmpty(assetPath))
111
+ // {
112
+ // Resource.Asset.LoadAsset<SpriteAtlas>(assetPath, callback);
113
+ // }
114
+ // else
115
+ // {
116
+ // throw new GameException($"The path to the SpriteAtlas file could not be found. {tag}");
117
+ // }
118
+ //};
118
119
119
120
//获取事件管理器
120
121
_event = GameFrameworkMode . GetModule < EventManager > ( ) ;
@@ -126,12 +127,6 @@ public ResourceManager()
126
127
_sceneLoadingEventArgs = new SceneLoadingEventArgs ( ) ;
127
128
_sceneLoadedEventArgs = new SceneLoadedEventArgs ( ) ;
128
129
_sceneAsyncOperations = new Dictionary < string , AsyncOperation > ( ) ;
129
-
130
- //BundleResourceHelper
131
- GameObject bundleBehaviourHelper = new GameObject ( "AssetBundleBehaviourHelper" ) ;
132
- Asset = bundleBehaviourHelper . AddComponent < BundleAssetsHelper > ( ) ;
133
- bundleBehaviourHelper . hideFlags = HideFlags . HideAndDontSave ;
134
- GameObject . DontDestroyOnLoad ( bundleBehaviourHelper ) ;
135
130
}
136
131
#endregion
137
132
@@ -157,7 +152,34 @@ public override void OnInit()
157
152
_remoteUpdatePath = Path . Combine ( _remoteUpdatePath , Utility . GetRuntimePlatformName ( ) ) ;
158
153
//资源版本
159
154
Version = new ResourceVersion ( _remoteUpdatePath , LocalPath ) ;
160
- }
155
+
156
+ //选择更新 | 读取本地 | 编辑器
157
+ switch ( ResUpdateType )
158
+ {
159
+ case ResourceUpdateType . None :
160
+ break ;
161
+ case ResourceUpdateType . Update :
162
+ //BundleResourceHelper
163
+ GameObject bundleBehaviourHelper = new GameObject ( "AssetBundleBehaviourHelper" ) ;
164
+ Asset = bundleBehaviourHelper . AddComponent < BundleAssetsHelper > ( ) ;
165
+ bundleBehaviourHelper . hideFlags = HideFlags . HideAndDontSave ;
166
+ GameObject . DontDestroyOnLoad ( bundleBehaviourHelper ) ;
167
+ break ;
168
+ case ResourceUpdateType . Local :
169
+ break ;
170
+ case ResourceUpdateType . Editor :
171
+ #if UNITY_EDITOR
172
+ Asset = new EditorAssetsHelper ( ) ;
173
+ #else
174
+ //如果在非编辑器模式下选择了Editor,使用本地文件
175
+ throw new GameException ( "Please select the correct resource type, not ResourceUpdateType.Editor!" ) ;
176
+ #endif
177
+ break ;
178
+ }
179
+
180
+
181
+
182
+ }
161
183
162
184
163
185
#region 外部接口
@@ -169,15 +191,34 @@ public void SetResourceHelper(IAssetsHelper resourceHelper)
169
191
{
170
192
Asset ? . Clear ( ) ;
171
193
Asset = resourceHelper ;
172
-
173
194
}
174
195
196
+ /// <summary>
197
+ /// 图集请求
198
+ /// </summary>
199
+ /// <param name="tag"></param>
200
+ /// <param name="callback"></param>
201
+ public void OnAtlasRequested ( string operation , Action < string , Action < SpriteAtlas > > callback )
202
+ {
203
+ if ( string . IsNullOrEmpty ( operation ) )
204
+ {
205
+ return ;
206
+ }
207
+ if ( operation . Equals ( "+" ) )
208
+ {
209
+ SpriteAtlasManager . atlasRequested += callback ;
210
+ }
211
+ else if ( operation . Equals ( "-" ) )
212
+ {
213
+ SpriteAtlasManager . atlasRequested -= callback ;
214
+ }
215
+ }
175
216
176
- /// <summary>
177
- /// 设置对象池管理器的
178
- /// </summary>
179
- /// <param name="helper"></param>
180
- public void SetGameObjectPoolHelper ( IGameObjectPoolHelper helper )
217
+ /// <summary>
218
+ /// 设置对象池管理器的
219
+ /// </summary>
220
+ /// <param name="helper"></param>
221
+ public void SetGameObjectPoolHelper ( IGameObjectPoolHelper helper )
181
222
{
182
223
_gameObjectPoolHelper = helper ;
183
224
}
0 commit comments