Skip to content

ValueReference<T> Class

Allows you to reference a ScriptableValue<T> or a constant value.

C#
[Serializable]
public class ValueReference<T>

T
The type that the value should be.

Inheritance object

Creates a new ValueReference<T> of type Reference.

C#
public ValueReference()

Creates a new ValueReference<T> of type Constant with the given constant value.

C#
public ValueReference(T constantValue)

constantValue T
The constant value.

Creates a new ValueReference<T> of type Reference with the given reference value.

C#
public ValueReference(ScriptableValue<T> referenceValue)

referenceValue ScriptableValue<T>
The reference value.

ValueReference(AssetReferenceT<ScriptableValue>)

Section titled “ValueReference(AssetReferenceT<ScriptableValue>)”

Creates a new ValueReference<T> of type Addressable with the given addressable reference.

C#
public ValueReference(AssetReferenceT<ScriptableValue<T>> addressableReference)

addressableReference AssetReferenceT<ScriptableValue<T>>
The addressable reference.

Get or set the current value. This can be changed at runtime.

C#
public T Value { get; set; }

If ValueType is set to Constant, this will set the constant value. If ValueType is set to Reference, this will set the value of the referenced ScriptableValue<T>. If ValueType is set to Addressable, this will set the value of the referenced ScriptableValue<T> if it is loaded.

Get the type of value reference.

C#
public ValueReferenceType ValueType { get; }

Checks if the value is an addressable value.

C#
public bool IsAddressable { get; }

This will always return false if the addressables package isn’t installed.

Checks if the addressable asset is loaded.

C#
public bool IsAddressableLoaded { get; }

This will always return true if the addressables package isn’t installed.

The handle to the loaded addressable asset.

C#
public AsyncOperationHandle<ScriptableValue<T>> AssetHandle { get; }

This will be a default UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle1ifHertzole.ScriptableValues.ValueReference1.LoadAddressableAssetAsync(System.Action%7bUnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle%7bHertzole.ScriptableValues.ScriptableValue%7b0%7d%7d%7d)` hasn’t been called yet.

Sets the current value without invoking the OnValueChanging and OnValueChanged events.

C#
public void SetValueWithoutNotify(T value)

value T

LoadAddressableAssetAsync(Action<AsyncOperationHandle<ScriptableValue>>?)

Section titled “LoadAddressableAssetAsync(Action<AsyncOperationHandle<ScriptableValue>>?)”

Loads the addressable asset asynchronously.

C#
public AsyncOperationHandle<ScriptableValue<T>> LoadAddressableAssetAsync(Action<AsyncOperationHandle<ScriptableValue<T>>>? onLoaded = null)

onLoaded Action<AsyncOperationHandle<ScriptableValue<T>>>
Optional callback that is called when the asset is loaded.

AsyncOperationHandle<ScriptableValue<T>>
The handle to the loaded addressable asset.

NotSupportedException
ValueType is not Addressable.

Releases the addressable asset.

C#
public void ReleaseAddressableAsset()

Called before the current value is set.

C#
public event ValueEventHandler<T> OnValueChanging

ValueEventHandler<T>

Called after the current value is set.

C#
public event ValueEventHandler<T> OnValueChanged

ValueEventHandler<T>