VioletaBabel

31. 연출용 툴 이용해 유니티에서 연출 본문

BCA/4. Unity
31. 연출용 툴 이용해 유니티에서 연출
Beabletoet 2018. 4. 27. 16:09

Main Camera에 LoadData.cs를 넣고, imageObject에 GameObject라는 프리팹(스프라이트 렌더러를 가짐)을, Dialog에는 Dialog라는 프리팹, TextObject에는 New Text를 넣어준다(여기서 나머지는 empty object지만 new text는 3d text임을 유의) 넣어준다. 그리고 글씨가 확실히 앞에 있게하기 위해 New Text에만 z값을 -1로 주었다.


연출용 툴에는 ( http://violetababel.tistory.com/406 )

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
Make moomin.jpg a 0.5 0.5 1 n 
Dialog grey_panel.png panel 0 -3 16 3 
ChangeColor panel 255 255 255 100 0 
Text Get the Fxxk Up! ; 
Wait 
TextCon Go Home Now!! ; 
Wait 
TextReturn Shut up Mouse! Hahahahahaha!!! ; 
EndDialog 
Spawn on 
FadeIn a 1.5 
Move a 2 2 5 
Spawn off 
ChangeColor a 100 100 100 255 1.5 
Spawn on 
ShakeScale a 2 
Rotate a 180 0.75 
Spawn off 
Spawn on 
Rotate a 0 0.75 
ChangeColor a 255 255 255 255 1.5 
ChangeScale a 1.5 1.5 
Spawn off 
PunchPosition a 0 1 2 
FadeOut a 1.5 
Delete a 
 
cs

을 넣어 Json파일로 저장한다.




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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
//LoadData.cs
using System.IO;
using UnityEngine;
using System.Net.Json;
using System.Collections.Generic;
using DG.Tweening;
public class LoadData : MonoBehaviour
{
    /// <summary>
    /// Make %s %s %f %f %f %c // 파일명 키값 x좌표 y좌표 z오더 처음에보여질유무(y,n)
    /// Move %s %f %f %f // 키값 x좌표 y좌표 이동시간
    /// FadeIn %s %f // 키값 시간
    /// FadeOut %s %f // 키값 시간
    /// ChangeColor %s %d %d %d %d %f // 키값 r값 g값 b값 a값 시간
    /// Delete %s // 키값
    /// ChangeScale %s %f %f // 키값 스케일값 시간
    /// Rotate %s %f %f // 키값 회전후바라볼각도 시간
    /// PunchPosition %s %f %f %f // 키값 x흔들림값 y흔들림값 시간
    /// ShakeScale %s %f // 키값 시간
    /// Spawn %s // 동시실행명령시작유무(on, off)
    /// Dialog %s %s %f %f %f %f // 파일명 키값 x좌표 y좌표 x스케일 y스케일
    /// </summary>
    public class Messages
    {
        public string name = "";
        public List<string> parameter = new List<string>();
    }
 
    public GameObject imageObject = null;
    public GameObject dialog = null;
    public GameObject textObject = null;
    private GameObject nowText = null;
 
    private string scriptText = "Hello";
    private Dictionary<string, GameObject> mValues = new Dictionary<string, GameObject>();
    private Queue<Messages> messageList = new Queue<Messages>();
    private float fNextTime = 0;
    private float fTime = 0;
    private bool bSpawn = false;
    private bool bDialogEnd = false;
    // Use this for initialization
    void Start()
    {
        LoadJsonData();
        nowText = Instantiate(textObject);
    }
    private void Next()
    {
        if (messageList.Count <= 0)
            return;
        Messages mes = messageList.Dequeue();
        if (mes.name.Equals("Make"))
            onMake(mes.parameter);
        else if (mes.name.Equals("ChangeColor"))
            ChangeColor(mes.parameter);
        else if (mes.name.Equals("Move"))
            onMove(mes.parameter);
        else if (mes.name.Equals("FadeIn"))
            FadeIn(mes.parameter);
        else if (mes.name.Equals("FadeOut"))
            FadeOut(mes.parameter);
        else if (mes.name.Equals("Delete"))
            onDelete(mes.parameter);
        else if (mes.name.Equals("ChangeScale"))
            ChangeScale(mes.parameter);
        else if (mes.name.Equals("Rotate"))
            onRotate(mes.parameter);
        else if (mes.name.Equals("PunchPosition"))
            PunchPosition(mes.parameter);
        else if (mes.name.Equals("ShakeScale"))
            ShakeScale(mes.parameter);
        else if (mes.name.Equals("Spawn"))
            Spawn(mes.parameter);
        else if (mes.name.Equals("Dialog"))
            onDialog(mes.parameter);
        else if (mes.name.Equals("Text"))
            onText(mes.parameter);
        else if (mes.name.Equals("TextCon"))
            onTextCon(mes.parameter);
        else if (mes.name.Equals("Wait"))
            onWait();
        else if (mes.name.Equals("TextReturn"))
            onTextCon(mes.parameter, "\n");
        else if (mes.name.Equals("EndDialog"))
            EndDialog();
    }
    // Update is called once per frame
    void Update()
    {
        fTime += Time.deltaTime;
 
        if (bSpawn)
        {
            Next();
        }
        else if(nowText.GetComponent<DialogText>().GetbWait())
        {
            if(Input.anyKeyDown)
            {
                nowText.GetComponent<DialogText>().TogglebWait();
                if (bDialogEnd)
                {
                    scriptText = "";
                    nowText.GetComponent<DialogText>().setText(scriptText);
                    bDialogEnd = false;
                }
            }
        }
        else if (fTime > fNextTime)
        {
            fTime = 0;
            if (!messageList.Count.Equals(0))
                Next();
        }
    }
 
    public void LoadJsonData()
    {
        string jsonText = File.ReadAllText("Assets/Json/TextTest.json");
        JsonTextParser textParser = new JsonTextParser();
        JsonObjectCollection root = textParser.Parse(jsonText) as JsonObjectCollection;
        JsonArrayCollection rootArray = root["Commands"as JsonArrayCollection;
        List<string> texts = new List<string>();
        foreach (JsonObjectCollection com in rootArray)
        {
            JsonStringValue Name = com["Name"as JsonStringValue;
            JsonArrayCollection list = com["List"as JsonArrayCollection;
            string name = Name.Value;
            foreach (JsonObjectCollection l in list)
            {
                string param = l[0].GetValue() as string;
                texts.Add(param);
            }
            Messages mes = new Messages();
            mes.name = name;
            mes.parameter = texts;
            messageList.Enqueue(mes);
            //if (name.Equals("Make"))
            //    onMake(texts);
            //else if (name.Equals("Move"))
            //    onMove(texts);
            //texts.Clear();
        }
    }
 
    private void onMake(List<string> datas)
    {
        GameObject m = Instantiate(imageObject);
        if (m.Equals(null))
            return;
        SpriteRenderer r = m.GetComponent<SpriteRenderer>();
        if (r.Equals(null))
            return;
        string fileName = datas[0];
        //r.sprite = Resources.Load(Path.GetFileNameWithoutExtension(fileName)) as Sprite;
        fileName = Path.GetFileNameWithoutExtension(fileName);
        Texture2D texture = Resources.Load(fileName) as Texture2D;
        Rect rt = new Rect(00, texture.width, texture.height);
        Sprite sp = Sprite.Create(texture, rt, new Vector2(0.5f, 0.5f));
        r.sprite = sp;
 
        mValues.Add(datas[1], m);
        float fx = float.Parse(datas[2]);
        float fy = float.Parse(datas[3]);
        int zOrder = int.Parse(datas[4]);
        m.transform.position = new Vector3(fx, fy, 0);
        r.sortingOrder = zOrder;
        string v = datas[5].ToUpper();
        if (v.Equals("N"))
        {
            Color c = r.color;
            c.a = 0;
            r.color = c;
        }
        datas.RemoveRange(06);
    }
 
    private void onMove(List<string> datas)
    {
        GameObject obj = mValues[datas[0]];
        if (obj.Equals(null))
            return;
        float fx = float.Parse(datas[1]);
        float fy = float.Parse(datas[2]);
        float onfTime = float.Parse(datas[3]);
        obj.transform.DOMove(new Vector3(fx, fy, 0), onfTime);
        checkNextTime(onfTime);
        datas.RemoveRange(04);
    }
 
    private void FadeIn(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        if (obj.Equals(null))
            return;
        float onfTime = float.Parse(param[1]);
        SpriteRenderer renderer = obj.GetComponent<SpriteRenderer>();
        if (renderer)
        {
            renderer.DOFade(1.0f, onfTime);
        }
        checkNextTime(onfTime);
        param.RemoveRange(02);
    }
 
 
    private void FadeOut(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        if (obj.Equals(null))
            return;
        float onfTime = float.Parse(param[1]);
        SpriteRenderer renderer = obj.GetComponent<SpriteRenderer>();
        if (renderer)
        {
            renderer.DOFade(0, onfTime);
        }
        checkNextTime(onfTime);
        param.RemoveRange(02);
    }
 
    private void ChangeColor(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        if (obj.Equals(null))
            return;
        Color c = new Color(float.Parse(param[1]) / 255.0f, float.Parse(param[2]) / 255.0f, float.Parse(param[3]) / 255.0f, float.Parse(param[4]) / 255.0f);
        SpriteRenderer renderer = obj.GetComponent<SpriteRenderer>();
        float onfTime = float.Parse(param[5]);
        renderer.DOColor(c, onfTime);
        checkNextTime(onfTime);
        param.RemoveRange(06);
    }
 
    private void onDelete(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        Destroy(obj);
        param.RemoveAt(0);
    }
 
    private void ChangeScale(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        float onfTime = float.Parse(param[2]);
        obj.transform.DOScale(float.Parse(param[1]), onfTime);
        checkNextTime(onfTime);
        param.RemoveRange(03);
    }
 
    private void onRotate(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        float onfTime = float.Parse(param[2]);
        obj.transform.DORotate(new Vector3(00-(float.Parse(param[1]))), onfTime);
        checkNextTime(onfTime);
        param.RemoveRange(03);
    }
 
    private void PunchPosition(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        float onfTime = float.Parse(param[3]);
        obj.transform.DOPunchPosition(new Vector3(float.Parse(param[1]), float.Parse(param[2])), onfTime);
        checkNextTime(onfTime);
        param.RemoveRange(04);
    }
    private void ShakeScale(List<string> param)
    {
        GameObject obj = mValues[param[0]];
        float onfTime = float.Parse(param[1]);
        obj.transform.DOShakeScale(onfTime);
        checkNextTime(onfTime);
        param.RemoveRange(02);
    }
 
    private void Spawn(List<string> param)
    {
        if (param[0].Equals("on"))
        {
            bSpawn = true;
            fNextTime = 0;
        }
        else
        {
            bSpawn = false;
        }
        param.RemoveAt(0);
    }
 
    private void checkNextTime(float onfTime)
    {
        if (bSpawn)
        {
            fNextTime = (fNextTime > onfTime) ? fNextTime : onfTime;
        }
        else
            fNextTime = onfTime;
    }
 
    private void onDialog(List<string> param)
    {
        GameObject nowDialog = Instantiate(dialog);
        if (nowDialog.Equals(null))
            return;
        SpriteRenderer r = nowDialog.GetComponent<SpriteRenderer>();
        if (r.Equals(null))
            return;
        string fileName = param[0];
        fileName = Path.GetFileNameWithoutExtension(fileName);
        Texture2D texture = Resources.Load(fileName) as Texture2D;
        Rect rt = new Rect(00, texture.width, texture.height);
 
 
 
        Sprite sp = Sprite.Create(texture, rt, new Vector2(0.5f, 0.5f));
        r.sprite = sp;
        mValues.Add(param[1], nowDialog);
        float fx = float.Parse(param[2]);
        float fy = float.Parse(param[3]);
        float xScale = float.Parse(param[4]);
        float yScale = float.Parse(param[5]);
        nowDialog.transform.position = new Vector3(fx, fy, 0);
        nowDialog.transform.localScale = new Vector3(xScale, yScale, 1);
        param.RemoveRange(06);
    }
    private void onText(List<string> param)
    {
        scriptText = "";
        int i = 0;
        foreach (string t in param)
        {
            if (t.Equals(";"))
            {
                ++i;
                break;
            }
            scriptText += t;
            scriptText += " ";
            ++i;
        }
        nowText.GetComponent<DialogText>().setText(scriptText);
        param.RemoveRange(0, i);
    }
 
    private void onTextCon(List<string> param, string preText = "")
    {
        int i = 0;
        scriptText = preText;
        foreach (string t in param)
        {
            if (t.Equals(";"))
            {
                ++i;
                break;
            }
            scriptText += t;
            scriptText += " ";
            ++i;
        }
        nowText.GetComponent<DialogText>().addText(scriptText);
        param.RemoveRange(0, i);
    }
 
    private void onWait()
    {
        nowText.GetComponent<DialogText>().TogglebWait();
    }
 
    private void EndDialog()
    {
        onWait();
        bDialogEnd = true;
    }
}
 
cs

그리고 위에서 연출용 툴을 이용해 TextTest.json으로 저장한 파일은 이렇게 저장된다.


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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
{
    "Commands": [
        {
            "Name""Make",
            "List": [
                {
                    "1""moomin.jpg"
                },
                {
                    "2""a"
                },
                {
                    "3""0.5"
                },
                {
                    "4""0.5"
                },
                {
                    "5""1"
                },
                {
                    "6""n"
                }
            ]
        },
        {
            "Name""Dialog",
            "List": [
                {
                    "1""grey_panel.png"
                },
                {
                    "2""panel"
                },
                {
                    "3""0"
                },
                {
                    "4""-3"
                },
                {
                    "5""16"
                },
                {
                    "6""3"
                }
            ]
        },
        {
            "Name""ChangeColor",
            "List": [
                {
                    "1""panel"
                },
                {
                    "2""255"
                },
                {
                    "3""255"
                },
                {
                    "4""255"
                },
                {
                    "5""100"
                },
                {
                    "6""0"
                }
            ]
        },
        {
            "Name""Text",
            "List": [
                {
                    "1""Get"
                },
                {
                    "2""the"
                },
                {
                    "3""Fxxk"
                },
                {
                    "4""Up!"
                },
                {
                    "5"";"
                }
            ]
        },
        {
            "Name""Wait",
            "List": [
                
            ]
        },
        {
            "Name""TextCon",
            "List": [
                {
                    "1""Go"
                },
                {
                    "2""Home"
                },
                {
                    "3""Now!!"
                },
                {
                    "4"";"
                }
            ]
        },
        {
            "Name""Wait",
            "List": [
                
            ]
        },
        {
            "Name""TextReturn",
            "List": [
                {
                    "1""Shut"
                },
                {
                    "2""up"
                },
                {
                    "3""Mouse!"
                },
                {
                    "4""Hahahahahaha!!!"
                },
                {
                    "5"";"
                }
            ]
        },
        {
            "Name""EndDialog",
            "List": [
                
            ]
        },
        {
            "Name""Spawn",
            "List": [
                {
                    "1""on"
                }
            ]
        },
        {
            "Name""FadeIn",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""1.5"
                }
            ]
        },
        {
            "Name""Move",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""2"
                },
                {
                    "3""2"
                },
                {
                    "4""5"
                }
            ]
        },
        {
            "Name""Spawn",
            "List": [
                {
                    "1""off"
                }
            ]
        },
        {
            "Name""ChangeColor",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""100"
                },
                {
                    "3""100"
                },
                {
                    "4""100"
                },
                {
                    "5""255"
                },
                {
                    "6""1.5"
                }
            ]
        },
        {
            "Name""Spawn",
            "List": [
                {
                    "1""on"
                }
            ]
        },
        {
            "Name""ShakeScale",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""2"
                }
            ]
        },
        {
            "Name""Rotate",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""180"
                },
                {
                    "3""0.75"
                }
            ]
        },
        {
            "Name""Spawn",
            "List": [
                {
                    "1""off"
                }
            ]
        },
        {
            "Name""Spawn",
            "List": [
                {
                    "1""on"
                }
            ]
        },
        {
            "Name""Rotate",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""0"
                },
                {
                    "3""0.75"
                }
            ]
        },
        {
            "Name""ChangeColor",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""255"
                },
                {
                    "3""255"
                },
                {
                    "4""255"
                },
                {
                    "5""255"
                },
                {
                    "6""1.5"
                }
            ]
        },
        {
            "Name""ChangeScale",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""1.5"
                },
                {
                    "3""1.5"
                }
            ]
        },
        {
            "Name""Spawn",
            "List": [
                {
                    "1""off"
                }
            ]
        },
        {
            "Name""PunchPosition",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""0"
                },
                {
                    "3""1"
                },
                {
                    "4""2"
                }
            ]
        },
        {
            "Name""FadeOut",
            "List": [
                {
                    "1""a"
                },
                {
                    "2""1.5"
                }
            ]
        },
        {
            "Name""Delete",
            "List": [
                {
                    "1""a"
                }
            ]
        }
    ]
}
cs


'BCA > 4. Unity' 카테고리의 다른 글

34. 3D plane에서 cube 이동  (0) 2018.05.09
32. 타워 디펜스게임  (0) 2018.05.03
29. 테트리스  (0) 2018.04.04
28. 슈팅게임 일단은 완성  (0) 2018.03.30
27일 : 간단한 슈팅게임  (0) 2018.03.28
Comments