-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateStage.cs
66 lines (59 loc) · 2.02 KB
/
CreateStage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateStage : MonoBehaviour {
public GameObject gstage;
public Vector3 pos;
private Vector3 space = new Vector3(1.0f, 1.0f, 1.0f);
private int iwidth;
void Start () {
/*
* 初期座標の設定
*/
pos = Vector3.zero;
}
public void Create(Vector3 pos) {
iwidth = 0;
/*
* ステージマップが保存されているテキストのパス
*/
string StageFile = System.IO.Path.GetFileName(@"C:\Users\stage.txt");
/*
* テキストの中身(ステージマップ)を読み込んで変数に保存
*/
ReadWrite rw = new ReadWrite();
string textdata = rw.Read(StageFile);
GameObject obj = null;
/*
* 変数に保存したステージマップを走査する
* #ならCubeを生成し、Cubeの大きさだけx軸に右に移動
* 改行文字ならz軸に下に移動して、x軸を初期化
* 空白、-、ならそのままx軸に右に移動
*/
foreach(char c in textdata) {
if(c == '#') {
obj = Instantiate(gstage, pos, Quaternion.identity) as GameObject;
obj.name = gstage.name;
pos.x += obj.transform.lossyScale.x;
iwidth++;
} else if (c == '\n') {
Vector3 origin = new Vector3((float)iwidth, 1.0f, 0f);
pos.z -= space.z;
pos.x -= origin.x;
iwidth = 0;
} else if (c == ' ' || c == '-') {
pos.x += space.x;
iwidth++;
}
}
}
public void Delete() {
/*
* ステージというタグのオブジェクトをすべて消去
*/
GameObject[] stages = GameObject.FindGameObjectsWithTag("Stage");
foreach(GameObject stage in stages) {
GameObject.DestroyImmediate(stage);
}
}
}