This may look complicated but it's not as bad as it looks, let me break down the pieces it consists of.
1. The realtime Component model script (That contains a string we want to sync to all players)
2.The "sync" script that reads the model string value, updates the realtime model if you or the other player updates it and then communicates that change to the other players.
3.A FSM event script that contains the event we will send to playmaker. We will activate that FROM the sync script.
Let's get started!
We are going to create a way to send an event to a playmaker FSM to tell it when a realtime component string has changed. Normcore sends it's own events but currently I don't know how to get them to talk to playmaker FSM's.
First make the script that will be the model called SelectedResourceModel for the realtime component string. our string is called "selectedResource"
using System.Collections;
Once that is created, you can compile that model script in the right of the inspector when you select that model script.
Now when that is compiled you can create the sync script that will talk to the model to sync the realtime component string. selectedResource. The script is called SelectedResourceScript
So in this script you can see the method private void SelectedResourceDidChange
Inside this method where we can run a method in another script to send the FSM event when it detects that the realtime component did change.
Now we need to create the textmeshproUI text for this script to go onto. The script above will sync the value of the realtime string model and update the text to the value of the model. This will let both players see the same string.
So create a textmeshUI pro gameobect (if it's not UI then you will have to modify the script above for NOT UI textmeshpro)
Now drop the SelectedResourceScript.cs onto that textmeshproUI.
Now we need to create a little script that will actually send an FSM event WHEN the script we just made updates the text. Called ResourceStringUpdatedScript.cs
This will send an event to the FSM called ResourceStringUpdated. Now drop this script onto the text mesh pro game object as well.
We created a method called ResourceUpdateString
We can now RUN this method in the SelectedResourceScript when the text is updated, and it will ALSO send our FSM event upon updating.
Add a playmaker FSM to the textmeshpro object also. What you have should look kind of like this.
MAKE SURE YOU ALSO HAVE A REALTIME VIEW on that textmeshproUI as well or the realtime component WILL NOT WORK PROPERLY.
Drag the FSM into the FSM field on your ResourceStringUpdatedScript slot for MyFSM
Now all that is left is to add the Method called ResourceUpdateString from our ResourceStringUpdatedScript. To get to the method in the other script we just add this line of code.
GetComponent<ResourceStringUpdatedScript>().ResourceUpdateString();
This shows how we add it to the DidChange Method
Now in the FSM that is on that TextmeshProUI game object. You can create and event that will fire.
Add an event with the same name as the event in the script ResourceStringUpdated
That's it! Now when your realtime changes it will automatically also fire the event in your playmaker FSM!