0
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
|
3 using System.Collections.Generic;
|
|
4
|
|
5 public class StageManager : MonoBehaviour {
|
|
6
|
3
|
7 public static StageManager Instance;
|
0
|
8 // stages["Attribute"]で取れる
|
4
|
9 public System.Collections.Generic.Dictionary<Stage.Type, GameObject> stages = new System.Collections.Generic.Dictionary<Stage.Type, GameObject>();
|
0
|
10 private GameObject baseStage;
|
|
11
|
3
|
12 void Awake () {
|
|
13 if (Instance == null) {
|
|
14 Instance = this;
|
|
15 }
|
|
16 }
|
|
17
|
0
|
18 // Use this for initialization
|
|
19 void Start () {
|
|
20 Init ();
|
|
21 SetStage ();
|
|
22 CreateStages (10);
|
|
23 }
|
|
24
|
|
25 void Init () {
|
|
26 baseStage = new GameObject ();
|
|
27 baseStage.name = "stage";
|
|
28 baseStage.transform.position = Vector3.zero;
|
4
|
29 GameObject.FindGameObjectWithTag ("Player").transform.SetParent (baseStage.transform);
|
0
|
30 }
|
|
31
|
|
32 void SetStage () {
|
3
|
33 object[] objects = Resources.LoadAll ("Prefabs/Object");
|
0
|
34 foreach (var obj in objects) {
|
|
35 GameObject gbj = (GameObject)obj;
|
4
|
36 stages.Add(gbj.GetComponent<Stage>().Attribute, gbj);
|
0
|
37 }
|
|
38 }
|
|
39
|
|
40 // One.
|
4
|
41 public void CreateStage (Stage.Type attr, Vector3 pos) {
|
|
42 GameObject obj = Instantiate (stages[attr]);
|
0
|
43 obj.GetComponent<Stage> ().SetPosition (pos);
|
|
44 obj.transform.SetParent (baseStage.transform);
|
|
45 }
|
|
46
|
|
47 // Any.
|
|
48 public void CreateStages (int count) {
|
|
49 for (int x = 0; x < count; x++) {
|
|
50 for (int z = 0; z < count; z++) {
|
4
|
51 CreateStage (GetTypes(Random.Range(0,3)), new Vector3 (x, Random.Range(-1, 1), z));
|
0
|
52 }
|
|
53 }
|
|
54 }
|
4
|
55
|
|
56 public Stage.Type GetTypes (int n) {
|
|
57 if (n == 0) {
|
|
58 return Stage.Type.SAND;
|
|
59 } else if (n == 1) {
|
|
60 return Stage.Type.WOOD;
|
|
61 } else {
|
|
62 return Stage.Type.GRASS;
|
|
63 }
|
|
64 }
|
0
|
65
|
|
66 // Update is called once per frame
|
|
67 void Update () {
|
|
68
|
|
69 }
|
|
70 }
|