HUDTest

Unity/수업내용 2019. 4. 25. 09:55
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
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class TestHudText : MonoBehaviour
{
    public Button btn;
    private Canvas canvas;
 
    private void Awake()
    {
        this.canvas = FindObjectOfType<Canvas>();
    }
 
    private void Start()
    {
        //DOTween.To(MyMethod, 0, 12, 0.5f);
 
        this.btn.onClick.AddListener(() =>
        {
            Debug.Log("앙기모띠");
 
            //프리팹 로드
            var hudPre = Resources.Load<HUDDamageText>("Prefabs/Test/HUDDamageText");
            //인스탄트
            var hud = Instantiate(hudPre);
 
            //인잇 메서드 호출(텍스트랑 컬러)
            Color color = new Color(100);
 
            hud.Init("456", color);
 
            //부모 Canvas로 설정
            hud.transform.SetParent(this.canvas.transform, false);
 
            //초기화
            hud.transform.localPosition = Vector3.zero;
 
            //타겟 포지션
            var targetLocalPos = hud.transform.localPosition;
            targetLocalPos.y += 200;
            
            DOTween.ToAlpha(() => hud.txt.color, x => hud.txt.color = x, 00.5f);
            hud.transform.DOScale(new Vector3(222), 0.3f).OnComplete(() =>
            {
                hud.transform.DOScale(new Vector3(111), 0.2f);
            });
            hud.transform.DOLocalMove(targetLocalPos, 0.5f).SetEase(Ease.OutCirc).OnComplete(() =>
            {
                Destroy(hud.gameObject);
            });
        });
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class HUDDamageText : MonoBehaviour
{
    //문자, 컬러
    public Text txt;
 
    public void Init(string strDamage, Color color)
    {
        this.txt.text = strDamage;
        this.txt.color = color;
    }
}
 
cs


'Unity > 수업내용' 카테고리의 다른 글

(1)BGLoop  (0) 2019.05.01
LayerMask  (0) 2019.05.01
자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링  (0) 2019.04.30
<캐릭터 조작>화면 터치, WASD, 조이스틱  (0) 2019.04.25
<죽어라돌덩이>  (0) 2019.04.12
:

Unity Canvas

Unity/찾아본것 2019. 4. 24. 18:58

캔버스, UI요소를 배치하기 위한 영역


UI요소는 Canvas의 자식요소여야 함


요소는 첫번째 자식이 맨 처음 그려지고, 그 다음 순서대로 그려지며

나중에 그려진 UI요소가 위에 표시 됨


요소 정렬을 위해. SetAsFirstSibling, SetAsLastSibling, SetSiblingIndex를 사용함


:

EffectTest

Unity 2019. 4. 24. 00:11

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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class EffectTest : MonoBehaviour
{
    [SerializeField]
    private Button btnAttack;
    [SerializeField]
    private GameObject hero;
    [SerializeField]
    private GameObject monster;
 
    public GameObject objPool;
    public Material hitMaterial;
    private Material originMaterial;
 
    private Animator heroAnim;
    private Animator monsterAnim;
    private bool isAttacking;
    private Coroutine heroActionRoutine;
    private GameObject fx;
 
    private System.Action OnDamageMonster;
 
    private void Awake()
    {
        //FX로드
        var loadFx = Resources.Load<GameObject>("Prefabs/Test/SwordHitRed");
 
        //인스턴스화
        this.fx = Instantiate<GameObject>(loadFx);
        fx.transform.SetParent(this.objPool.transform);
        fx.name = "SwordHitRed";
        this.fx.SetActive(false);
    }
 
    private void Start()
    {
        //버튼 이벤트 등록
        this.btnAttack.onClick.AddListener(() =>
        {
            if (this.isAttacking == false)
            {
                //몬스터가 공격을 받을 시
                this.OnDamageMonster = () =>
                {
                    StartCoroutine(this.MonsterGetDamage());
                };
                Debug.Log("어택!");
                //영웅이 공격! attack_sword_01 실행
                this.heroActionRoutine = StartCoroutine(HeroPlayAttackAnim());
            }
            else
            {
                Debug.Log("공격불가");
            }
            //attack_sword_01 애니메이션 실행 후  idle@loop실행
        });
 
        //애니메이션 컴포넌트 가져옴
        this.heroAnim = this.hero.GetComponent<Animator>();
        this.monsterAnim = this.monster.GetComponent<Animator>();
 
        this.originMaterial = this.monster.transform.Find("StoneMonster").GetComponent<SkinnedMeshRenderer>().material;
    }
 
    private IEnumerator MonsterGetDamage()
    {
        this.monsterAnim.Play("Anim_Damage");
 
        var length = this.GetAnimLength("Anim_Damage");
 
        StartCoroutine(this.MonsterSwitchMaterial());
 
        yield return new WaitForSeconds(length);
 
        this.monsterAnim.Play("Anim_Idle");
    }
 
    private IEnumerator MonsterSwitchMaterial()
    {
        this.monster.transform.Find("StoneMonster").GetComponent<SkinnedMeshRenderer>().material = this.hitMaterial;
        yield return new WaitForSeconds(0.1f);
 
        this.monster.transform.Find("StoneMonster").GetComponent<SkinnedMeshRenderer>().material = this.originMaterial;
    }
 
    private IEnumerator HeroPlayAttackAnim()
    {
        this.isAttacking = true;
        this.heroAnim.Play("attack_sword_01");
 
        var length = this.GetAnimLength("attack_sword_01");
 
        yield return new WaitForSeconds(0.25f);
 
        Debug.Log("타격!!");
        this.AddFx("SwordHitRed"this.monster.transform.Find("fsPoint").position);
        this.OnDamageMonster();
        yield return new WaitForSeconds(length - 0.25f);
 
        this.isAttacking = false;
 
        Debug.Log("공격 완료!!!");
        this.heroAnim.Play("idle@loop");
    }
 
    private void AddFx(string effectName, Vector3 fxPos)
    {
        //만들어진 프리팹 인스턴스의 위치를 fxPos로 설정
        this.fx.transform.SetParent(this.monster.transform.Find("HitFxPoint"));
        this.fx.transform.position = fxPos;
        this.fx.SetActive(true);
        var particle = this.fx.GetComponent<ParticleSystem>();
 
        this.StartCoroutine(this.PlayFx(particle));
    }
 
    private IEnumerator PlayFx(ParticleSystem particle)
    {
        particle.Play();
        yield return new WaitForSeconds(particle.main.duration);
        this.fx.transform.SetParent(this.objPool.transform);
        this.fx.SetActive(false);
    }
 
    private float GetAnimLength(string animName)
    {
        float time = 0;
        RuntimeAnimatorController ac1 = heroAnim.runtimeAnimatorController;
        RuntimeAnimatorController ac2 = monsterAnim.runtimeAnimatorController;
 
        foreach (var data in ac1.animationClips)
        {
            Debug.Log(data.name);
        }
        for (int i = 0; i < ac1.animationClips.Length; i++)
        {
            if (ac1.animationClips[i].name == animName)
            {
                time = ac1.animationClips[i].length;
            }
        }
 
        if (time == 0)
        {
            foreach (var data in ac2.animationClips)
            {
                Debug.Log(data.name);
            }
            for (int i = 0; i < ac2.animationClips.Length; i++)
            {
                if (ac2.animationClips[i].name == animName)
                {
                    time = ac2.animationClips[i].length;
                }
            }
        }
        return time;
    }
}
 
cs


'Unity' 카테고리의 다른 글

개인정보 처리방침  (0) 2019.06.13
:

Animator Length 구하기 API

Unity/찾아본것 2019. 4. 23. 17:55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private float GetAnimLength(string animName)
    {
        float time = 0;
        RuntimeAnimatorController ac = heroAnim.runtimeAnimatorController;
 
        for (int i = 0; i < ac.animationClips.Length; i++)
        {
            if (ac.animationClips[i].name == animName)
            {
                time = ac.animationClips[i].length;
            }
        }
 
        return time;
    }
cs


1
var length = this.GetAnimLength("attack_sword_01");
cs


:

<설계구조를 다시 짜보았다.>

Unity/과제 2019. 4. 21. 23:34


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
public class App : MonoBehaviour
{
    public Camera uiCamera;
 
    //씬
    private Logo logo;
    private Title title;
    private UIInGame inGame;
    private System.Action OnLogoEnd;
    private System.Action OnTitleEnd;
 
    private void Awake()
    {
        Object.DontDestroyOnLoad(this);
    }
 
    private void Start()
    {
        #region 로고 씬 로드 하는 부분(로고 씬 테스트 건너 뛰고 싶을 시 region 주석)
        var operLogo = SceneManager.LoadSceneAsync("Logo");
        operLogo.completed += (AsyncOper) =>
        {
            Debug.Log("로고 씬 로드");
            var logo = GameObject.FindObjectOfType<Logo>();
            logo.Init(this.uiCamera);
            logo.OnLogoEnd = () =>
            {
                this.OnLogoEnd();
            };
        };
        #endregion
 
        #region 타이틀 씬 로드하는 부분(타이틀 씬 테스트 건너 뛰고 싶을 시 region 주석)
        this.OnLogoEnd = () =>
        {
            var operTitle = SceneManager.LoadSceneAsync("Title");
            operTitle.completed += (AsyncOper) =>
            {
                Debug.Log("타이틀 씬 로드");
                var title = GameObject.FindObjectOfType<Title>();
                title.Init(this.uiCamera);
                title.OnTitleEnd = () =>
                  {
                      this.OnTitleEnd();
                  };
            };
        };
        #endregion
 
        #region 인게임 씬 로드하는 부분
        this.OnTitleEnd = () =>
          {
              var operInGame = SceneManager.LoadSceneAsync("InGame");
              operInGame.completed += (AsyncOper) =>
              {
                  Debug.Log("인게임 씬 로드");
                  var inGame = GameObject.FindObjectOfType<UIInGame>();
                  inGame.Init(this.uiCamera);
 
              };
          };
        #endregion
 
        #region 테스트용 스킵
        //로고 씬 테스트 건너뛰고 싶을 시 밑의 주석 제거
        //this.OnLogoEnd();
        //타이틀 씬 테스트 건너뛰고 싶을 시 밑의 주석 제거
        //this.OnTitleEnd();
        #endregion
    }
}
 
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
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
 
namespace SG.scenes
{
    public class InGame : MonoBehaviour
    {
        public UIInGame uiInGame;
 
        private Canvas canvas;
        private Image dim;
        private GameObject currentStage;
        private Character hero;
        private List<Character> monsters;
 
        private int posCount = 0;
 
 
        private void Awake()
        {
            //데이터 불러오기
            DataManager.GetInstance().LoadCharacterDatas("Data/character_data");
            DataManager.GetInstance().LoadMonsterGroupDatas("Data/monster_group_data");
            DataManager.GetInstance().LoadStageDatas("Data/stage_data");
 
            AssetManager.GetInstance().LoadDatas("Preloads");
 
            var characterDatas = DataManager.GetInstance();
            var monsterGroupDatas = DataManager.GetInstance();
            var stageDatas = DataManager.GetInstance();
 
 
            //스테이지 생성
            this.CreateStage(stageDatas.GetStageData(0).id);
 
            //캐릭터 생성하기(히어로)
            this.hero = this.CreateCharacter(0);
            //캐릭터 썸네일 생성하기
 
            //스테이지에 맞는 몬스터 생성하기
            this.monsters = this.CreateMonsterGroup(0);
 
            //칼만들기
            var itemPre = AssetManager.GetInstance().dicAssetData["ch_sword_01"];
            var item = Instantiate(itemPre);
            
 
            //칼 장비하기
            item.transform.SetParent(GameObject.FindGameObjectWithTag("Rweapon").transform, false);
 
            //몬스터의 썸네일 만들어놓기(?), 아니면 Character || Monster:Character 에서 쳐 맞는 순간 만들기?(띄우기?)
 
            //몬뒤시 썸네일 회색으로 만들어 3초간 유지하고 X표까지 그리면 좋고. 썸네일과 몬스터 둘다 사라지게 하기(?)
 
        }
 
        private void CreateWeapon()
        {
            
        }
 
        private List<Character> CreateMonsterGroup(int id)
        {
            //스테이지 데이터에 아이디를 입력받아, 황량한 사막의 정보를 저장함
            var stageData = DataManager.GetInstance().GetStageData(id);
 
            //스테이지에 저장된 몬스터 그룹아이디를 불러옴//100
            var monsterGroupID = stageData.monster_group_id;
 
            //몬스터들의 그룹아이디가 100인 애들을 다 가꼬옴
            var monsterDatas = DataManager.GetInstance().dicMonsterGroupData;
 
            List<Character> monsters = new List<Character>();
            foreach (var data in monsterDatas)
            {
                print(data.Value.group_no);
                if (data.Value.group_no == monsterGroupID)
                {
                    monsters.Add(CreateCharacter(data.Value.monster_id));
                }
            }
            return monsters;
        }
 
        private Character CreateCharacter(int id)
        {
            var characterData = DataManager.GetInstance().GetCharacterData(id);
            var asset = AssetManager.GetInstance().dicAssetData[characterData.prefab_name];
 
            var charGo = GameObject.Instantiate<GameObject>(asset);
            var modelPrefab = AssetManager.GetInstance().dicAssetData[characterData.prefab_name];
            var character = charGo.AddComponent<Character>();
            
            character.name = characterData.character_name;
            character.info = new SG.CharacterInfo(id, characterData.hp, new Vector3(000));
 
            var stage_01 = this.currentStage.GetComponent<Stage_01>();
 
            character.transform.position = stage_01.charactersPos[this.posCount++].transform.position;
 
            Debug.Log("캐릭터가 생성되었습니다.");
            return character;
        }
 
        private void CreateStage(int id)
        {
            var stageDatas = DataManager.GetInstance().GetStageData(id);
            var stagePrefab = AssetManager.GetInstance().dicAssetData[stageDatas.prefab_name];
            var stageGo = Instantiate(stagePrefab);
            this.currentStage = stageGo;
            stageGo.transform.position = Vector3.zero;
        }
 
        public void Init(Camera uiCamera)
        {
            this.canvas.worldCamera = uiCamera;
            Debug.Log("와 게임 시작이다!");
            //월드 생성 후 페이드 아웃
            this.uiInGame.OnFadeInComplete = () =>
            {
                Debug.Log("페이드 인 완료");
            };
            this.uiInGame.FadeIn();
        }
    }
}
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Character : MonoBehaviour
{
    private Animation anim;
    public int id;
    public GameObject model;
    public string characterName;
    public SG.CharacterInfo info;
 
    private void Awake()
    {
        this.anim = this.gameObject.GetComponent<Animation>();
    }
 
    public void Init(Vector3 initPosition)
    {
        this.gameObject.transform.position = initPosition;
    }
 
    public void Move(Vector3 targetPos)
    {
        //좌표받아 이동
    }
 
    public void Move(Character target)
    {
        //공격할 몬스터 받아서 이동
    }
 
    public void Attack(Character target)
    {
        //공격할 몬스터 받아서 이동, 후 때리기
    }
 
    public void HitDamage(int damage)
    {
        //몬스터 데미지 받기
    }
}
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
namespace SG
{
    public class MonsterGroupData
    {
        public int id;
        public int group_no;
        public int monster_id;
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
namespace SG
{
    public class CharacterData
    {
        public int id;
        public string character_name;
        public int type;
        public string prefab_name;
        public int hp;
        public string thumb_name;
        public string thumb_hex_color;
        public string idle_anim_name;
        public string run_anim_name;
        public string attack_anim_name;
        public string hit_anim_name;
        public string death_anim_name;
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
namespace SG
{
    public class CharacterInfo
    {
        public int id;
        public int hp;
        public Vector3 pos;
 
        public CharacterInfo(int id, int hp, Vector3 pos)
        {
            this.id = id;
            this.hp = hp;
            this.pos = pos;
        }
    }
}
 
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
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
namespace SG
{
    public class AssetManager
    {
        private static AssetManager Instance;
        public Dictionary<string, GameObject> dicAssetData;
 
        private AssetManager()
        {
            this.dicAssetData = new Dictionary<string, GameObject>();
        }
 
        public static AssetManager GetInstance()
        {
            if (AssetManager.Instance == null)
            {
                AssetManager.Instance = new AssetManager();
            }
            return AssetManager.Instance;
        }
 
        public void LoadDatas(string path)
        {
            var asset = Resources.LoadAll<GameObject>(path);
            foreach (var data in asset)
            {
                this.dicAssetData.Add(data.name, data);
            }
        }
    }
}
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
 
namespace SG
{
    public class DataManager
    {
        private static DataManager Instance;
        public Dictionary<int, CharacterData> dicCharacterData;
        public Dictionary<int, MonsterGroupData> dicMonsterGroupData;
        public Dictionary<int, StageData> dicStageData;
 
        private DataManager()
        {
            this.dicCharacterData = new Dictionary<int, CharacterData>();
            this.dicMonsterGroupData = new Dictionary<int, MonsterGroupData>();
            this.dicStageData = new Dictionary<int, StageData>();
        }
 
        public static DataManager GetInstance()
        {
            if (DataManager.Instance == null)
            {
                DataManager.Instance = new DataManager();
            }
            return DataManager.Instance;
        }
 
        public void LoadCharacterDatas(string path)
        {
            Debug.Log("캐릭터 데이터 로드 완료");
            var json = Resources.Load<TextAsset>(path);
            var arrDatas = JsonConvert.DeserializeObject<CharacterData[]>(json.text);
 
            foreach (var data in arrDatas)
            {
                this.dicCharacterData.Add(data.id, data);
            }
        }
 
        public void LoadMonsterGroupDatas(string path)
        {
            Debug.Log("몬스터 그룹 데이터 로드 완료");
            var json = Resources.Load<TextAsset>(path);
            var arrDatas = JsonConvert.DeserializeObject<MonsterGroupData[]>(json.text);
 
            foreach (var data in arrDatas)
            {
                this.dicMonsterGroupData.Add(data.id, data);
            }
        }
 
        public void LoadStageDatas(string path)
        {
            Debug.Log("스테이지 데이터 로드 완료");
            var json = Resources.Load<TextAsset>(path);
            var arrDatas = JsonConvert.DeserializeObject<StageData[]>(json.text);
 
            foreach (var data in arrDatas)
            {
                this.dicStageData.Add(data.id, data);
            }
        }
 
        public CharacterData GetCharacterData(int id)
        {
            return this.dicCharacterData[id];
        }
 
        public MonsterGroupData GetMonsterGroupData(int id)
        {
            return this.dicMonsterGroupData[id];
        }
 
        public StageData GetStageData(int id)
        {
            return this.dicStageData[id];
        }
    }
}
cs


:

<캐릭터 생성 월드로>한단계 진화함

Unity/과제 2019. 4. 19. 01:12



//추가할것, 링큐써서 데이터 매니져 제네릭타입으로 구현해보기( 못하겠으면 빠르게 손절하기 )( +링큐 공부 ), 몬스터 추가, 움직이기 때리기(예전에 했던거),몬스터썸네일 몬스터 때리면 뜨도록 수정

//무기줍고 때리기, 0,0,0으로 귀환하기


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
namespace SG.scenes
{
    public class App : MonoBehaviour
    {
        public Camera uiCamera;
 
        private void Awake()
        {
            //로드된 직후 호출
            Object.DontDestroyOnLoad(this);
        }
 
        // Start is called before the first frame update
        void Start()
        {
            //객체 생성시 호출
            var oper = SceneManager.LoadSceneAsync("Logo");
            oper.completed += (AsyncOper) =>
              {
                  Debug.Log("로고 씬 로드 완료");
                  var logo = GameObject.FindObjectOfType<Logo>();
                  logo.Init(this.uiCamera);
              };
        }
    }
}
 
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
namespace SG.scenes
{
    public class Logo : MonoBehaviour
    {
        public UILogo uiLogo;
        public System.Action OnWaitForSeconds;
 
        public void Init(Camera uiCamera)
        {
            this.uiLogo.OnFadeInComplete = () =>//3완료
            {
                Debug.Log("페이드 인 완료");
 
                //타이틀 씬으로 전환
                var oper = SceneManager.LoadSceneAsync("Title");
                oper.completed += (AsyncOper) =>
                {
                    Debug.Log("로고 씬 로드 완료");
                    var title = GameObject.FindObjectOfType<Title>();
                    title.Init(uiCamera);
                };
            };
            this.uiLogo.OnFadeOutComplete = () =>//1완료
            {
                Debug.Log("페이드 아웃 완료");
 
                //3초기달
                this.OnWaitForSeconds = () =>//2완료
                {
                    StartCoroutine(this.uiLogo.FadeIn());//3
                };
                StartCoroutine(this.WaitForSeconds(2));//2
            };
 
            this.uiLogo.Init(uiCamera);
            StartCoroutine(this.uiLogo.FadeOut());//1
        }
        private IEnumerator WaitForSeconds(float sec)
        {
            yield return new WaitForSeconds(sec);
            OnWaitForSeconds();
        }
    }
}
 
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class UILogo : MonoBehaviour
{
    public Canvas canvas;
    public Image dim;
    public System.Action OnFadeOutComplete;
    public System.Action OnFadeInComplete;
 
    public void Init(Camera uiCamera)
    {
        this.canvas.worldCamera = uiCamera;
    }
 
    public IEnumerator FadeOut()
    {
        var color = this.dim.color;
        float alpha = color.a;
        
        while (true)
        {
            alpha -= 0.016f;
            color.a = alpha;
            this.dim.color = color;
 
            if (alpha <= 0)
            {
                alpha = 0;
                break;
            }
            yield return null;
        }
        this.OnFadeOutComplete();
    }
 
    public IEnumerator FadeIn()
    {
        var color = this.dim.color;
        float alpha = color.a;
 
        while (true)
        {
            alpha += 0.016f;
            color.a = alpha;
            this.dim.color = color;
 
            if (alpha >= 1)
            {
                alpha = 1;
                break;
            }
            yield return null;
        }
        this.OnFadeInComplete();
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class UITitle : MonoBehaviour
{
    public Canvas canvas;
    public Image dim;
    public System.Action OnFadeOutComplete;
    public System.Action OnFadeInComplete;
    public Button btn;
 
    public void Init(Camera uiCamera)
    {
        this.canvas.worldCamera = uiCamera;
    }
 
    public IEnumerator FadeOut()
    {
        var color = this.dim.color;
        float alpha = color.a;
 
        while (true)
        {
            alpha -= 0.016f;
            color.a = alpha;
            this.dim.color = color;
 
            if (alpha <= 0)
            {
                alpha = 0;
                break;
            }
            yield return null;
        }
        this.OnFadeOutComplete();
    }
 
    public IEnumerator FadeIn()
    {
        var color = this.dim.color;
        float alpha = color.a;
 
        while (true)
        {
            alpha += 0.016f;
            color.a = alpha;
            this.dim.color = color;
 
            if (alpha >= 1)
            {
                alpha = 1;
                break;
            }
            yield return null;
        }
        this.OnFadeInComplete();
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class StageData
{
    public int id;
    public string name;
    public string prefab_name;
    public int monster_group_id;
}
 
cs

1
2
3
4
5
6
7
8
9
10
11
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class MonsterGroupData
{
    public int id;
    public int group_id;
    public int monster_id;
}
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class CharacterData
{
    public int id;
    public string character_name;
    public int type;
    public string prefab_name;
    public int hp;
    public string thumb_name;
    public string thumb_hex_color;
    public string idle_anim_name;
    public string run_anim_name;
    public string attack_anim_name;
    public string hit_anim_name;
    public string death_anim_name;
}
 
 
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SG
{
    public class CharacterInfo
    {
        public int id;
        public int hp;
        public Vector3 pos;
 
        public CharacterInfo(int id, int hp, Vector3 pos)
        {
            this.id = id;
            this.hp = hp;
            this.pos = pos;
        }
    }
}
 
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
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace SG.scenes
{
    public class InGame : MonoBehaviour
    {
        public Canvas canvas;
        public Image dim;
 
        public Character hero;
        public Character monster;
 
        public System.Action OnFadeOutComplete;
        public System.Action OnFadeInComplete;
        public System.Action OnWaitForSeconds;
 
        private void Awake()
        {
            //데이터 불러오기
            DataManager.GetInstance().LoadCharacterDatas("Data/character_data");
            DataManager.GetInstance().LoadMonsterGroupDatas("Data/monster_group_data");
            DataManager.GetInstance().LoadStageDatas("Data/stage_data");
 
            AssetManager.GetInstance().LoadDatas("PreLoad");
 
            var characterDatas = DataManager.GetInstance();
            var monsterGroupDatas = DataManager.GetInstance();
 
            //스테이지 생성
            var stageDatas = DataManager.GetInstance().GetStageData(0);
            this.CreateStage(stageDatas.id);
            //캐릭터 생성하기(히어로&&몬스터)
            this.hero = CreateCharacter(0);
 
        }
 
        private Character CreateCharacter(int id)
        {
            var data = DataManager.GetInstance().GetCharacterData(id);
            var asset = AssetManager.GetInstance().dicAssetData[data.prefab_name];
 
            var charGo = GameObject.Instantiate<GameObject>(asset);
            var modelPrefab = AssetManager.GetInstance().dicAssetData[data.prefab_name];
            var character = charGo.AddComponent<Character>();
            
            character.name= data.character_name;
            character.info = new SG.CharacterInfo(id, data.hp, new Vector3(000));
 
            if (character.info.id == 1)
            {
                character.transform.position = new Vector3(505);
            }
            else
            {
                character.transform.position = character.info.pos;
            }
 
            Debug.Log("캐릭터가 생성되었습니다.");
            return character;
        }
 
        private void CreateStage(int id)
        {
            var stageDatas = DataManager.GetInstance().GetStageData(id);
            var stagePrefab = AssetManager.GetInstance().dicAssetData[stageDatas.prefab_name];
            var stageGo = Instantiate(stagePrefab);
 
            stageGo.transform.position = Vector3.zero;
        }
 
        public void Init(Camera uiCamera)
        {
            this.canvas.worldCamera = uiCamera;
            Debug.Log("와 게임 시작이다!");
            //월드 생성 후 페이드 아웃
            this.OnFadeOutComplete = () =>
              {
                  Debug.Log("페이드 아웃완료");
              };
            StartCoroutine(this.FadeOut());
        }
 
        public IEnumerator FadeOut()
        {
            var color = this.dim.color;
            float alpha = color.a;
 
            while (true)
            {
                alpha -= 0.016f;
                color.a = alpha;
                this.dim.color = color;
 
                if (alpha <= 0)
                {
                    alpha = 0;
                    break;
                }
                yield return null;
            }
            this.OnFadeOutComplete();
        }
 
        public IEnumerator FadeIn()
        {
            var color = this.dim.color;
            float alpha = color.a;
 
            while (true)
            {
                alpha += 0.016f;
                color.a = alpha;
                this.dim.color = color;
 
                if (alpha >= 1)
                {
                    alpha = 1;
                    break;
                }
                yield return null;
            }
            this.OnFadeInComplete();
        }
 
        private IEnumerator WaitForSeconds(float sec)
        {
            yield return new WaitForSeconds(sec);
            OnWaitForSeconds();
        }
    }
}
 
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Character : MonoBehaviour
{
    private Animation anim;
    public int id;
    public GameObject model;
    public string characterName;
    public SG.CharacterInfo info;
 
    private void Awake()
    {
        this.anim = this.gameObject.GetComponent<Animation>();
    }
    
    public void Init(Vector3 initPosition)
    {
        this.gameObject.transform.position = initPosition;
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class AssetManager
{
    private static AssetManager Instance;
    public Dictionary<string, GameObject> dicAssetData;
 
    private AssetManager()
    {
        this.dicAssetData = new Dictionary<string, GameObject>();
    }
 
    public static AssetManager GetInstance()
    {
        if (AssetManager.Instance == null)
        {
            AssetManager.Instance = new AssetManager();
        }
        return AssetManager.Instance;
    }
 
    public void LoadDatas(string path)
    {
        var asset = Resources.LoadAll<GameObject>(path);
        foreach(var data in asset)
        {
            this.dicAssetData.Add(data.name, data);
        }
    }
}
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
 
public class DataManager
{
    private static DataManager Instance;
    public Dictionary<int, CharacterData> dicCharacterData;
    public Dictionary<int, MonsterGroupData> dicMonsterGroupData;
    public Dictionary<int, StageData> dicStageData;
 
    private DataManager()
    {
        this.dicCharacterData = new Dictionary<int, CharacterData>();
        this.dicMonsterGroupData = new Dictionary<int, MonsterGroupData>();
        this.dicStageData = new Dictionary<int, StageData>();
    }
 
    public static DataManager GetInstance()
    {
        if (DataManager.Instance == null)
        {
            DataManager.Instance = new DataManager();
        }
        return DataManager.Instance;
    }
 
    public void LoadCharacterDatas(string path)
    {
        Debug.Log("캐릭터 데이터 로드 완료");
        var json = Resources.Load<TextAsset>(path);
        var arrDatas = JsonConvert.DeserializeObject<CharacterData[]>(json.text);
 
        foreach (var data in arrDatas)
        {
            this.dicCharacterData.Add(data.id, data);
        }
    }
 
    public void LoadMonsterGroupDatas(string path)
    {
        Debug.Log("몬스터 그룹 데이터 로드 완료");
        var json = Resources.Load<TextAsset>(path);
        var arrDatas = JsonConvert.DeserializeObject<MonsterGroupData[]>(json.text);
 
        foreach (var data in arrDatas)
        {
            this.dicMonsterGroupData.Add(data.id, data);
        }
    }
 
    public void LoadStageDatas(string path)
    {
        Debug.Log("스테이지 데이터 로드 완료");
        var json = Resources.Load<TextAsset>(path);
        var arrDatas = JsonConvert.DeserializeObject<StageData[]>(json.text);
 
        foreach (var data in arrDatas)
        {
            this.dicStageData.Add(data.id, data);
        }
    }
 
    public CharacterData GetCharacterData(int id)
    {
        return this.dicCharacterData[id];
    }
 
    public MonsterGroupData GetMonsterGroupData(int id)
    {
        return this.dicMonsterGroupData[id];
    }
 
    public StageData GetStageData(int id)
    {
        return this.dicStageData[id];
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
 
namespace SG.scenes
{
    public class Title : MonoBehaviour
    {
        public UITitle uiTitle;
        public Camera uiCamera;
        public bool isRead;
 
        private void Awake()
        {
            this.uiTitle.btn.onClick.AddListener(() => 
            {
                if (!isRead)
                {
                    Debug.Log("아직 실행이 준비되지 않았습니다.");
                }
                else
                {
                    //인게임 실행
                    var oper = SceneManager.LoadSceneAsync("InGame");
                    oper.completed += (AsyncOper) =>
                    {
                        Debug.Log("인게임씬 로드 완료");
                        var inGame = GameObject.FindObjectOfType<InGame>();
                        inGame.Init(this.uiCamera);
                    };
                }
            });
 
        }
 
        public void Init(Camera uiCamera)
        {
            this.uiCamera = uiCamera;
            this.uiTitle.Init(uiCamera);
            this.uiTitle.OnFadeOutComplete = () =>
            {
                Debug.Log("똬이럴실행");
                isRead = true;
            };
            StartCoroutine(this.uiTitle.FadeOut());
        }
    }
}
 
cs


'Unity > 과제' 카테고리의 다른 글

<설계구조를 다시 짜보았다.>  (0) 2019.04.21
<데이터 로드, 월드 구성, by포토샵>미완성  (0) 2019.04.18
:

<데이터 로드, 월드 구성, by포토샵>미완성

Unity/과제 2019. 4. 18. 00:34


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
namespace SG.scenes
{
    public class App : MonoBehaviour
    {
        public Camera uiCamera;
 
        private void Awake()
        {
            //로드된 직후 호출
            Object.DontDestroyOnLoad(this);
        }
 
        // Start is called before the first frame update
        void Start()
        {
            //객체 생성시 호출
            var oper = SceneManager.LoadSceneAsync("Logo");
            oper.completed += (AsyncOper) =>
              {
                  Debug.Log("로고 씬 로드 완료");
                  var logo = GameObject.FindObjectOfType<Logo>();
                  logo.Init(this.uiCamera);
              };
        }
    }
}
 
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
namespace SG.scenes
{
    public class Logo : MonoBehaviour
    {
        public UILogo uiLogo;
        public System.Action OnWaitForSeconds;
 
        public void Init(Camera uiCamera)
        {
            this.uiLogo.OnFadeInComplete = () =>//3완료
            {
                Debug.Log("페이드 인 완료");
 
                //타이틀 씬으로 전환
                var oper = SceneManager.LoadSceneAsync("Title");
                oper.completed += (AsyncOper) =>
                {
                    Debug.Log("로고 씬 로드 완료");
                    var title = GameObject.FindObjectOfType<Title>();
                    title.Init(uiCamera);
                };
            };
            this.uiLogo.OnFadeOutComplete = () =>//1완료
            {
                Debug.Log("페이드 아웃 완료");
 
                //3초기달
                this.OnWaitForSeconds = () =>//2완료
                {
                    StartCoroutine(this.uiLogo.FadeIn());//3
                };
                StartCoroutine(this.WaitForSeconds(2));//2
            };
 
            this.uiLogo.Init(uiCamera);
            StartCoroutine(this.uiLogo.FadeOut());//1
        }
        private IEnumerator WaitForSeconds(float sec)
        {
            yield return new WaitForSeconds(sec);
            OnWaitForSeconds();
        }
    }
}
 
 
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
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
 
public class AssetManager
{
    public enum eDataType
    {
        None = -1,
        CharacterData,
        MonsterGroupData,
        StageData
    }
 
    private static AssetManager Instance;
    public Dictionary<string, GameObject> dicAssetData;
 
    private AssetManager()
    {
        this.dicAssetData = new Dictionary<string, GameObject>();
    }
 
    public static AssetManager GetInstance()
    {
        if (AssetManager.Instance == null)
        {
            AssetManager.Instance = new AssetManager();
        }
        return AssetManager.Instance;
    }
 
    public void LoadDatas<T>(string path)
    {
        var asset = Resources.Load<TextAsset>(path);
        var arrDatas = JsonConvert.DeserializeObject<T[]>(asset.text);
        foreach(var data in arrDatas)
        {
            //데이터 넣기
        }
    }
}
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
 
public class DataManager
{
    public enum eDataType
    {
        None = -1,
        CharacterData,
        MonsterGroupData,
        StageData
    }
 
    private static DataManager Instance;
    public Dictionary<int, CharacterData> dicCharacterData = new Dictionary<int, CharacterData>();
    public Dictionary<int, MonsterGroupData> dicMonsterGroupData = new Dictionary<int, MonsterGroupData>();
    public Dictionary<int, StageData> dicStageData = new Dictionary<int, StageData>();
 
    private DataManager()
    {
 
    }
 
    public static DataManager GetInstance()
    {
        if (DataManager.Instance == null)
        {
            DataManager.Instance = new DataManager();
        }
        return DataManager.Instance;
    }
 
    public void LoadDatas<T>(string path, eDataType dataType)
    {
        var asset = Resources.Load<TextAsset>(path);
        var arrDatas = JsonConvert.DeserializeObject<T[]>(asset.text);
        foreach(var data in arrDatas)
        {
            //데이터 넣기
        }
    }
}
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
 
namespace SG.scenes
{
    public class Title : MonoBehaviour
    {
        public UITitle uiTitle;
        public Camera uiCamera;
        public bool isRead;
 
        private void Awake()
        {
            this.uiTitle.btn.onClick.AddListener(() => 
            {
                if (!isRead)
                {
                    Debug.Log("아직 실행이 준비되지 않았습니다.");
                }
                else
                {
                    //인게임 실행
                    var oper = SceneManager.LoadSceneAsync("InGame");
                    oper.completed += (AsyncOper) =>
                    {
                        Debug.Log("인게임씬 로드 완료");
                        var inGame = GameObject.FindObjectOfType<InGame>();
                        inGame.Init(this.uiCamera);
                    };
                }
            });
 
        }
 
        public void Init(Camera uiCamera)
        {
            this.uiCamera = uiCamera;
            this.uiTitle.Init(uiCamera);
            this.uiTitle.OnFadeOutComplete = () =>
            {
                Debug.Log("똬이럴실행");
                isRead = true;
            };
            StartCoroutine(this.uiTitle.FadeOut());
        }
    }
}
 
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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace SG.scenes
{
    public class InGame : MonoBehaviour
    {
        public Canvas canvas;
        public Image dim;
        public GameObject heroGo;
        public GameObject monsterGo;
        public System.Action OnFadeOutComplete;
        public System.Action OnFadeInComplete;
 
        private void Awake()
        {
            DataManager.GetInstance().LoadDatas<Character>("Data/character_data"0);
            DataManager.GetInstance().LoadDatas<MonsterGroupData>("Data/monster_group_data"0);
            DataManager.GetInstance().LoadDatas<StageData>("Data/stage_data"0);
        }
 
        public void Init(Camera uiCamera)
        {
            this.canvas.worldCamera = uiCamera;
            Debug.Log("와 게임 시작이다!");
            var hero = this.heroGo.GetComponent<Character>();
            var monster = this.monsterGo.GetComponent<Character>();
            //System.Action OnFadeOutComplete = () =>
            //  {
            //      System.Action OnFadeInComplete = () =>
            //      {
 
            //      };
            //      this.FadeIn();
            //  };
            //this.Fadeout();
        }
 
        private void PreLoad()
        {
            var arrObject=  Resources.LoadAll("PreFabs");
            foreach(var obj in arrObject)
            {
                //데이터 넣기
            }
        }
 
        public void Fadeout()
        {
            StartCoroutine(FadeOutImpl());
        }
 
        public IEnumerator FadeOutImpl()
        {
            var color = this.dim.color;
            float alpha = color.a;
 
            while (true)
            {
                alpha -= 0.016f;
                color.a = alpha;
                this.dim.color = color;
 
                if (alpha <= 0)
                {
                    alpha = 0;
                    break;
                }
                yield return null;
            }
            this.OnFadeOutComplete();
        }
 
        public void FadeIn()
        {
            StartCoroutine(FadeInImpl());
        }
        public IEnumerator FadeInImpl()
        {
            var color = this.dim.color;
            float alpha = color.a;
 
            while (true)
            {
                alpha += 0.016f;
                color.a = alpha;
                this.dim.color = color;
 
                if (alpha >= 1)
                {
                    alpha = 1;
                    break;
                }
                yield return null;
            }
            this.OnFadeInComplete();
        }
    }
}
 
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class StageData
{
    public int id;
    public string name;
    public string prefab_name;
    public int monster_group_id;
}
 
cs

1
2
3
4
5
6
7
8
9
10
11
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class MonsterGroupData
{
    public int id;
    public int group_id;
    public int monster_id;
}
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
namespace SG.scenes
{
    public class CharacterData
    {
        public int id;
        public string name;
        public string prefab_name;
        public string thumb_name;
        public string thumb_hex_color;
        public string idle_anim_name;
        public string run_anim_name;
        public string attack_anim_name;
        public string hit_anim_name;
        public string death_anim_name;
    }
}
 
 
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class TestAttackAnim : MonoBehaviour
{
    public GameObject bullGo;
    public Button btn1;
    public Button btn2;
    public Button btn3;
    private Animator anim;
 
    // Start is called before the first frame update
    private void Awake()
    {
        this.anim = this.bullGo.GetComponent<Animator>();
 
        this.btn1.onClick.AddListener(() =>
        {
            this.anim.SetBool("idle"true);
        });
        this.btn2.onClick.AddListener(() =>
        {
            this.anim.SetBool("run"true);
        });
        this.btn3.onClick.AddListener(() =>
        {
            this.anim.SetBool("attack_01"true);
            StartCoroutine(this.WaitforAttacComplete(() =>
            {
                Debug.Log("타격!");
            }, () =>
            {
                Debug.Log("공격끝");
            }));
        });
    }
    private IEnumerator WaitforAttacComplete(System.Action onAttack, System.Action onAttackComplete)
    {
        yield return new WaitForSeconds(0.75f);
        onAttack();
        yield return new WaitForSeconds(0.25f);
        onAttackComplete();
    }
}
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class UITitle : MonoBehaviour
{
    public Canvas canvas;
    public Image dim;
    public System.Action OnFadeOutComplete;
    public System.Action OnFadeInComplete;
    public Button btn;
 
    public void Init(Camera uiCamera)
    {
        this.canvas.worldCamera = uiCamera;
    }
 
    public IEnumerator FadeOut()
    {
        var color = this.dim.color;
        float alpha = color.a;
 
        while (true)
        {
            alpha -= 0.016f;
            color.a = alpha;
            this.dim.color = color;
 
            if (alpha <= 0)
            {
                alpha = 0;
                break;
            }
            yield return null;
        }
        this.OnFadeOutComplete();
    }
 
    public IEnumerator FadeIn()
    {
        var color = this.dim.color;
        float alpha = color.a;
 
        while (true)
        {
            alpha += 0.016f;
            color.a = alpha;
            this.dim.color = color;
 
            if (alpha >= 1)
            {
                alpha = 1;
                break;
            }
            yield return null;
        }
        this.OnFadeInComplete();
    }
}
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Character : MonoBehaviour
{
    private Animation anim;
 
    private void Awake()
    {
        this.anim = this.gameObject.GetComponent<Animation>();
    }
 
    public void Init(Vector3 initPosition)
    {
        this.gameObject.transform.position = initPosition;
    }
}
 
cs


'Unity > 과제' 카테고리의 다른 글

<설계구조를 다시 짜보았다.>  (0) 2019.04.21
<캐릭터 생성 월드로>한단계 진화함  (0) 2019.04.19
:

GameObject, TimedeltaTime

Unity/찾아본것 2019. 4. 14. 22:37

게임 오브젝트

└컴포넌트

└트랜스폼

└프리팹

└정적 게임오브젝트

└런타임시 프리팹의 인스턴스화

└작업저장


게임오브젝트

게임오브젝트는 유니티에디터에서 가장 중요한 개념이다.

게임에 존재하는 모든 오브젝트가 게임 오브젝트이다.

게임오브젝트 자체로는 아무것도 할 수 없고, 게임 오브젝트가 캐릭터,환경,특수효과가 되기 위해선 ?프로퍼티를 부여해야한다.

?프로퍼티 : 값


컴포넌트

게임 오브젝트가 포함하는 프로퍼티(값)들

기본적으로 모든 오브젝트는 Transform(좌표위치Position, 회전각도Rotation, 크기Scale)을 가지고 있다..


정적 게임 오브젝트(Static GameObject)

게임의 최적화를 위해서 게임플레이중 움직이지 않는 오브젝트는 정적 오브젝트로하여

정적오브젝트 들을 '배치(arrangement)'라는 큰 오브젝트로 결합시켜 렌더링을 최적화 할 수 있다.

게임오브젝트 인스펙터 맨 오른쪽 상단에는 정적 체크박스 및 메뉴가 있다.


프리팹

오브젝트를 복사하기만 하면, 복제본이 생성되지만 개별편집 할 수 있습니다.

일반적으로 모든 인스턴스가 동일한 프로퍼티를 가지는 것이 좋다.


프리팹 에셋타입으로 오브젝트를 저장할 수 있다

프리팹은 씬에서 새로운 오브젝트인스턴스를 생성할 수 있는 템플릿으로 사용됩니다.

인스턴스의 각 컴포넌트와 설정을 개별적으로 '오버라이드' 할 수도 있음.


Time.deltaTime

public static float deltaTime;

지난프레임이 완료되는 데 까지 걸린 시간을 나타낸다. 단위는초를 사용한다(읽기전용)


사용자의 frame rate를 독립적으로 적용하기 위해 사용함.


매 프레임마다 어떤값을 더하거나 빼는 계산을 하는 경우에 Time.deltaTime을 곱해서 사용한다.

ex)오브젝트를 프레임당 10미터가 아닌 초당 10미터를 움직이고 싶은 경우


?MonoBehaviour의 ?FixedUpdate에서 호출되는 경우에 고정 프레임률 deltaTime을 반환한다.


?MonoBehaviour

모든 스크립트가 상속받는 기본 클래스


?MonoBehaviour.FixedUpdate()

MonoBehaviour이 활성화 되어 있는 경우에, 매 고정된 프레임율의 프레임 마다 호출됩니다.

Time.deltaTime을 사용하여, 지난 Update호출로부터 경과된 시간을 받아옵니다.

: