Skip to content

Instantly share code, notes, and snippets.

@Collonville
Created September 26, 2017 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Collonville/ea760f2ddb78f13ec12acc14b2a79747 to your computer and use it in GitHub Desktop.
Save Collonville/ea760f2ddb78f13ec12acc14b2a79747 to your computer and use it in GitHub Desktop.
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