Improve JsonAssetReference
This commit is contained in:
@@ -146,7 +146,7 @@ namespace FlaxEngine
|
||||
public string Path;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BehaviorKnowledgeSelectorAny"/> structure.
|
||||
/// Initializes a new instance of the <see cref="BehaviorKnowledgeSelector{T}"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="path">The selector path.</param>
|
||||
public BehaviorKnowledgeSelector(string path)
|
||||
@@ -155,7 +155,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BehaviorKnowledgeSelectorAny"/> structure.
|
||||
/// Initializes a new instance of the <see cref="BehaviorKnowledgeSelector{T}"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="other">The other selector.</param>
|
||||
public BehaviorKnowledgeSelector(BehaviorKnowledgeSelectorAny other)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
@@ -19,13 +20,9 @@ namespace FlaxEngine
|
||||
public JsonAsset Asset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the Json Asset. Null if unset.
|
||||
/// Gets the instance of the serialized object from the json asset data. Cached internally.
|
||||
/// </summary>
|
||||
/// <returns>instance of the Json Asset or null if unset.</returns>
|
||||
public T Get()
|
||||
{
|
||||
return (T)Asset?.Instance;
|
||||
}
|
||||
public T Instance => (T)Asset?.Instance;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonAssetReference{T}"/> structure.
|
||||
@@ -68,6 +65,35 @@ namespace FlaxEngine
|
||||
return new JsonAssetReference<T>(Object.FromUnmanagedPtr(valuePtr) as JsonAsset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the object exists (reference is not null and the unmanaged object pointer is valid).
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to check.</param>
|
||||
/// <returns>True if object is valid, otherwise false.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator bool(JsonAssetReference<T> obj)
|
||||
{
|
||||
return obj.Asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the two objects are equal.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(JsonAssetReference<T> left, JsonAssetReference<T> right)
|
||||
{
|
||||
return left.Asset == right.Asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the two objects are not equal.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(JsonAssetReference<T> left, JsonAssetReference<T> right)
|
||||
{
|
||||
return left.Asset != right.Asset;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
template<typename T>
|
||||
API_STRUCT(NoDefault, Template, MarshalAs=JsonAsset*) struct JsonAssetReference : AssetReference<JsonAsset>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the deserialized native object instance of the given type. Returns null if asset is not loaded or loaded object has different type.
|
||||
/// </summary>
|
||||
/// <returns>The asset instance object or null.</returns>
|
||||
FORCE_INLINE T* GetInstance() const
|
||||
{
|
||||
return _asset ? Get()->GetInstance<T>() : nullptr;
|
||||
}
|
||||
|
||||
JsonAssetReference& operator=(JsonAsset* asset) noexcept
|
||||
{
|
||||
OnSet(asset);
|
||||
|
||||
Reference in New Issue
Block a user