Fix issues with multiplayer button
This commit is contained in:
1 file changed
+9
@@ -242,9 +242,17 @@ public class PlayModePrefab : MonoBehaviour {
|
|||||||
nothingBerryChance.onSelect.AddListener((value) => OnSelect(value, nothingBerryChance));
|
nothingBerryChance.onSelect.AddListener((value) => OnSelect(value, nothingBerryChance));
|
||||||
nothingBerryChance.onDeselect.AddListener((value) => OnDeselect(value, nothingBerryChance));
|
nothingBerryChance.onDeselect.AddListener((value) => OnDeselect(value, nothingBerryChance));
|
||||||
|
|
||||||
|
WebsocketHandler.Instance._Connection.StateChanged += OnStateChanged;
|
||||||
WebsocketHandler.Instance._Connection.MessageReceived += OnMessageReceived;
|
WebsocketHandler.Instance._Connection.MessageReceived += OnMessageReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnStateChanged(WebSocketConnection connection, WebSocketState oldState, WebSocketState newState) {
|
||||||
|
multiplayerButton.gameObject.SetActive(newState == WebSocketState.Connected);
|
||||||
|
var pos = autoButton.transform.localPosition;
|
||||||
|
pos.x = newState == WebSocketState.Connected ? 155 : 0;
|
||||||
|
autoButton.transform.localPosition = pos;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnMessageReceived(WebSocketConnection connection, WebSocketMessage message) {
|
private void OnMessageReceived(WebSocketConnection connection, WebSocketMessage message) {
|
||||||
if (message.String != null && connection.State == WebSocketState.Connected) {
|
if (message.String != null && connection.State == WebSocketState.Connected) {
|
||||||
JToken data = JToken.Parse(message.String);
|
JToken data = JToken.Parse(message.String);
|
||||||
@@ -297,6 +305,7 @@ public class PlayModePrefab : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnDestroy() {
|
void OnDestroy() {
|
||||||
|
WebsocketHandler.Instance._Connection.StateChanged -= OnStateChanged;
|
||||||
WebsocketHandler.Instance._Connection.MessageReceived -= OnMessageReceived;
|
WebsocketHandler.Instance._Connection.MessageReceived -= OnMessageReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user