Alright so I’m having a bit of an issue with SyncListStructs here, I’ve googled like crazy watched different networking videos, read through the network documentation and I feel stumped.
ServerHandler is attached to its own GameObject, not attached to the player.
WorldHandler is where I add TileStructs to the TileStructList.
I know my IsServer else is missing a call but I just can’t honestly figure out what. I believe I should send an update from the server to all clients about the contents of its TileStructList but i genuinely have no idea how to do that.
What I want to accomplish
I want all players to get the same exact TileStructList that the host client has.
Is this beyond UNET or am I just totally missing something?
using UnityEngine;
using UnityEngine.Networking;
public class ServerHandler : NetworkBehaviour
{
public class SyncListTile : SyncListStruct<TileStruct> { }
public SyncListTile TileStructList = new SyncListTile();
public GameObject WorldHandlerPrefab;
public override void OnStartServer()
{
base.OnStartServer();
}
public override void OnStartClient()
{
base.OnStartClient();
GameObject worldGo = GameObject.Instantiate(WorldHandlerPrefab) as GameObject;
if (isServer)
{
worldGo.GetComponent<WorldHandler>().CreateEmptyWorld(this);
TileStructList.Callback = OnTileChanged;
}
else
{
}
}
public void OnTileChanged(SyncList<TileStruct>.Operation op, int index)
{
Debug.Log("INDEX: " + index);
}
}
Here is my TileStruct class. It’s in its own TileStruct.cs file.
[Serializable]
public enum TileType { Empty, Ground, FarmPlot, WoodPlot };
[System.Serializable]
public struct TileStruct
{
public int X;
public int Y;
public TileType Type;
public TileStruct(int x, int y, TileType type)
{
X = x;
Y = y;
Type = type;
}
}