-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
107 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// © 2023 Nikolay Melnikov <n.melnikov@depra.org> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Depra.Assets.Delegates; | ||
using Depra.Assets.Exceptions; | ||
using Depra.Assets.ValueObjects; | ||
using UnityEngine; | ||
|
||
namespace Depra.Assets.Files.Database | ||
{ | ||
public sealed class RuntimeDatabaseAsset<TAsset> : IAssetFile<TAsset>, IDisposable where TAsset : ScriptableObject | ||
{ | ||
private TAsset _loadedAsset; | ||
|
||
public RuntimeDatabaseAsset(string name) : this((IAssetUri) new AssetName(name)) { } | ||
|
||
public RuntimeDatabaseAsset(IAssetUri uri) => Metadata = new AssetMetadata(uri, FileSize.Unknown); | ||
|
||
public AssetMetadata Metadata { get; } | ||
public bool IsLoaded => _loadedAsset != null; | ||
|
||
public TAsset Load() | ||
{ | ||
var loadedAsset = ScriptableObject.CreateInstance<TAsset>(); | ||
Guard.AgainstNull(loadedAsset, () => new AssetCatNotBeCreated(typeof(TAsset), nameof(TAsset))); | ||
|
||
return _loadedAsset = loadedAsset; | ||
} | ||
|
||
public void Unload() | ||
{ | ||
if (_loadedAsset) | ||
{ | ||
_loadedAsset = null; | ||
} | ||
} | ||
|
||
void IDisposable.Dispose() => Unload(); | ||
|
||
IEnumerable<IAssetUri> IAssetFile.Dependencies() => Array.Empty<IAssetUri>(); | ||
|
||
[Obsolete("Not yet supported in Unity. Use RuntimeDatabaseAsset<TAsset>.Load() instead")] | ||
Task<TAsset> IAssetFile<TAsset>.LoadAsync(DownloadProgressDelegate onProgress, | ||
CancellationToken cancellationToken) | ||
{ | ||
onProgress?.Invoke(DownloadProgress.Full); | ||
return Task.FromResult(IsLoaded ? _loadedAsset : Load()); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters