Created
September 26, 2017 16:07
-
-
Save Collonville/ea760f2ddb78f13ec12acc14b2a79747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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