Refactor Asset::GetReferences to support file path references
This commit is contained in:
@@ -536,6 +536,14 @@ void Asset::CancelStreaming()
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void Asset::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
// Fallback to the old API
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS;
|
||||
GetReferences(assets);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS;
|
||||
}
|
||||
|
||||
void Asset::GetReferences(Array<Guid>& output) const
|
||||
{
|
||||
// No refs by default
|
||||
@@ -544,7 +552,8 @@ void Asset::GetReferences(Array<Guid>& output) const
|
||||
Array<Guid> Asset::GetReferences() const
|
||||
{
|
||||
Array<Guid> result;
|
||||
GetReferences(result);
|
||||
Array<String> files;
|
||||
GetReferences(result, files);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,10 +179,13 @@ public:
|
||||
/// For some asset types (e.g. scene or prefab) it may contain invalid asset ids due to not perfect gather method,
|
||||
/// which is optimized to perform scan very quickly. Before using those ids perform simple validation via Content cache API.
|
||||
/// The result collection contains only 1-level-deep references (only direct ones) and is invalid if asset is not loaded.
|
||||
/// Also the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
|
||||
/// Also, the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
|
||||
/// </remarks>
|
||||
/// <param name="output">The output collection of the asset ids referenced by this asset.</param>
|
||||
virtual void GetReferences(Array<Guid, HeapAllocation>& output) const;
|
||||
/// <param name="assets">The output collection of the asset ids referenced by this asset.</param>
|
||||
/// <param name="files">The output list of file paths referenced by this asset. Files might come from project Content folder (relative path is preserved in cooked game), or external location (copied into Content root folder of cooked game).</param>
|
||||
virtual void GetReferences(Array<Guid, HeapAllocation>& assets, Array<String, HeapAllocation>& files) const;
|
||||
// [Deprecated in v1.9]
|
||||
DEPRECATED virtual void GetReferences(Array<Guid, HeapAllocation>& output) const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the asset references. Supported only in Editor.
|
||||
@@ -191,7 +194,7 @@ public:
|
||||
/// For some asset types (e.g. scene or prefab) it may contain invalid asset ids due to not perfect gather method,
|
||||
/// which is optimized to perform scan very quickly. Before using those ids perform simple validation via Content cache API.
|
||||
/// The result collection contains only 1-level-deep references (only direct ones) and is invalid if asset is not loaded.
|
||||
/// Also the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
|
||||
/// Also, the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
|
||||
/// </remarks>
|
||||
/// <returns>The collection of the asset ids referenced by this asset.</returns>
|
||||
API_FUNCTION() Array<Guid, HeapAllocation> GetReferences() const;
|
||||
|
||||
@@ -222,12 +222,10 @@ void AnimationGraph::FindDependencies(AnimGraphBase* graph)
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationGraph::GetReferences(Array<Guid>& output) const
|
||||
void AnimationGraph::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
// Base
|
||||
BinaryAsset::GetReferences(output);
|
||||
|
||||
Graph.GetReferences(output);
|
||||
BinaryAsset::GetReferences(assets, files);
|
||||
Graph.GetReferences(assets);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -64,7 +64,7 @@ private:
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override;
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -45,3 +45,13 @@ MaterialInstance* MaterialBase::CreateVirtualInstance()
|
||||
instance->SetBaseMaterial(this);
|
||||
return instance;
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void MaterialBase::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
BinaryAsset::GetReferences(assets, files);
|
||||
Params.GetReferences(assets);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
Action ParamsChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if material is an material instance.
|
||||
/// Returns true if material is a material instance.
|
||||
/// </summary>
|
||||
virtual bool IsMaterialInstance() const = 0;
|
||||
|
||||
@@ -77,12 +77,6 @@ public:
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override
|
||||
{
|
||||
// Base
|
||||
BinaryAsset::GetReferences(output);
|
||||
|
||||
Params.GetReferences(output);
|
||||
}
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -123,13 +123,11 @@ bool MaterialInstance::IsMaterialInstance() const
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void MaterialInstance::GetReferences(Array<Guid>& output) const
|
||||
void MaterialInstance::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
// Base
|
||||
MaterialBase::GetReferences(output);
|
||||
|
||||
MaterialBase::GetReferences(assets, files);
|
||||
if (_baseMaterial)
|
||||
output.Add(_baseMaterial->GetID());
|
||||
assets.Add(_baseMaterial->GetID());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
// [MaterialBase]
|
||||
bool IsMaterialInstance() const override;
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override;
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
#endif
|
||||
|
||||
// [IMaterial]
|
||||
|
||||
@@ -788,15 +788,13 @@ void Model::CancelStreaming()
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void Model::GetReferences(Array<Guid>& output) const
|
||||
void Model::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
// Base
|
||||
BinaryAsset::GetReferences(output);
|
||||
BinaryAsset::GetReferences(assets, files);
|
||||
|
||||
for (int32 i = 0; i < MaterialSlots.Count(); i++)
|
||||
{
|
||||
output.Add(MaterialSlots[i].Material.GetID());
|
||||
}
|
||||
assets.Add(MaterialSlots[i].Material.GetID());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -251,7 +251,7 @@ public:
|
||||
void InitAsVirtual() override;
|
||||
void CancelStreaming() override;
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override;
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
#endif
|
||||
|
||||
// [StreamableResource]
|
||||
|
||||
@@ -68,12 +68,10 @@ private:
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override
|
||||
{
|
||||
// Base
|
||||
BinaryAsset::GetReferences(output);
|
||||
|
||||
output.Add(Skeleton.GetID());
|
||||
BinaryAsset::GetReferences(assets, files);
|
||||
assets.Add(Skeleton.GetID());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -974,15 +974,13 @@ void SkinnedModel::CancelStreaming()
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void SkinnedModel::GetReferences(Array<Guid>& output) const
|
||||
void SkinnedModel::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
// Base
|
||||
BinaryAsset::GetReferences(output);
|
||||
BinaryAsset::GetReferences(assets, files);
|
||||
|
||||
for (int32 i = 0; i < MaterialSlots.Count(); i++)
|
||||
{
|
||||
output.Add(MaterialSlots[i].Material.GetID());
|
||||
}
|
||||
assets.Add(MaterialSlots[i].Material.GetID());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -323,7 +323,7 @@ public:
|
||||
void InitAsVirtual() override;
|
||||
void CancelStreaming() override;
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override;
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
#endif
|
||||
|
||||
// [StreamableResource]
|
||||
|
||||
@@ -277,12 +277,10 @@ public:
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& output) const override
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override
|
||||
{
|
||||
// Base
|
||||
BinaryAsset::GetReferences(output);
|
||||
|
||||
Graph.GetReferences(output);
|
||||
BinaryAsset::GetReferences(assets, files);
|
||||
Graph.GetReferences(assets);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -109,20 +109,20 @@ uint64 JsonAssetBase::GetMemoryUsage() const
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void FindIds(ISerializable::DeserializeStream& node, Array<Guid>& output)
|
||||
void FindIds(ISerializable::DeserializeStream& node, Array<Guid>& output, Array<String>& files)
|
||||
{
|
||||
if (node.IsObject())
|
||||
{
|
||||
for (auto i = node.MemberBegin(); i != node.MemberEnd(); ++i)
|
||||
{
|
||||
FindIds(i->value, output);
|
||||
FindIds(i->value, output, files);
|
||||
}
|
||||
}
|
||||
else if (node.IsArray())
|
||||
{
|
||||
for (rapidjson::SizeType i = 0; i < node.Size(); i++)
|
||||
{
|
||||
FindIds(node[i], output);
|
||||
FindIds(node[i], output, files);
|
||||
}
|
||||
}
|
||||
else if (node.IsString())
|
||||
@@ -137,13 +137,14 @@ void FindIds(ISerializable::DeserializeStream& node, Array<Guid>& output)
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAssetBase::GetReferences(const StringAnsiView& json, Array<Guid>& output)
|
||||
void JsonAssetBase::GetReferences(const StringAnsiView& json, Array<Guid>& assets)
|
||||
{
|
||||
ISerializable::SerializeDocument document;
|
||||
document.Parse(json.Get(), json.Length());
|
||||
if (document.HasParseError())
|
||||
return;
|
||||
FindIds(document, output);
|
||||
Array<String> files;
|
||||
FindIds(document, assets, files);
|
||||
}
|
||||
|
||||
bool JsonAssetBase::Save(const StringView& path) const
|
||||
@@ -207,7 +208,7 @@ bool JsonAssetBase::Save(JsonWriter& writer) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void JsonAssetBase::GetReferences(Array<Guid>& output) const
|
||||
void JsonAssetBase::GetReferences(Array<Guid>& assets, Array<String>& files) const
|
||||
{
|
||||
if (Data == nullptr)
|
||||
return;
|
||||
@@ -219,7 +220,7 @@ void JsonAssetBase::GetReferences(Array<Guid>& output) const
|
||||
// It produces many invalid ids (like refs to scene objects).
|
||||
// But it's super fast, super low-memory and doesn't involve any advanced systems integration.
|
||||
|
||||
FindIds(*Data, output);
|
||||
FindIds(*Data, assets, files);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
/// Parses Json string to find any object references inside it. It can produce list of references to assets and/or scene objects. Supported only in Editor.
|
||||
/// </summary>
|
||||
/// <param name="json">The Json string.</param>
|
||||
/// <param name="output">The output list of object IDs references by the asset (appended, not cleared).</param>
|
||||
API_FUNCTION() static void GetReferences(const StringAnsiView& json, API_PARAM(Out) Array<Guid, HeapAllocation>& output);
|
||||
/// <param name="assets">The output list of object IDs references by the asset (appended, not cleared).</param>
|
||||
API_FUNCTION() static void GetReferences(const StringAnsiView& json, API_PARAM(Out) Array<Guid, HeapAllocation>& assets);
|
||||
|
||||
/// <summary>
|
||||
/// Saves this asset to the file. Supported only in Editor.
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
const String& GetPath() const override;
|
||||
uint64 GetMemoryUsage() const override;
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid, HeapAllocation>& output) const override;
|
||||
void GetReferences(Array<Guid, HeapAllocation>& assets, Array<String, HeapAllocation>& files) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user