New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added selective ContentManager asset unloading #6663
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -471,6 +471,58 @@ public virtual void Unload() | |
loadedAssets.Clear(); | ||
} | ||
|
||
/// <summary> | ||
/// Unloads a single asset. | ||
/// </summary> | ||
/// <param name="assetName">The name of the asset to unload. This cannot be null.</param> | ||
public virtual void UnloadAsset(string assetName) | ||
{ | ||
if (string.IsNullOrEmpty(assetName)) | ||
{ | ||
throw new ArgumentNullException("assetName"); | ||
} | ||
if (disposed) | ||
{ | ||
throw new ObjectDisposedException("ContentManager"); | ||
} | ||
|
||
//Check if the asset exists | ||
object asset; | ||
if (loadedAssets.TryGetValue(assetName, out asset)) | ||
{ | ||
//Check if it's disposable and remove it from the disposable list if so | ||
var disposable = asset as IDisposable; | ||
if (disposable != null) | ||
{ | ||
disposable.Dispose(); | ||
disposableAssets.Remove(disposable); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why |
||
} | ||
|
||
loadedAssets.Remove(assetName); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Unloads a set of assets. | ||
/// </summary> | ||
/// <param name="assetNames">The names of the assets to unload.</param> | ||
public virtual void UnloadAssets(IList<string> assetNames) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For usability, can this be |
||
{ | ||
if (assetNames == null) | ||
{ | ||
throw new ArgumentNullException("assetNames"); | ||
} | ||
if (disposed) | ||
{ | ||
throw new ObjectDisposedException("ContentManager"); | ||
} | ||
|
||
for (int i = 0; i < assetNames.Count; i++) | ||
{ | ||
UnloadAsset(assetNames[i]); | ||
} | ||
} | ||
|
||
public string RootDirectory | ||
{ | ||
get | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does overloading
Unload
make more sense thanUnloadAsset
, since the load method isLoad
, notLoadAsset
?