Closed lincoln310 closed 3 years ago
Thanks for your question!
I believe you may find something useful in https://github.com/UnityTech/ConnectAppCN/blob/master/Assets/ConnectApp/Utils/WebSocket/WebSocketHost.cs and its relevant classes, which will show you how to integrate a web socket plugin into a uiwidgets App.
这个是UIWidgets的state类 在UIPanel类上实例化
`
using RSG;
using System;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;
public class TestState : StatefulWidget
{
public override State createState()
{
return new TestStateState();
}
}
class TestStateState : State
这个类挂载到物体上 负责执行回调
using System;
using UnityEngine;
public class TestMessage : MonoBehaviour { public static TestMessage instance; public Action callBack; // Start is called before the first frame update void Start() { instance = this; }
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
callBack?.Invoke();
}
}
}
` 每次按A键 State类就会同步刷新 不知道能不能帮到你
多谢,我用@ssssssilver的方式处理的。在state中记录了两个时间,一个msg更新时间,一个update处理时间,然后再update中检查两个时间,来触发action,更新界面。
hi, 我用uiwidgets制作了一个界面,用来对接mqtt服务和数据的。 我用了M2MqttUnity这个包,然后重新封装了一个类,把unity的MonoBehavior去掉了(主要是不知道怎么结合uiwidgets和这种MonoBehavior)。
目前的效果是:能正常的连接到服务器,能订阅topic,也能收到数据。但是不能实时的更新界面。
我对unity和界面都是新手,看了ConnectAppCN的代码,也没找到合适的内容。能否提供一些帮助?谢谢!
code:
stack: