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;
}
}