User avatar
aliagha.huseynli
Topic Author
Posts: 44
Joined: 29 Mar 2023, 10:17

RiveApp Trigger issue

18 Jul 2023, 08:02

Hi Noesis team members,

I have a problem with using the Rive trigger type in C#
Any idea how can I use it in C# also how can I bind it within my xaml?

By the way, I can add other types such as boolean, number(float, int)
<NoesisGUIExtensions:RiveControl Height="500" Width="500" Source="/Assets/App/TestRive/Anchor_Cannon.riv">
            
            <!--#region Boolean-->
            <NoesisGUIExtensions:RiveInput InputName="IsThrow" InputValue="{Binding IsThrow}"/>
            <NoesisGUIExtensions:RiveInput InputName="IsDown" InputValue="{Binding IsDown}"/>
            <!--#endregion-->
            
            <!--#region Number-->            
            <NoesisGUIExtensions:RiveInput InputName="AnchorReload" InputValue="{Binding AnchorReload}"/>            
            <!--#endregion-->
            
        </NoesisGUIExtensions:RiveControl>  
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: RiveApp Trigger issue

18 Jul 2023, 11:54

If you are referring to the RiveTriggerAction, it is defined as an interactivity action you can use in response to any interactivity trigger as shown in the documentation example.
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">
  <noesis:RiveControl x:Name="rive" Source="player.riv"/>
  <Button Content="{Binding PlayerName}">
    <b:Interaction.Triggers>
      <b:EventTrigger EventName="Click">
        <noesis:RiveTriggerAction TargetName="rive" TriggerName="Fire"/>
      </b:EventTrigger>
    </b:Interaction.Triggers>
  </Button>
</Grid>
If you want to trigger the action from C# you can use the DataEventTrigger and just raise an event that you will be listening from the xaml.
 
User avatar
aliagha.huseynli
Topic Author
Posts: 44
Joined: 29 Mar 2023, 10:17

Re: RiveApp Trigger issue

18 Jul 2023, 14:11

If you are referring to the RiveTriggerAction, it is defined as an interactivity action you can use in response to any interactivity trigger as shown in the documentation example.
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">
  <noesis:RiveControl x:Name="rive" Source="player.riv"/>
  <Button Content="{Binding PlayerName}">
    <b:Interaction.Triggers>
      <b:EventTrigger EventName="Click">
        <noesis:RiveTriggerAction TargetName="rive" TriggerName="Fire"/>
      </b:EventTrigger>
    </b:Interaction.Triggers>
  </Button>
</Grid>
If you want to trigger the action from C# you can use the DataEventTrigger and just raise an event that you will be listening from the xaml.
Thanks but it is outdated documentation. And with all due respect, it is horrible :)
It does not show me any path I can follow. This one as well (https://www.noesisengine.com/docs/App.R ... ntrol.html)
Do you believe that to call or reach this Rive input from .xaml to my C# code I watched a video from YouTube at 21:51 I saw the code which I want (https://youtu.be/F6Q4pfnBhbI)
It should be in the documentation not in the video ))
Anyway...
Now I need a similar version of the code example to know how can I use it.
Can you help me with this?
Thanks in advance :)
https://ibb.co/b1cj3q5

https://ibb.co/3RcRBvK
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:NoesisGUIExtensions="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions" xmlns:b="http://schemas.microsoft.com/xaml/behaviors" x:Class="Testing.TestEventTrigger"
  x:Name="Root" Width="1920" Height="1080">

    <Grid>
        <NoesisGUIExtensions:RiveControl Height="500" Width="500" Source="/Assets/App/TestEventTrigger/Shapes.riv"/>
        <NoesisGUIExtensions:RiveTriggerAction TargetName="rive" TriggerName="Fire"/>
    </Grid>

</UserControl>
using UnityEngine;
using Noesis;
using NoesisGUIExtensions;

public class TestEventTriggerViewModel : MonoBehaviour
{
	private void Start()
	{
		
	}

	private void Update()
	{
		
	}
}
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: RiveApp Trigger issue

19 Jul 2023, 18:18

it is outdated documentation
In what sense is outdated? The sample included in that document is functional.
And with all due respect, it is horrible :)
Well, there is always room for improvement. What are you missing from that class documentation? The code/data binding stuff? There is more documentation about code-behind and data binding topics in other tutorials.
It does not show me any path I can follow.
From your first message I understood you already had the bool/number inputs working. So you probably had a ViewModel exposing bool/number properties, and already notifying of changes, and the ViewModel set as DataContext of the xaml. And if your question was about the RiveTriggerAction and how to trigger it from C# the best option is to expose an event in your ViewModel and use the DataEventTrigger in xaml as I mentioned. The C# code will look like this:
public class RiveTriggerViewModel : MonoBehaviour
{
    public event EventHandler OnStar;
    private void RaiseOnStar() { OnStar?.Invoke(this, EventArgs.Empty); }

    void Start() {
        NoesisView view = GetComponent<NoesisView>();
        view.Content.DataContext = this;
    }

    void Update() {
        if (Input.GetKeyDown(KeyCode.Space))
           RaiseOnStar();
    }
}
And the xaml will look like this:
<Grid>
  <b:Interaction.Triggers>
    <NoesisGUIExtensions:DataEventTrigger Source="{Binding}" EventName="OnStar">
      <NoesisGUIExtensions:RiveTriggerAction TargetName="rive" TriggerName="OnStar"/>
    </NoesisGUIExtensions:DataEventTrigger>
  </b:Interaction.Triggers>
  <NoesisGUIExtensions:RiveControl x:Name="rive" Height="500" Width="500" Source="/Assets/App/TestEventTrigger/Shapes.riv"/>
</Grid>
Is this what you are looking for?
 
User avatar
aliagha.huseynli
Topic Author
Posts: 44
Joined: 29 Mar 2023, 10:17

Re: RiveApp Trigger issue

20 Jul 2023, 08:04

Thanks for your time. Right now it works how it should be.
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: RiveApp Trigger issue

24 Jul 2023, 12:15

Glad to be helpful :)

Who is online

Users browsing this forum: No registered users and 10 guests