-
Im try get react value from c# but i don't know how it really works, because docs don't explain very well. using ReactUnity.UIToolkit;
using UnityEngine;
public class TestReactUnity : MonoBehaviour
{
public ReactRendererUIToolkit react;
public uint delay = 3;
private uint _count = 0;
private float _timer;
private void Start()
{
react.Globals.AddListener((e) =>
{
string listener = $"len({e.Count})";
foreach (var i in e)
{
dynamic r = i.Value;
listener += $"\n{i.Key} -> {r}";
}
print($"listener event: {listener}");
print(react.Globals["reactside"]);
});
}
private void Update()
{
_timer += Time.deltaTime;
if (_timer > Mathf.Clamp(delay, 1, 100))
{
_timer = 0;
_count++;
// add only.
// react.Globals.Add("csharpside", $"C# counter {_count}");
// add or update
react.Globals.Set("csharpside", $"C# counter {_count}");
}
}
} const globals = useGlobals()
return (<>
<h1 style={{ color: 'white' }}>Ola Mundo, C#: {globals.csharpside}</h1>
<h1 style={{ color: 'white' }}>Ola Mundo, JS: {globals.reactside}</h1>
<button onClick={() => { Globals.reactside++; }}>
Increase ReactSide
</button>
</>)
} How can i access |
Beta Was this translation helpful? Give feedback.
Answered by
alec1o
Dec 4, 2023
Replies: 1 comment
Answer selected by
alec1o
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#103 (comment)