This commit is contained in:
Wojtek Figat
2021-06-15 13:51:16 +02:00
parent f5cdb0abfd
commit a75e403b35
6 changed files with 48 additions and 9 deletions

View File

@@ -20,7 +20,6 @@ AssetReferenceBase::~AssetReferenceBase()
_asset->OnLoaded.Unbind<AssetReferenceBase, &AssetReferenceBase::OnLoaded>(this);
_asset->OnUnloaded.Unbind<AssetReferenceBase, &AssetReferenceBase::OnUnloaded>(this);
_asset->RemoveReference();
_asset = nullptr;
}
}
@@ -55,13 +54,15 @@ void AssetReferenceBase::OnSet(Asset* asset)
void AssetReferenceBase::OnLoaded(Asset* asset)
{
ASSERT(_asset == asset);
if (_asset != asset)
return;
Loaded();
}
void AssetReferenceBase::OnUnloaded(Asset* asset)
{
ASSERT(_asset == asset);
if (_asset != asset)
return;
Unload();
OnSet(nullptr);
}
@@ -92,7 +93,8 @@ void WeakAssetReferenceBase::OnSet(Asset* asset)
void WeakAssetReferenceBase::OnUnloaded(Asset* asset)
{
ASSERT(_asset == asset);
if (_asset != asset)
return;
Unload();
asset->OnUnloaded.Unbind<WeakAssetReferenceBase, &WeakAssetReferenceBase::OnUnloaded>(this);
_asset = nullptr;

View File

@@ -35,6 +35,7 @@ public:
EventType Changed;
public:
NON_COPYABLE(AssetReferenceBase);
/// <summary>
/// Initializes a new instance of the <see cref="AssetReferenceBase"/> class.
@@ -114,6 +115,22 @@ public:
OnSet(other.Get());
}
AssetReference(AssetReference&& other)
{
OnSet(other.Get());
other.OnSet(nullptr);
}
AssetReference& operator=(AssetReference&& other)
{
if (&other != this)
{
OnSet(other.Get());
other.OnSet(nullptr);
}
return *this;
}
/// <summary>
/// Finalizes an instance of the <see cref="AssetReference"/> class.
/// </summary>

View File

@@ -25,6 +25,7 @@ public:
EventType Unload;
public:
NON_COPYABLE(WeakAssetReferenceBase);
/// <summary>
/// Initializes a new instance of the <see cref="WeakAssetReferenceBase"/> class.
@@ -100,6 +101,22 @@ public:
OnSet(other.Get());
}
WeakAssetReference(WeakAssetReference&& other)
{
OnSet(other.Get());
other.OnSet(nullptr);
}
WeakAssetReference& operator=(WeakAssetReference&& other)
{
if (&other != this)
{
OnSet(other.Get());
other.OnSet(nullptr);
}
return *this;
}
/// <summary>
/// Finalizes an instance of the <see cref="WeakAssetReference"/> class.
/// </summary>