'분류 전체보기'에 해당되는 글 118건

  1. 2020.10.12 MFC CString to Char*
  2. 2020.09.17 MFC 강의, 참고
  3. 2020.08.17 6.Google Play Beta.ver//구글 플레이 베타버전 업로드
  4. 2020.08.17 5.Stage, Cube, CubeMove
  5. 2020.08.17 4.Title/StageSelect
  6. 2020.08.17 3.App -> Logo
  7. 2020.08.17 2.Unity Info관리
  8. 2020.08.17 1.Unity GameSceneManager

MFC CString to Char*

C++/problemsC++ 2020. 10. 12. 10:43

출처 : https://skql.tistory.com/559
===============================본문================================
CString 에서 Char* (배열)

UDP 소켓 통신하면서

CString으로 받은 값을 Char* 로 센드 시켰을때

길이는 맞게 오는데 자꾸 한글자만 나와 ㅠ.ㅠ

구글링 네이뇬 검색 하면 아래 와 비슷한 내용들 많이 나오는데...

방법은
1. (LPSTR)(LPCTSTR)로 강제 형변환
2. CString str;
   str.GetBuffer(str.GetLength());
   해주시면 char *을 리턴합니다.
ps. 위 두가지 방법중에 2번을 추천합니다.
      그리고 GetBuffer를 사용하시면 ReleaseBuffer()를 사용해서 해제해 주셔야합니다.


CString msg = "abcdefg";
char* tempchar;

tempchar = LPSTR(LPCTSTR(msg));
머 요런식으로 해서

strlen(tempchar) === 1
msg.getLength === 6

머냐고요~~~

strcpy
memcpy 다 1글자씩 밖에 안드감 ㅠ.ㅠ


다시 구글링(해결법)


char Buffer[255];
CString szString;
size_t CharactersConverted = 0;

wcstombs_s(&CharactersConverted, Buffer, szString.GetLength()+1, szString, _TRUNCATE);


위방법 ㅠ.ㅠ

3시간 정도 찾은거 같아 ㅠ.ㅠ

비록 땃짓도 많이 했지만 C#은 간단하구 좋았는데..

VS2005 VC++ 대략 알고리즘 짜는데 시간이 가는게 아니라... 타입케스팅 하다가 시간이 다 가버림 ㅠ.ㅠ 쥘쥘쥘쥘 꺼우져!!!!!!!

'C++ > problemsC++' 카테고리의 다른 글

Eclipse CDT C++11 사용 설정(#include <thread>)  (0) 2021.07.23
MFC Char* to CString  (0) 2020.11.27
매개변수로 배열 전달시 sizeof 문제  (0) 2020.10.22
:

MFC 강의, 참고

C++/MFC 2020. 9. 17. 17:52

https://www.youtube.com/playlist?list=PLiZvlxkcLhalUHK9UnRS_KweH9R3tgBIO"

유튜브 강의

https://yyman.tistory.com/category/%EC%86%8C%ED%94%84%ED%8A%B8%EC%9B%A8%EC%96%B4%28SW%29/MS%20-%20C++%20%28GUI%29%20MFC


정리된 블로그1

'C++ > MFC' 카테고리의 다른 글

프로젝트에 리소스로 PNG파일 추가  (0) 2021.05.13
CString to float/float to Byte/Byte to Float  (0) 2020.10.15
:

6.Google Play Beta.ver//구글 플레이 베타버전 업로드

개발 일지/Move Cube 2020. 8. 17. 15:52

https://play.google.com/store/apps/details?id=com.Hanayafld.ProjectCubeDev

'개발 일지 > Move Cube' 카테고리의 다른 글

5.Stage, Cube, CubeMove  (0) 2020.08.17
4.Title/StageSelect  (0) 2020.08.17
3.App -> Logo  (0) 2020.08.17
2.Unity Info관리  (0) 2020.08.17
1.Unity GameSceneManager  (0) 2020.08.17
:

5.Stage, Cube, CubeMove

개발 일지/Move Cube 2020. 8. 17. 15:50

1.Stage

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class SceneStage : MonoBehaviour
{
    public Cube cube;
 
    public Button btnRegameKey;
    public Button btnHomeKey;
    public Button btnNextStage;
    public Button btnStart;
 
    public GameObject buttons;
    public GameObject clearMessage;
    public GameObject failedMessage;
    public GameObject objTxtMove;
    public GameObject objTxtTime;
 
    public Text txtCurrentMove;
    public Text txtMaxMove;
    public Text txtTimeLimit;
 
    private int currentMoveCount;
    private int maxMoveCount;
    private int timeLimit;
 
    private int stageId;
    private Camera mainCamera;
 
    private bool isClear = false;
    private bool isFaeiled = false;
    
    public void InitStage(int stageId)
    {
        this.stageId = stageId;
        Debug.LogFormat("불러온 스테이지 id : {0}"this.stageId);
        //stageNum에 맞는 스테이지 불러와서 실행
 
        #region Data
        var dataManager = DataManager.GetInstance();
        var stageData = dataManager.dicStageData[this.stageId];
        #endregion
 
        #region Info
        var infoManager = InfoManager.GetInstance();
        var userInfo = infoManager.GetUserInfo();
        var userStageLevel = userInfo.stageLevel;
        #endregion
 
        #region Stage Reset
        this.cube.transform.position = new Vector3(010);
        this.SetStageMap(stageData.path);
        this.SetCamara(stageData.cameraX, stageData.cameraY, stageData.cameraZ);
 
        this.btnStart.gameObject.SetActive(true);
        this.buttons.SetActive(false);
        this.cube.isMoveWait = false;
 
        this.SetDefeat(stageData.maxMove, stageData.timeLimit);
        #endregion Stage Reset
 
        this.cube.onMoveCount = () =>
        {
            this.MoveCounting();
        };
        this.cube.onGameClear = () =>
        {
            if(this.isFaeiled == false)
            {
                this.isClear = true;
                this.objTxtMove.SetActive(false);
                this.objTxtTime.SetActive(false);
                this.StageClear(userStageLevel, stageData.stageLevel);
                this.txtTimeLimit.gameObject.SetActive(false);
                this.txtCurrentMove.gameObject.SetActive(false);
                this.txtMaxMove.gameObject.SetActive(false);
            }
        };
        this.cube.onGameFailed = () =>
        {
            if(this.isClear == false)
            {
                this.isFaeiled = true;
                this.objTxtMove.SetActive(false);
                this.objTxtTime.SetActive(false);
                this.StageFailed(userStageLevel, stageData.stageLevel);
                this.txtTimeLimit.gameObject.SetActive(false);
                this.txtCurrentMove.gameObject.SetActive(false);
                this.txtMaxMove.gameObject.SetActive(false);
            }
        };
 
        #region Button
        this.btnStart.onClick.AddListener(() =>
        {
            this.btnStart.gameObject.SetActive(false);
            this.buttons.SetActive(true);
            this.cube.isMoveWait = true;
            StartCoroutine(this.MoveCamera());
            StartCoroutine(this.Timer());
        });
 
        this.btnRegameKey.onClick.AddListener(() =>
        {
            Debug.Log("다시하기");
            GameSceneManager.GetInstance().LoadScene(4this.stageId);
        });
 
        this.btnHomeKey.onClick.AddListener(() =>
        {
            Debug.Log("난이도 선택");
            GameSceneManager.GetInstance().LoadScene(3);
        });
 
        this.btnNextStage.onClick.AddListener(() =>
        {
            Debug.LogFormat("다음 단계 : {0}"this.stageId + 1);
            GameSceneManager.GetInstance().LoadScene(4this.stageId + 1);
        });
        #endregion
    }
 
    #region 스테이지 클리어 관련
    private IEnumerator Timer()
    {
        while (true)
        {
            if (this.timeLimit == 0)
            {
                Debug.Log("타임아웃");
                this.cube.onGameFailed();
                break;
            }
            yield return new WaitForSeconds(1.0f);
            this.timeLimit--;
            this.txtTimeLimit.text = this.timeLimit.ToString();
        }
        yield return null;
    }
 
    private void MoveCounting()
    {
        if (this.currentMoveCount == this.maxMoveCount)
        {
            Debug.Log("이동아웃");
            this.cube.onGameFailed();
        }
        this.currentMoveCount++;
        this.txtCurrentMove.text = this.currentMoveCount.ToString();
    }
 
    private void SetDefeat(int count, int time)
    {
        if (count == -1)
        {
            this.objTxtTime.SetActive(false);
            this.objTxtMove.SetActive(false);
            this.txtCurrentMove.gameObject.SetActive(false);
            this.txtMaxMove.gameObject.SetActive(false);
            this.currentMoveCount = count * 100;
        }
        else
        {
            this.txtCurrentMove.text = "0";
            this.txtMaxMove.text = "/" + count.ToString();
            this.currentMoveCount = 0;
            this.maxMoveCount = count;
        }
 
        if (time == -1)
        {
            this.txtTimeLimit.gameObject.SetActive(false);
            this.timeLimit = -100;
        }
        else
        {
            this.txtTimeLimit.text = time.ToString();
            this.timeLimit = time;
        }
    }
 
    private void StageClear(int userStageLevel, int currentStageLevel)
    {
        //내 레벨이 스테이지 레벨과 같을 경우 레벨업을 한다.
        if (userStageLevel == currentStageLevel)
        {
            var infoManager = InfoManager.GetInstance();
            infoManager.SaveUserInfo(true);
        }
 
        //클리어 메시지와 클리어 UI 설정
        var dataManager = DataManager.GetInstance();
 
        if (currentStageLevel == dataManager.dicStageData.Count)
        {
            var rtRegameKey = (RectTransform)this.btnRegameKey.transform;
            rtRegameKey.sizeDelta = new Vector3(180180);
            this.btnRegameKey.transform.localPosition = new Vector3(-120-1200);
            var rtHomeKey = (RectTransform)this.btnHomeKey.transform;
            rtHomeKey.sizeDelta = new Vector3(180180);
            this.btnHomeKey.transform.localPosition = new Vector3(120-1200);
        }
        else
        {
            this.btnNextStage.gameObject.SetActive(true);
            var rtRegameKey = (RectTransform)this.btnRegameKey.transform;
            rtRegameKey.sizeDelta = new Vector3(180180);
            this.btnRegameKey.transform.localPosition = new Vector3(-240-1200);
            var rtHomeKey = (RectTransform)this.btnHomeKey.transform;
            rtHomeKey.sizeDelta = new Vector3(180180);
            this.btnHomeKey.transform.localPosition = new Vector3(0-1200);
        }
        this.buttons.SetActive(false);
        this.clearMessage.SetActive(true);
 
    }
 
    private void StageFailed(int userStageLevel, int currentStageLevel)
    {
        //UI설정
        this.buttons.SetActive(false);
        this.failedMessage.SetActive(true);
 
        if (userStageLevel > currentStageLevel)
        {
            this.btnNextStage.gameObject.SetActive(true);
 
            var rtRegameKey = (RectTransform)this.btnRegameKey.transform;
            rtRegameKey.sizeDelta = new Vector3(180180);
            this.btnRegameKey.transform.localPosition = new Vector3(-240-1200);
            var rtHomeKey = (RectTransform)this.btnHomeKey.transform;
            rtHomeKey.sizeDelta = new Vector3(180180);
            this.btnHomeKey.transform.localPosition = new Vector3(0-1200);
        }
        else
        {
            var rtRegameKey = (RectTransform)this.btnRegameKey.transform;
            rtRegameKey.sizeDelta = new Vector3(180180);
            this.btnRegameKey.transform.localPosition = new Vector3(-120-1200);
            var rtHomeKey = (RectTransform)this.btnHomeKey.transform;
            rtHomeKey.sizeDelta = new Vector3(180180);
            this.btnHomeKey.transform.localPosition = new Vector3(120-1200);
        }
    }
    #endregion
 
    #region 스테이지 맵 세팅
    private void SetStageMap(string path)
    {
        Debug.LogFormat("셋 스테이지 맵 경로 : {0}", path);
        var stagePrefabs = Resources.Load<GameObject>(path);
        var stageMap = Instantiate<GameObject>(stagePrefabs);
    }
    #endregion
 
    #region 카메라 셋팅
    private void SetCamara(float x, float y, float z)
    {
        Debug.Log("카메라 셋팅");
        this.mainCamera = FindObjectOfType<Camera>();
        this.mainCamera.transform.position = new Vector3(x, y, z);
    }
 
    private IEnumerator MoveCamera()
    {
        Vector3 cameraPos = this.mainCamera.transform.position;
        Vector3 cameraPoint = new Vector3(4120);
 
        var distancePos = new Vector3(cameraPos.x - cameraPoint.x, cameraPos.y - cameraPoint.y, cameraPos.z - cameraPoint.z);
        if (distancePos.x < 0)
        {
            while (true)
            {
                if (cameraPoint.x - this.mainCamera.transform.position.x < 0)
                {
                    this.mainCamera.transform.position = cameraPoint;//정렬
                    break;
                }
                this.mainCamera.transform.position += new Vector3(-distancePos.x / (Time.deltaTime * 2000), -distancePos.y / (Time.deltaTime * 2000), -distancePos.z / (Time.deltaTime * 2000));
 
                yield return null;
            }
        }
        else
        {
            while (true)
            {
                if (cameraPoint.x - this.mainCamera.transform.position.x > 0)
                {
                    this.mainCamera.transform.position = cameraPoint;//정렬
                    break;
                }
                this.mainCamera.transform.position += new Vector3(-distancePos.x / (Time.deltaTime * 2000), -distancePos.y / (Time.deltaTime * 2000), -distancePos.z / (Time.deltaTime * 2000));
 
                yield return null;
            }
        }
        yield return null;
    }
    #endregion
}
 
cs


2.Cube

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class Cube : MonoBehaviour
{
    [HideInInspector]
    public bool isMoveWait = false;//이게 true면, 이동조작가능, false면 이동조작불가
    public Sensor[] sensors;// 센서들 순서대로 0~4, 위 아래 왼 오 바닥센서(납작한 박스콜라이더로 되어있음)
    public GameObject cubeBody;
    public PanelGoal panelGoal;
 
    public int cubeSpeed = 1;
    private CubeMove cubeMove;
    public System.Action onGameClear;
    public System.Action onGameFailed;
    public System.Action onMoveCount;//이동횟수 알려줌
 
    void Awake()
    {
        this.cubeMove = GetComponent<CubeMove>();
        this.panelGoal.onGameClear = () =>
        {
            StartCoroutine(this.GameClear());
        }; 
    }
 
    #region 특수 타일 감지
    private void OnTriggerEnter(Collider other)//큐브가 올라가는 순간 타일을 읽음
    {
        if (other.tag == "Tile")
        {
            StartCoroutine(this.Tile());
        }
        else if (other.tag == "Goal")
        {
            StartCoroutine(this.Tile());
        }
        else if (other.tag == "OutLine")
        {
            Debug.Log("OutLine");
            this.onGameFailed();
        }
        else if (other.tag == "Trap")
        {
            Debug.Log("Trap");
            this.onGameFailed();
        }
        else if (other.tag == "RotateLeft")
        {
            Debug.Log("RotateLeft");
            StartCoroutine(this.TileRotate(-1));
        }
        else if (other.tag == "RotateRight")
        {
            Debug.Log("RotateRight");
            StartCoroutine(this.TileRotate(1)); ;
        }
        else if (other.tag == "Slide")
        {
            Debug.Log("Slide");
            StartCoroutine(this.TileSlide(other.transform.eulerAngles.y));
        }
        else if (other.tag == "In")
        {
            Debug.Log("In");
            StartCoroutine(this.TileInOut(other.transform.Find("Tile(Out)").transform.position));
        }
    }
    #endregion
 
    #region 특수 타일 효과 모음
    private IEnumerator Tile()
    {
        yield return new WaitForSeconds(1.5f / cubeSpeed);
        this.isMoveWait = true;
    }
 
    private IEnumerator TileInOut(Vector3 tileOut)
    {
        yield return new WaitForSeconds(1.5f / cubeSpeed);
 
        //내려감
        Vector3 dir = new Vector3(010);
        for (int i = 0; i < 30 / this.cubeSpeed; i++)
        {
            this.transform.position += 1 / 30f * -dir * this.cubeSpeed;
            yield return null;
        }
 
        //이동
        this.transform.position = tileOut;
        yield return new WaitForSeconds(1.5f / cubeSpeed);
 
        //올라옴
        for (int i = 0; i < 30 / this.cubeSpeed; i++)
        {
            this.transform.position += 1 / 30f * dir * this.cubeSpeed;
            yield return null;
        }
 
        this.isMoveWait = true;
    }
 
    private IEnumerator TileSlide(float tileDir)//타일의 화살표 위치를 받음
    {
        yield return new WaitForSeconds(1.5f / cubeSpeed);
        Debug.Log(tileDir);
        Vector3 dir = new Vector3(000);//큐브가 이동 할 방향
 
        if (tileDir == 0)
        {
            //위
            dir.x = -1;
        }
        else if (tileDir == 90)
        {
            //오른
            dir.z = 1;
        }
        else if (tileDir == 180)
        {
            //아래
            dir.x = 1;
        }
        else if (tileDir == 270)
        {
            //왼
            dir.z = -1;
        }
 
        Debug.Log(dir);
        for (int i = 0; i < 30 / this.cubeSpeed; i++)
        {
            this.transform.position += 1 / 30f * dir * this.cubeSpeed;
            this.cubeMove.mainCamera.transform.position += 1 / 30f * dir * this.cubeSpeed;
            yield return null;
        }
    }
 
    private IEnumerator TileRotate(int dir)
    {
        yield return new WaitForSeconds(1.5f / cubeSpeed);
 
        for (int i = 0; i < 45 / this.cubeSpeed; i++)
        {
            this.cubeBody.transform.Rotate(0, dir * this.cubeSpeed * 20, Space.World);
            yield return null;
        }
 
        this.isMoveWait = true;
    }
    #endregion
    
    #region 게임 클리어와 실패 시
    private IEnumerator GameClear()
    {
        this.onGameClear();
        yield return new WaitForSeconds(1.5f / cubeSpeed);
 
        float pointA = this.transform.position.y;
 
        while (true)
        {
            if (this.transform.position.y <= pointA - 1.1f)
            {
                break;
            }
            this.transform.Translate(new Vector3(0-0.03f, 0));
            yield return null;
        }
        yield return null;
    }
    #endregion
}
 
cs


3.CubeMove


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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class CubeMove : MonoBehaviour
{
    public GameObject body;
    public Camera mainCamera;
    private Cube cube;
 
    public float cubeSpeed;
    public Coroutine moveRoutine;
 
    public Button btnUp;
    public Button btnDown;
    public Button btnLeft;
    public Button btnRight;
 
    void Awake()
    {
        this.cube = GetComponent<Cube>();
        this.cubeSpeed = this.cube.cubeSpeed;
        this.mainCamera = FindObjectOfType<Camera>();
    }
 
 
    void Start()
    {
        this.moveRoutine = StartCoroutine(this.KeyInput());
 
        #region 모바일 조작 Button(Main)
        this.btnUp.onClick.AddListener(() =>
        {
            if (this.cube.isMoveWait)
            {
                if (this.cube.sensors[0].isMove)
                {
                    this.cube.isMoveWait = false;
                    StartCoroutine(this.Move("z"1));
                    this.MoveReset();
                }
            }
        });
 
        this.btnDown.onClick.AddListener(() =>
        {
            if (this.cube.isMoveWait)
            {
                if (this.cube.sensors[1].isMove)
                {
                    this.cube.isMoveWait = false;
                    StartCoroutine(this.Move("z"-1));
                    this.MoveReset();
                }
            }
        });
 
        this.btnLeft.onClick.AddListener(() =>
        {
            if (this.cube.isMoveWait)
            {
                if (this.cube.sensors[2].isMove)
                {
                    this.cube.isMoveWait = false;
                    StartCoroutine(this.Move("x"-1));
                    this.MoveReset();
                }
            }
        });
 
        this.btnRight.onClick.AddListener(() =>
        {
            if (this.cube.isMoveWait)
            {
                if (this.cube.sensors[3].isMove)
                {
                    this.cube.isMoveWait = false;
                    StartCoroutine(this.Move("x"1));
                    this.MoveReset();
                }
            }
        });
        #endregion
    }
 
    #region 키보드 조작 ArrowKey && WASD
    private IEnumerator KeyInput()
    {
        while (true)
        {
            if (this.cube.isMoveWait)
            {
                #region 키보드 조작
                if (Input.GetKey("up"|| Input.GetKey("w"))
                {
                    if (this.cube.sensors[0].isMove)
                    {
                        this.cube.isMoveWait = false;
                        StartCoroutine(this.Move("z"1));
                        this.MoveReset();
                    }
                }
                else if (Input.GetKey("down"|| Input.GetKey("s"))
                {
                    if (this.cube.sensors[1].isMove)
                    {
                        this.cube.isMoveWait = false;
                        StartCoroutine(this.Move("z"-1));
                        this.MoveReset();
                    }
                }
                else if (Input.GetKey("left"|| Input.GetKey("a"))
                {
                    if (this.cube.sensors[2].isMove)
                    {
                        this.cube.isMoveWait = false;
                        StartCoroutine(this.Move("x"-1));
                        this.MoveReset();
                    }
                }
                else if (Input.GetKey("right"|| Input.GetKey("d"))
                {
                    if (this.cube.sensors[3].isMove)
                    {
                        this.cube.isMoveWait = false;
                        StartCoroutine(this.Move("x"1));
                        this.MoveReset();
                    }
                }
                #endregion
            }
            yield return null;
        }
    }
    #endregion
 
    private void MoveReset()//연달은 벽 통과할때 생기는 OnTriggerExit오류 방지 메서드
    {
        for (int i = 0; i < 4; i++)
        {
            this.cube.sensors[i].isMove = true;
        }
    }
 
    #region 큐브 이동 자연스럽게
    private IEnumerator Move(string shaft, int dir)//shaft = 축(x, y, z), dir = 방향 (-1, 1)
    {
        for (int i = 0; i < 30 / this.cubeSpeed; i++)//돌면서 y값 위로
        {
            this.MoveCube(shaft, dir);
            this.RotateCube(shaft, dir);
            this.NaturalRotate(1);
            yield return null;
        }
 
        for (int i = 0; i < 30 / this.cubeSpeed; i++)//돌면서 y값 아래로
        {
            this.MoveCube(shaft, dir);
            this.RotateCube(shaft, dir);
            this.NaturalRotate(-1);
            yield return null;
        }
        //위의 for문으로 이동시 0.9999.. 로 이동함, 그래서 정수단위 값으로 정렬해서 위치 재설정 코드
        this.cube.transform.position = new Vector3((float)Math.Round(this.cube.transform.position.x), (float)Math.Round(this.cube.transform.position.y), (float)Math.Round(this.cube.transform.position.z));
        this.cube.onMoveCount();//테스트(Test)시 주석처리
    }
 
    private void MoveCube(string shaft, int dir)
    {
        float x = 0, y = 0, z = 0;
        if (shaft == "x")
        {
            z = 1 / 60f * dir * this.cubeSpeed;
        }
        else if (shaft == "z")
        {
            x = 1 / 60f * -dir * this.cubeSpeed;
        }
        this.transform.position += (new Vector3(x, y, z));
        this.mainCamera.transform.position += (new Vector3(x, y, z));
    }
 
    private void RotateCube(string shaft, int dir)
    {
        float x = 0, y = 0, z = 0;
        if (shaft == "x")
        {
            x = 1.5f * dir * this.cubeSpeed;
        }
        else if (shaft == "z")
        {
            z = 1.5f * dir * this.cubeSpeed;
        }
        this.body.transform.Rotate(x, y, z, Space.World);
    }
 
    private void NaturalRotate(int dir)//자연스러운 회전을 위한 회전각 계수
    {
        this.body.transform.position += new Vector3(00.007f * dir * this.cubeSpeed, 0);
    }
    #endregion
}
 
cs




'개발 일지 > Move Cube' 카테고리의 다른 글

6.Google Play Beta.ver//구글 플레이 베타버전 업로드  (0) 2020.08.17
4.Title/StageSelect  (0) 2020.08.17
3.App -> Logo  (0) 2020.08.17
2.Unity Info관리  (0) 2020.08.17
1.Unity GameSceneManager  (0) 2020.08.17
:

4.Title/StageSelect

개발 일지/Move Cube 2020. 8. 17. 15:45

1.Title

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
 
public class SceneLogo : MonoBehaviour
{
    public Image imgLogo;
 
    public void Init(string name = ""int prefabId = 0)
    {
        StartCoroutine(this.FadeInOut());
    }
 
    public IEnumerator FadeInOut()
    {
        var color = this.imgLogo.color;
        float alpha = color.a;
        while (true)
        {
            alpha += 0.016f;
            color.a = alpha;
            this.imgLogo.color = color;
 
            if (alpha >= 1)
            {
                alpha = 1;
                break;
            }
            yield return null;
        }
 
        yield return new WaitForSeconds(1.5f);
 
        while (true)
        {
            alpha -= 0.016f;
            color.a = alpha;
            this.imgLogo.color = color;
 
            if (alpha <= 0)
            {
                alpha = 0;
                break;
            }
            yield return null;
        }
 
        GameSceneManager.GetInstance().LoadScene(3);
    }
}
 
cs




'개발 일지 > Move Cube' 카테고리의 다른 글

6.Google Play Beta.ver//구글 플레이 베타버전 업로드  (0) 2020.08.17
5.Stage, Cube, CubeMove  (0) 2020.08.17
3.App -> Logo  (0) 2020.08.17
2.Unity Info관리  (0) 2020.08.17
1.Unity GameSceneManager  (0) 2020.08.17
:

3.App -> Logo

개발 일지/Move Cube 2020. 8. 17. 15:41

1.App

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class SceneApp : MonoBehaviour
{
    public void Start()
    {
        DontDestroyOnLoad(this);
 
        var dataManager = DataManager.GetInstance();
        dataManager.LoadStageData();
 
        GameSceneManager.GetInstance().LoadScene(2);
    }
}
 
cs


2.Logo
로고 페이드 인아웃 구현.

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
 
public class SceneLogo : MonoBehaviour
{
    public Image imgLogo;
 
    public void Init(string name = ""int prefabId = 0)
    {
        StartCoroutine(this.FadeInOut());
    }
 
    public IEnumerator FadeInOut()
    {
        var color = this.imgLogo.color;
        float alpha = color.a;
        while (true)
        {
            alpha += 0.016f;
            color.a = alpha;
            this.imgLogo.color = color;
 
            if (alpha >= 1)
            {
                alpha = 1;
                break;
            }
            yield return null;
        }
 
        yield return new WaitForSeconds(1.5f);
 
        while (true)
        {
            alpha -= 0.016f;
            color.a = alpha;
            this.imgLogo.color = color;
 
            if (alpha <= 0)
            {
                alpha = 0;
                break;
            }
            yield return null;
        }
 
        GameSceneManager.GetInstance().LoadScene(3);
    }
}
 
cs


Title에서 Stage 선택, 더 복잡한 프로젝트 구성시 FadeInOut은 매니져로 이동.

'개발 일지 > Move Cube' 카테고리의 다른 글

6.Google Play Beta.ver//구글 플레이 베타버전 업로드  (0) 2020.08.17
5.Stage, Cube, CubeMove  (0) 2020.08.17
4.Title/StageSelect  (0) 2020.08.17
2.Unity Info관리  (0) 2020.08.17
1.Unity GameSceneManager  (0) 2020.08.17
:

2.Unity Info관리

개발 일지/Move Cube 2020. 8. 17. 15:36

1.UserInfo

1
2
3
4
5
6
7
8
9
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class UserInfo
{
    public int stageLevel;
}
 
cs


2.InfoManager

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
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Newtonsoft.Json;
 
public class InfoManager
{
    private static InfoManager instance;
    private string path = "/Info";
 
    //Info Dictionary
    private UserInfo userInfo;
 
    private InfoManager()
    {
        this.userInfo = new UserInfo();
    }
 
    public static InfoManager GetInstance()
    {
        if (InfoManager.instance == null)
        {
            InfoManager.instance = new InfoManager();
        }
 
        return InfoManager.instance;
    }
 
    #region 유저인포 로드
    public void LoadInfo()
    {
        this.LoadInfoImpl();
    }
    
    private void LoadInfoImpl()
    {
        var checkDirectory = Directory.Exists(Application.persistentDataPath + path);
 
        if (checkDirectory)
        {
            //persistentDataPath에 폴더가 존재하면
            var checkInfo = File.Exists(Application.persistentDataPath + path + "/userInfo.json");
            if (checkInfo)
            {
                //userInfo.json 파일이 존재하면
                Debug.Log("기존");
                Debug.Log(Application.persistentDataPath + path + "/userInfo.json");
                var text = File.ReadAllText(Application.persistentDataPath + path + "/userInfo.json");
                this.userInfo = JsonConvert.DeserializeObject<UserInfo>(text);
            }
            else
            {
                //userInfo.json 파일이 존재하지 않으면
                Debug.Log("신규");
                this.SetNewUserInfo();
                this.SaveUserInfo(false);
            }
        }
        else
        {
            //persistentDataPath에 폴더가 존재하지 않으면 + 폴더가 없으니 파일도 존재하지 않음
            Debug.Log("신규");
            Directory.CreateDirectory(Application.persistentDataPath + path);//폴더 생성
            this.SetNewUserInfo();
            this.SaveUserInfo(false);
        }
    }
    #endregion
 
    #region 신규유저 인포 세팅
    private void SetNewUserInfo()
    {
        this.userInfo = new UserInfo();
        //새로하기 선택시 세팅값 설정
        this.userInfo.stageLevel = 1;
    }
    #endregion
 
    #region 유저인포 리턴
    public UserInfo GetUserInfo()
    {
        return this.userInfo;
    }
    #endregion
 
    #region 유저인포 저장
    public void SaveUserInfo(bool isLevelUp)
    {
        if (isLevelUp)
        {
            Debug.Log("레벨업!");
            this.userInfo.stageLevel++;
        }
        var json = JsonConvert.SerializeObject(this.userInfo);
        File.WriteAllText(Application.persistentDataPath + path + "/userInfo.json", json, System.Text.Encoding.UTF8);
        Debug.Log("Info저장 완료");
    }
    #endregion
}
 
cs


UserInfo에 다른 값 추가시 ( 2개 이상의 값 ) ID를 통해 Dictionary로 관리하기

'개발 일지 > Move Cube' 카테고리의 다른 글

6.Google Play Beta.ver//구글 플레이 베타버전 업로드  (0) 2020.08.17
5.Stage, Cube, CubeMove  (0) 2020.08.17
4.Title/StageSelect  (0) 2020.08.17
3.App -> Logo  (0) 2020.08.17
1.Unity GameSceneManager  (0) 2020.08.17
:

1.Unity GameSceneManager

개발 일지/Move Cube 2020. 8. 17. 14:39

1.GameSceneManager

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
public class GameSceneManager
{
    private static GameSceneManager instance;
    private List<string> listBeforeScene;
    private string caller;
 
    private GameSceneManager()
    {
        this.listBeforeScene = new List<string>();
    }
 
    public static GameSceneManager GetInstance()
    {
        if(GameSceneManager.instance == null)
        {
            GameSceneManager.instance = new GameSceneManager();
        }
        return GameSceneManager.instance;
    }
 
    #region 로드씬
    public void LoadScene(int id, int stageLevel = 0)
    {
        this.listBeforeScene = new List<string>();
 
        var sceneName = ((SceneEnums.sceneName)id).ToString();
        var operation = SceneManager.LoadSceneAsync(sceneName);
 
        Debug.LogFormat("불러온 씬 : {0}", sceneName);
 
        operation.completed += (asyncOper) =>
        {
            SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName));
            this.InitScene((SceneEnums.sceneName)id, "", stageLevel);
        };   
    }
    #endregion
 
    #region 언로드씬
    public void UnloadScene()
    {
        var operation = SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene());
 
        operation.completed += (asyncOper) =>
        {
            SceneManager.SetActiveScene(SceneManager.GetSceneByName(this.listBeforeScene[this.listBeforeScene.Count-1]));
            this.listBeforeScene.RemoveAt(this.listBeforeScene.Count - 1);
        };
    }
 
    public void UnloadAllScene()
    {
        foreach(var name in this.listBeforeScene)
        {
            SceneManager.UnloadSceneAsync(name);
        }
    }
    #endregion
 
    #region 씬초기화
    //Scene을 초기화하는 과정이므로 Init메서드는 Scene의 대표 오브젝트 스크립트에서 정의
    //caller는 LoadScene 메소드를 호출한 Scene을 뜻함
    private void InitScene(SceneEnums.sceneName sceneName, string caller = ""int stageLevel = 0)
    {
        switch(sceneName)
        {
            case SceneEnums.sceneName.Logo:
                {
                    var go = GameObject.FindObjectOfType<SceneLogo>();
                    go.Init();
                    break;
                }
            case SceneEnums.sceneName.Title:
                {
                    var go = GameObject.FindObjectOfType<SceneTitle>();
                    go.Init();
                    break;
                }
            case SceneEnums.sceneName.Loading:
                {
                    var go = GameObject.FindObjectOfType<SceneLoading>();
                    go.Init();
                    break;
                }
            case SceneEnums.sceneName.Stage:
                {
                    var go = GameObject.FindObjectOfType<SceneStage>();
                    go.InitStage(stageLevel);
                    break;
                }
            default:
                break;
        }
    }
    #endregion
}
 
cs


2.SceneEnums


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class SceneEnums
{
    //Scene Enums
    public enum sceneName
    {
        None = -1,
        App = 0,
        Loading = 1,
        Logo = 2,
        Title = 3,
        Stage = 4
    }
}
 
cs


'개발 일지 > Move Cube' 카테고리의 다른 글

6.Google Play Beta.ver//구글 플레이 베타버전 업로드  (0) 2020.08.17
5.Stage, Cube, CubeMove  (0) 2020.08.17
4.Title/StageSelect  (0) 2020.08.17
3.App -> Logo  (0) 2020.08.17
2.Unity Info관리  (0) 2020.08.17
: