Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections.Generic;
using UnityEngine;
public class ServerManager : MonoBehaviour {
private Dictionary<int, ClientData> clientList;
[SerializeField]
private GameObject clientPrefab;
// Use this for initialization
void Start () {
clientList = new Dictionary<int, ClientData>();
//ClientData型のクラスをリストに格納
for(int i = 0; i < 3; i++)
{
//クライアントデータを格納するプレハブの複製
Transform clientObject = Instantiate(clientPrefab.transform) as Transform;
ClientData clientData = clientObject.GetComponent<ClientData>();
clientData.id = i;
clientData.itemList = new List<ItemData>()
{
new ItemData { id = 0, power = 100 },
new ItemData { id = 1, power = 110 }
};
//クライアントデータをリストに格納
clientList.Add(i, clientData);
}
//格納したデータを表示
foreach (var data in clientList.Values)
{
List<ItemData> items = data.itemList;
foreach(var item in items)
{
Debug.Log(data.id + " " + item.id + " " + item.power);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.