// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Content/JsonAsset.h"
#include "Engine/Content/AssetReference.h"
///
/// Json asset reference utility. References resource with a typed data type.
///
/// Type of the asset instance type.
template
API_STRUCT(NoDefault, Template, MarshalAs=JsonAsset*) struct JsonAssetReference : AssetReference
{
JsonAssetReference() = default;
JsonAssetReference(JsonAsset* asset)
{
OnSet(asset);
}
///
/// Gets the deserialized native object instance of the given type. Returns null if asset is not loaded or loaded object has different type.
///
/// The asset instance object or null.
FORCE_INLINE T* GetInstance() const
{
return _asset ? Get()->template GetInstance() : nullptr;
}
JsonAssetReference& operator=(JsonAsset* asset) noexcept
{
OnSet(asset);
return *this;
}
operator JsonAsset*() const
{
return Get();
}
};