Mercurial > hg > Members > kazuma > JungleforUnity
diff Assets/Application/Scripts/StageManager.cs @ 4:2878be4487ec
add Maping Code.
author | Kazuma |
---|---|
date | Tue, 08 Nov 2016 17:07:48 +0900 |
parents | 2dd40b4412e4 |
children | 599bd8ddb72b |
line wrap: on
line diff
--- a/Assets/Application/Scripts/StageManager.cs Mon Nov 07 18:42:01 2016 +0900 +++ b/Assets/Application/Scripts/StageManager.cs Tue Nov 08 17:07:48 2016 +0900 @@ -6,11 +6,9 @@ public static StageManager Instance; // stages["Attribute"]で取れる - public System.Collections.Generic.List<GameObject> stages = new System.Collections.Generic.List<GameObject>(); + public System.Collections.Generic.Dictionary<Stage.Type, GameObject> stages = new System.Collections.Generic.Dictionary<Stage.Type, GameObject>(); private GameObject baseStage; - public System.Collections.Generic.List<Vector3> StageData = new System.Collections.Generic.List<Vector3> (); - void Awake () { if (Instance == null) { Instance = this; @@ -28,19 +26,20 @@ baseStage = new GameObject (); baseStage.name = "stage"; baseStage.transform.position = Vector3.zero; + GameObject.FindGameObjectWithTag ("Player").transform.SetParent (baseStage.transform); } void SetStage () { object[] objects = Resources.LoadAll ("Prefabs/Object"); foreach (var obj in objects) { GameObject gbj = (GameObject)obj; - stages.Add(gbj); + stages.Add(gbj.GetComponent<Stage>().Attribute, gbj); } } // One. - public void CreateStage (int num, Vector3 pos) { - GameObject obj = Instantiate (stages[num]); + public void CreateStage (Stage.Type attr, Vector3 pos) { + GameObject obj = Instantiate (stages[attr]); obj.GetComponent<Stage> ().SetPosition (pos); obj.transform.SetParent (baseStage.transform); } @@ -49,10 +48,20 @@ public void CreateStages (int count) { for (int x = 0; x < count; x++) { for (int z = 0; z < count; z++) { - CreateStage (Random.Range (0, stages.Count), new Vector3 (x, Random.Range(-1, 1), z)); + CreateStage (GetTypes(Random.Range(0,3)), new Vector3 (x, Random.Range(-1, 1), z)); } } } + + public Stage.Type GetTypes (int n) { + if (n == 0) { + return Stage.Type.SAND; + } else if (n == 1) { + return Stage.Type.WOOD; + } else { + return Stage.Type.GRASS; + } + } // Update is called once per frame void Update () {