Chat 5.5 synclist Stuck
I've been beating my head against the proverbial wall on this. I'm using the steps from the skimpy tutorial in that I have a networkmanager, and my players have networkidentity and networktransform. I don't know what is happening here, but my syncliststring does't appear to send changes to any client other than the one who sends the message. What am I missing???
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class ChatController : NetworkBehaviour
{
public Text textPrefab;
public RectTransform contents;
public float originalHeight;
public SyncListString chatLog = new SyncListString();
void Start() { chatLog.Callback += OnLogChange; }
// public override void OnStartLocalPlayer() {
// base.OnStartLocalPlayer();
// Debug.Log(GetPlayerName() + " Local player started");
// Debug.Log(chatLog);
// chatLog.Callback += OnLogChange;
// }
private void OnLogChange(SyncList<string>.Operation op, int itemIndex) {
Text t = Instantiate<Text>(textPrefab, contents.transform);
t.text = ": " + chatLog[itemIndex];
//Debug.LogFormat("LogChange: local={0}, text='{1}', player={2} chatLog size={3}", isLocalPlayer, t.text, GetPlayerName(), chatLog.Count);
switch (op) {
case SyncList<string>.Operation.OP_ADD:
// Debug.Log("?????");
break;
case SyncList<string>.Operation.OP_CLEAR:
break;
case SyncList<string>.Operation.OP_DIRTY:
break;
case SyncList<string>.Operation.OP_INSERT:
break;
case SyncList<string>.Operation.OP_REMOVE:
break;
case SyncList<string>.Operation.OP_REMOVEAT:
break;
case SyncList<string>.Operation.OP_SET:
break;
}
}
public void Workabout(string text) {
CmdSendMsg(GetPlayerName() + ": " + text);
}
[Command]
public void CmdSendMsg(string text) {
//Debug.LogFormat("isServer({1} Connections({0}) " , NetworkServer.connections.Count, isServer);
chatLog.Add(text);
}
string GetPlayerName() {
return GetComponentInParent<MR_PlayerController>().playerName;
}
}
If I setup my callback in OnStartClient ins$$anonymous$$d of the other options I do see my debug statement (the one that is commented out above at line 32) on both clients. The original sending client updates fine, but the other client is not local so it never puts the text to the screen.
Unet seems so incredibly brittle I'm debating on dumping it completely. Since I started using it I haven't been able to work on my actual game at all, it is all just frustrating unet issues. It acts like a cheap 3rd party plugin with zero documentation.
Answer by AmbroseFurback · Feb 15, 2017 at 02:44 PM
In case anyone is interested, I solved this by eliminating the synclist and just sending manually:
public class ChatController : NetworkBehaviour
{
public Text textPrefab;
public RectTransform contents;
public float originalHeight;
public override void OnStartLocalPlayer() {
base.OnStartLocalPlayer();
MR_NetworkManager.Instance.client.RegisterHandler(MR_MessageTypes.CHAT_MESSAGE, OnChat);
}
void OnChat(NetworkMessage msg) {
ChatMessage m = msg.ReadMessage<ChatMessage>();
Instantiate<Text>(textPrefab, contents.transform).text = m.ToString();
}
public void Workabout(string text) {
CmdSendMsg(text);
}
[Command]
public void CmdSendMsg(string text) {
ChatMessage msg = new ChatMessage(GetPlayerName(), text);
NetworkServer.SendUnreliableToAll(MR_MessageTypes.CHAT_MESSAGE, msg);
}
string GetPlayerName() {
return GetComponentInParent<MR_PlayerController>().playerName;
}
}
public class ChatMessage : MessageBase
{
public string fromPlayer;
public string messageText;
public ChatMessage() : base() { }
public ChatMessage(string from, string text) : base() {
fromPlayer = from;
messageText = text;
}
public override string ToString() {
if (fromPlayer == null) {
return "<color=yellow>System: " + messageText + "</color>";
}
return fromPlayer + ": " + messageText;
}
}
I guess synclist isn't ready for prime time.
Decided on using LLAPI NetworkTransport ins$$anonymous$$d. Until Unity creates documentation for the HLAPI it isn't worth the hassle.
One note that might help, I discovered that the NetworkTransport doesn't operate correctly if the client or server runs in the editor. I couldn't get it to work until I build the app and ran two instances outside the editor. Very annoying.