This commit is contained in:
2026-05-19 17:39:03 +07:00
parent bf0ebe447d
commit 5da832bb57
559 changed files with 69543 additions and 1 deletions

View File

@@ -0,0 +1,85 @@
using System;
using System.Runtime.InteropServices;
using Rive.Utils;
namespace Rive
{
/// <summary>
/// A view model instance property for artboard properties.
/// </summary>
public sealed class ViewModelInstanceArtboardProperty : ViewModelInstancePrimitiveProperty
{
public ViewModelInstanceArtboardProperty(IntPtr instanceValuePtr, ViewModelInstance instance) : base(instanceValuePtr, instance)
{
}
/// <summary>
/// Sets the artboard value for this property.
/// </summary>
public BindableArtboard Value
{
set
{
ThrowIfOwnerDisposed();
SetArtboardInternal(value);
}
}
/// <summary>
/// Raised when the artboard property is changed in the Rive graphic.
/// </summary>
public event Action OnValueChanged
{
add => AddPropertyCallback(value, ref m_onValueChanged);
remove => RemovePropertyCallback(value, ref m_onValueChanged);
}
private Action m_onValueChanged;
/// <summary>
/// Sets the artboard for the property.
/// </summary>
private void SetArtboardInternal(BindableArtboard artboard)
{
if (artboard != null && artboard.NativeBindableArtboard == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to assign an invalid artboard.");
return;
}
bool wasSuccess = setViewModelInstanceArtboardValue(
InstancePropertyPtr,
artboard?.NativeBindableArtboard ?? IntPtr.Zero,
artboard?.ViewModelInstanceHandle ?? ViewModelInstanceSafeHandle.Null);
if (!wasSuccess)
{
DebugLogger.Instance.LogError("Failed to set artboard.");
}
}
internal override void RaiseChangedEvent()
{
m_onValueChanged?.Invoke();
}
internal override void ClearAllCallbacks()
{
m_onValueChanged = null;
base.ClearAllCallbacks();
}
internal override void ClearDelegatesOnly()
{
m_onValueChanged = null;
}
[DllImport(NativeLibrary.name)]
private static extern bool setViewModelInstanceArtboardValue(
IntPtr instanceProperty,
IntPtr artboard,
ViewModelInstanceSafeHandle viewModelInstance);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b64163b892710430ca18cb732dee8721
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceArtboardProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,39 @@
using System;
using System.Runtime.InteropServices;
namespace Rive
{
/// <summary>
/// A view model instance property that holds a boolean.
/// </summary>
public sealed class ViewModelInstanceBooleanProperty : ViewModelInstancePrimitiveProperty<bool>
{
internal ViewModelInstanceBooleanProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance) : base(instanceValuePtr, rootInstance)
{
}
/// <summary>
/// The value of the property.
/// </summary>
public override bool Value
{
get
{
ThrowIfOwnerDisposed();
return getViewModelInstanceBooleanValue(InstancePropertyPtr);
}
set
{
ThrowIfOwnerDisposed();
setViewModelInstanceBooleanValue(InstancePropertyPtr, value);
}
}
[DllImport(NativeLibrary.name)]
private static extern bool getViewModelInstanceBooleanValue(IntPtr instanceProperty);
[DllImport(NativeLibrary.name)]
private static extern void setViewModelInstanceBooleanValue(IntPtr instanceProperty, bool value);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: dcd5e9d7761f24131b540f069e42d80f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceBooleanProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,93 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace Rive
{
/// <summary>
/// A view model instance property that holds a color.
/// </summary>
public sealed class ViewModelInstanceColorProperty : ViewModelInstancePrimitiveProperty<UnityEngine.Color>
{
internal ViewModelInstanceColorProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance) : base(instanceValuePtr, rootInstance)
{
}
private static int ColorToArgb(UnityEngine.Color color)
{
return (Mathf.RoundToInt(color.a * 255) << 24) |
(Mathf.RoundToInt(color.r * 255) << 16) |
(Mathf.RoundToInt(color.g * 255) << 8) |
Mathf.RoundToInt(color.b * 255);
}
private static int Color32ToArgb(Color32 color)
{
return (color.a << 24) |
(color.r << 16) |
(color.g << 8) |
color.b;
}
private static UnityEngine.Color ArgbToColor(int argb)
{
return new UnityEngine.Color(
((argb >> 16) & 0xFF) / 255f, // R (from ARGB)
((argb >> 8) & 0xFF) / 255f, // G (from ARGB)
(argb & 0xFF) / 255f, // B (from ARGB)
((argb >> 24) & 0xFF) / 255f // A (from ARGB)
);
}
private static Color32 ArgbToColor32(int argb)
{
return new Color32(
(byte)((argb >> 16) & 0xFF), // R (from ARGB)
(byte)((argb >> 8) & 0xFF), // G (from ARGB)
(byte)(argb & 0xFF), // B (from ARGB)
(byte)((argb >> 24) & 0xFF) // A (from ARGB)
);
}
/// <summary>
/// Gets or sets the color value as a Unity Color.
/// </summary>
public override UnityEngine.Color Value
{
get
{
ThrowIfOwnerDisposed();
return ArgbToColor(getViewModelInstanceColorValue(InstancePropertyPtr));
}
set
{
ThrowIfOwnerDisposed();
setViewModelInstanceColorValue(InstancePropertyPtr, ColorToArgb(value));
}
}
/// <summary>
/// Gets or sets the color value as a Color32
/// </summary>
public Color32 Value32
{
get
{
ThrowIfOwnerDisposed();
return ArgbToColor32(getViewModelInstanceColorValue(InstancePropertyPtr));
}
set
{
ThrowIfOwnerDisposed();
setViewModelInstanceColorValue(InstancePropertyPtr, Color32ToArgb(value));
}
}
[DllImport(NativeLibrary.name)]
private static extern int getViewModelInstanceColorValue(IntPtr instanceProperty);
[DllImport(NativeLibrary.name)]
private static extern void setViewModelInstanceColorValue(IntPtr instanceProperty, int value);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 7bdf3f20b1174474299449e497069b00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceColorProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,163 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Rive.Utils;
namespace Rive
{
/// <summary>
/// A view model instance property that holds an enum.
/// </summary>
public sealed class ViewModelInstanceEnumProperty : ViewModelInstancePrimitiveProperty<string>
{
private string[] m_enumValues;
/// <summary>
/// Constructor for the enum property. This is used when the enum values are known ahead of time.
/// </summary>
/// <param name="instanceValuePtr"> The pointer to the instance property. </param>
/// <param name="rootInstance"> The root instance of the view model. </param>
/// <param name="enumValues"> The list of enum values. </param>
internal ViewModelInstanceEnumProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance, string[] enumValues) : base(instanceValuePtr, rootInstance)
{
m_enumValues = enumValues;
}
/// <summary>
/// Constructor for the enum property. This is used when the enum values are not known ahead of time.
/// </summary>
/// <param name="instanceValuePtr"> The pointer to the instance property. </param>
/// <param name="rootInstance"> The root instance of the view model. </param>
internal ViewModelInstanceEnumProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance) : base(instanceValuePtr, rootInstance)
{
PopulateEnumValuesIfNeeded();
}
/// <summary>
/// The current enum value of the property.
/// </summary>
public override string Value
{
get
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogWarning("Trying to get a null enum property.");
return null;
}
if (m_enumValues.Length == 0)
{
return null;
}
return m_enumValues[(int)getViewModelInstanceEnumIndex(InstancePropertyPtr)];
}
set
{
ThrowIfOwnerDisposed();
int index = Array.IndexOf(m_enumValues, value);
if (index == -1)
{
DebugLogger.Instance.LogWarning("Invalid enum value: " + value);
return;
}
if (index < 0)
{
DebugLogger.Instance.LogWarning("Trying to set a negative enum value.");
return;
}
setViewModelInstanceEnumIndex(InstancePropertyPtr, (uint)index);
}
}
/// <summary>
/// The current enum value index of the property in the enum values list.
/// </summary>
internal int ValueIndex
{
get
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogWarning("Trying to get a null enum property.");
return -1;
}
return (int)getViewModelInstanceEnumIndex(InstancePropertyPtr);
}
set
{
ThrowIfOwnerDisposed();
if (value < 0 || value >= m_enumValues.Length)
{
DebugLogger.Instance.LogWarning("Invalid enum value index: " + value);
return;
}
setViewModelInstanceEnumIndex(InstancePropertyPtr, (uint)value);
}
}
private void PopulateEnumValuesIfNeeded()
{
if (m_enumValues == null)
{
IntPtr m_enumValuesPtr = getViewModelInstanceEnumValues(InstancePropertyPtr);
nuint valueCount = getViewModelInstanceEnumValueCount(m_enumValuesPtr);
m_enumValues = new string[(int)valueCount];
for (nuint i = 0; i < valueCount; i++)
{
m_enumValues[i] = Marshal.PtrToStringAnsi(getViewModelInstanceEnumValueAtIndex(m_enumValuesPtr, i));
}
freeViewModelInstanceEnumValues(m_enumValuesPtr);
}
}
/// <summary>
/// The list of enum options for this property.
/// </summary>
public IReadOnlyList<string> EnumValues
{
get
{
if (m_enumValues == null)
{
PopulateEnumValuesIfNeeded();
}
return m_enumValues;
}
}
[DllImport(NativeLibrary.name)]
private static extern uint getViewModelInstanceEnumIndex(IntPtr instanceProperty);
[DllImport(NativeLibrary.name)]
private static extern void setViewModelInstanceEnumIndex(IntPtr instanceProperty, uint value);
[DllImport(NativeLibrary.name)]
private static extern IntPtr getViewModelInstanceEnumValues(IntPtr instanceProperty);
[DllImport(NativeLibrary.name)]
private static extern nuint getViewModelInstanceEnumValueCount(IntPtr listPtr);
[DllImport(NativeLibrary.name)]
private static extern IntPtr getViewModelInstanceEnumValueAtIndex(IntPtr listPtr, nuint index);
[DllImport(NativeLibrary.name)]
private static extern void freeViewModelInstanceEnumValues(IntPtr listPtr);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8d4dd5b4ee8df436ebc24fa8c0b56d49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceEnumProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,83 @@
using System;
using System.Runtime.InteropServices;
using Rive.Utils;
namespace Rive
{
/// <summary>
/// A view model instance property for image properties.
/// </summary>
public sealed class ViewModelInstanceImageProperty : ViewModelInstancePrimitiveProperty
{
public ViewModelInstanceImageProperty(IntPtr instanceValuePtr, ViewModelInstance instance) : base(instanceValuePtr, instance)
{
}
/// <summary>
/// Sets the image asset for the property.
/// </summary>
/// <param name="imageAsset"> The image asset to set. </param>
public ImageOutOfBandAsset Value
{
set
{
ThrowIfOwnerDisposed();
SetImage(value);
}
}
/// <summary>
/// Raised when the image property is changed in the Rive graphic.
/// </summary>
public event Action OnValueChanged
{
add => AddPropertyCallback(value, ref m_onValueChanged);
remove => RemovePropertyCallback(value, ref m_onValueChanged);
}
private Action m_onValueChanged;
/// <summary>
/// Sets the image asset for the property.
/// </summary>
/// <param name="imageAsset"> The image asset to set. </param>
private void SetImage(ImageOutOfBandAsset imageAsset)
{
if (imageAsset != null && imageAsset.NativeAsset == IntPtr.Zero)
{
DebugLogger.Instance.LogWarning("Trying to assign an unloaded image asset.");
return;
}
bool wasSuccess = setViewModelInstanceImageValue(InstancePropertyPtr, imageAsset == null ? IntPtr.Zero : imageAsset.NativeAsset);
if (!wasSuccess)
{
DebugLogger.Instance.LogWarning("Failed to set image asset.");
}
}
internal override void RaiseChangedEvent()
{
m_onValueChanged?.Invoke();
}
internal override void ClearAllCallbacks()
{
m_onValueChanged = null;
base.ClearAllCallbacks();
}
internal override void ClearDelegatesOnly()
{
m_onValueChanged = null;
}
[DllImport(NativeLibrary.name)]
private static extern bool setViewModelInstanceImageValue(IntPtr instanceProperty,
IntPtr imageAsset);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 23f3f5571d2ec47dfaefa91d59d07cde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceImageProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,297 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Rive.Utils;
namespace Rive
{
/// <summary>
/// A view model instance property that holds a list of view model instances.
/// </summary>
public sealed class ViewModelInstanceListProperty : ViewModelInstancePrimitiveProperty
{
internal ViewModelInstanceListProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance)
: base(instanceValuePtr, rootInstance)
{
}
/// <summary>
/// The number of items in the list.
/// </summary>
public int Count
{
get
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogWarning("Trying to get length of a null list property.");
return 0;
}
return (int)getViewModelInstanceListSize(InstancePropertyPtr);
}
}
/// <summary>
/// Gets the view model instance at the specified index.
/// </summary>
/// <param name="index">The index of the item to get.</param>
/// <returns>The view model instance at the specified index, or null if the index is out of bounds.</returns>
public ViewModelInstance GetInstanceAt(int index)
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to get item from a null list property.");
return null;
}
if (index < 0 || index >= Count)
{
DebugLogger.Instance.LogError($"Index {index} is out of bounds for list of length {Count}.");
return null;
}
IntPtr instancePtr = getViewModelInstanceListItemAt(InstancePropertyPtr, index);
if (instancePtr == IntPtr.Zero)
{
return null;
}
ViewModelInstance vmi = GetOrCreateVMInstanceFromPtr(instancePtr);
return vmi;
}
private ViewModelInstance GetOrCreateVMInstanceFromPtr(IntPtr instancePtr)
{
if (instancePtr == IntPtr.Zero)
{
return null;
}
return ViewModelInstance.GetOrCreateFromPointer(instancePtr, this.RootInstance?.RiveFile, this.RootInstance);
}
/// <summary>
/// Adds a view model instance to the end of the list.
/// </summary>
/// <param name="instance">The view model instance to add.</param>
public void Add(ViewModelInstance instance)
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to add to a null list property.");
return;
}
if (instance == null || instance.NativeSafeHandle.IsInvalid)
{
DebugLogger.Instance.LogError("Cannot add null or invalid view model instance to list.");
return;
}
addViewModelInstanceToList(InstancePropertyPtr, instance.NativeSafeHandle.DangerousGetHandle());
instance.AddParent(this.RootInstance);
}
/// <summary>
/// Inserts a view model instance at the specified index.
/// </summary>
/// <param name="instance">The view model instance to insert.</param>
/// <param name="index">The index at which to insert the instance.</param>
public void Insert(ViewModelInstance instance, int index)
{
ThrowIfOwnerDisposed();
if (instance == null)
{
DebugLogger.Instance.LogError("Cannot insert null or invalid view model instance into list.");
return;
}
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to insert into a null list property.");
return;
}
if (index < 0)
{
DebugLogger.Instance.LogError($"Index {index} is out of bounds for list of length {Count}.");
return;
}
if (!addViewModelInstanceToListAt(InstancePropertyPtr, instance.NativeSafeHandle.DangerousGetHandle(), index))
{
DebugLogger.Instance.LogError($"Failed to insert view model instance at index {index}.");
return;
}
instance.AddParent(this.RootInstance);
}
/// <summary>
/// Removes a view model instance from the list.
/// </summary>
/// <param name="instance">The view model instance to remove.</param>
/// <remarks>
/// This method will remove every occurrence of the instance from the list.
/// </remarks>
public void Remove(ViewModelInstance instance)
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to remove from a null list property.");
return;
}
if (instance == null || instance.NativeSafeHandle.IsInvalid)
{
DebugLogger.Instance.LogError("Cannot remove null or invalid view model instance from list.");
return;
}
removeViewModelInstanceFromList(InstancePropertyPtr, instance.NativeSafeHandle.DangerousGetHandle());
instance.RemoveParent(this.RootInstance);
}
/// <summary>
/// Removes the view model instance at the specified index.
/// </summary>
/// <param name="index">The index of the item to remove.</param>
public void RemoveAt(int index)
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to remove from a null list property.");
return;
}
if (index < 0 || index >= Count)
{
DebugLogger.Instance.LogError($"Index {index} is out of bounds for list of length {Count}.");
return;
}
ViewModelInstance instance = GetInstanceAt(index);
if (instance == null)
{
DebugLogger.Instance.LogError($"No instance found at index {index}.");
return;
}
removeViewModelInstanceFromListAt(InstancePropertyPtr, index);
}
/// <summary>
/// Swaps the view model instances at the specified indices.
/// </summary>
/// <param name="indexA">The index of the first item to swap.</param>
/// <param name="indexB">The index of the second item to swap.</param>
public void Swap(int indexA, int indexB)
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogError("Trying to swap instances in a null list property.");
return;
}
if (indexA == indexB)
{
DebugLogger.Instance.LogError("Cannot swap instances at the same index.");
return;
}
if (indexA < 0 || indexA >= Count)
{
DebugLogger.Instance.LogError($"Index {indexA} is out of bounds for list of length {Count}.");
return;
}
if (indexB < 0 || indexB >= Count)
{
DebugLogger.Instance.LogError($"Index {indexB} is out of bounds for list of length {Count}.");
return;
}
swapViewModelInstancesInList(InstancePropertyPtr, indexA, indexB);
}
/// <summary>
/// Called when the list property value changes.
/// </summary>
internal override void RaiseChangedEvent()
{
// List changes don't have a specific value, just notify that the list changed
m_onTriggered?.Invoke();
}
/// <summary>
/// Event that is raised when the list changes.
/// </summary>
public event Action OnChanged
{
add => AddPropertyCallback(value, ref m_onTriggered);
remove => RemovePropertyCallback(value, ref m_onTriggered);
}
private Action m_onTriggered;
/// <summary>
/// Clears all callbacks registered with this property.
/// </summary>
internal override void ClearAllCallbacks()
{
m_onTriggered = null;
base.ClearAllCallbacks();
}
internal override void ClearDelegatesOnly()
{
m_onTriggered = null;
}
[DllImport(NativeLibrary.name)]
private static extern nuint getViewModelInstanceListSize(IntPtr listProperty);
[DllImport(NativeLibrary.name)]
private static extern IntPtr getViewModelInstanceListItemAt(IntPtr listProperty, int index);
[DllImport(NativeLibrary.name)]
private static extern void addViewModelInstanceToList(IntPtr listProperty, IntPtr instance);
[DllImport(NativeLibrary.name)]
private static extern bool addViewModelInstanceToListAt(IntPtr listProperty, IntPtr instance, int index);
[DllImport(NativeLibrary.name)]
private static extern void removeViewModelInstanceFromList(IntPtr listProperty, IntPtr instance);
[DllImport(NativeLibrary.name)]
private static extern void removeViewModelInstanceFromListAt(IntPtr listProperty, int index);
[DllImport(NativeLibrary.name)]
private static extern void swapViewModelInstancesInList(IntPtr listProperty, int indexA, int indexB);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 09fb2d52775024f32a84dee326a45e35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceListProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,38 @@
using System;
using System.Runtime.InteropServices;
namespace Rive
{
/// <summary>
/// A view model instance property that holds a number.
/// </summary>
public sealed class ViewModelInstanceNumberProperty : ViewModelInstancePrimitiveProperty<float>
{
internal ViewModelInstanceNumberProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance) : base(instanceValuePtr, rootInstance)
{
}
/// <summary>
/// The value of the property.
/// </summary>
public override float Value
{
get
{
ThrowIfOwnerDisposed();
return getViewModelInstanceNumberValue(InstancePropertyPtr);
}
set
{
ThrowIfOwnerDisposed();
setViewModelInstanceNumberValue(InstancePropertyPtr, value);
}
}
[DllImport(NativeLibrary.name)]
private static extern float getViewModelInstanceNumberValue(IntPtr instanceProperty);
[DllImport(NativeLibrary.name)]
private static extern void setViewModelInstanceNumberValue(IntPtr instanceProperty, float value);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2f10803c1a29a410ebcfb1731ef0cabc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceNumberProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,64 @@
using System;
using System.Runtime.InteropServices;
namespace Rive
{
/// <summary>
/// A view model instance property that holds a string.
/// </summary>
public sealed class ViewModelInstanceStringProperty : ViewModelInstancePrimitiveProperty<string>
{
[StructLayout(LayoutKind.Sequential)]
private struct StringHashInfo
{
public IntPtr str;
public uint length;
public uint hash;
}
private StringHashInfo m_lastInfo;
private string m_stringVal = null;
internal ViewModelInstanceStringProperty(IntPtr instanceValuePtr, ViewModelInstance parentInstance) : base(instanceValuePtr, parentInstance)
{
}
public override string Value
{
get
{
ThrowIfOwnerDisposed();
StringHashInfo currentInfo = getViewModelInstanceStringInfo(InstancePropertyPtr);
// We check if either length or hash changed before marshalling the string
// This is a performance optimization to avoid marshalling the string every frame if it hasn't changed as it allocates memory every time the value is read
// This allocation can be expensive and might cause GC spikes if done frequently
// TODO: Since the VM Instance Runtime knows when the string changes, we should switch to using that instead instead of a hash at some point
bool stringHasChanged = currentInfo.length != m_lastInfo.length || currentInfo.hash != m_lastInfo.hash;
if (m_stringVal == null || stringHasChanged)
{
m_lastInfo = currentInfo;
m_stringVal = Marshal.PtrToStringAnsi(currentInfo.str);
}
return m_stringVal;
}
set
{
ThrowIfOwnerDisposed();
setViewModelInstanceStringValue(InstancePropertyPtr, value);
}
}
[DllImport(NativeLibrary.name)]
private static extern IntPtr getViewModelInstanceStringValue(IntPtr instanceValue);
[DllImport(NativeLibrary.name)]
private static extern void setViewModelInstanceStringValue(IntPtr instanceValue, string value);
[DllImport(NativeLibrary.name)]
private static extern StringHashInfo getViewModelInstanceStringInfo(IntPtr instanceValue);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ca5f8fb25618247ff9b6588c9d075a95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceStringProperty.cs
uploadId: 896810

View File

@@ -0,0 +1,61 @@
using System;
using System.Runtime.InteropServices;
using Rive.Utils;
namespace Rive
{
/// <summary>
/// A view model instance property for trigger properties.
/// </summary>
public sealed class ViewModelInstanceTriggerProperty : ViewModelInstancePrimitiveProperty
{
internal ViewModelInstanceTriggerProperty(IntPtr instanceValuePtr, ViewModelInstance rootInstance) : base(instanceValuePtr, rootInstance)
{
}
/// <summary>
/// Raised when the trigger property is fired in the Rive graphic.
/// </summary>
public event Action OnTriggered
{
add => AddPropertyCallback(value, ref m_onTriggered);
remove => RemovePropertyCallback(value, ref m_onTriggered);
}
private Action m_onTriggered;
/// <summary>
/// Fires the trigger
/// </summary>
public void Trigger()
{
ThrowIfOwnerDisposed();
if (InstancePropertyPtr == IntPtr.Zero)
{
DebugLogger.Instance.LogWarning("Trying to trigger a null trigger property.");
return;
}
fireViewModelInstanceTrigger(InstancePropertyPtr);
}
[DllImport(NativeLibrary.name)]
private static extern void fireViewModelInstanceTrigger(IntPtr instanceProperty);
internal override void RaiseChangedEvent()
{
m_onTriggered?.Invoke();
}
internal override void ClearAllCallbacks()
{
m_onTriggered = null;
base.ClearAllCallbacks();
}
internal override void ClearDelegatesOnly()
{
m_onTriggered = null;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 0243f34ec09e64cd5904a8e4c5c01bdc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 350858
packageName: Rive
packageVersion: 0.4.2
assetPath: Packages/app.rive.rive-unity/Runtime/DataBinding/Values/ViewModelInstanceTriggerProperty.cs
uploadId: 896810