<설계구조를 다시 짜보았다.>
Unity/과제 2019. 4. 21. 23:341 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(0, 0, 0)); 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 > 과제' 카테고리의 다른 글
<캐릭터 생성 월드로>한단계 진화함 (0) | 2019.04.19 |
---|---|
<데이터 로드, 월드 구성, by포토샵>미완성 (0) | 2019.04.18 |