몬스터 json 로드를 위한 코드 추가
This commit is contained in:
44
Gameton-06/Assets/Gameton/Resources/GameData/monster.json
Normal file
44
Gameton-06/Assets/Gameton/Resources/GameData/monster.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "blueDragon",
|
||||||
|
"level": 1,
|
||||||
|
"hp": 10,
|
||||||
|
"attackPower": 35,
|
||||||
|
"defencePower": 36,
|
||||||
|
"monsterSkillID": "S001",
|
||||||
|
"patrolRange": 1,
|
||||||
|
"detectionRange": 1,
|
||||||
|
"chaseRange": 1,
|
||||||
|
"moveSpeed": 1,
|
||||||
|
"attackRange": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "greenDragon",
|
||||||
|
"level": 1,
|
||||||
|
"hp": 10,
|
||||||
|
"attackPower": 35,
|
||||||
|
"defencePower": 36,
|
||||||
|
"monsterSkillID": "S001",
|
||||||
|
"patrolRange": 1,
|
||||||
|
"detectionRange": 1,
|
||||||
|
"chaseRange": 1,
|
||||||
|
"moveSpeed": 1,
|
||||||
|
"attackRange": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "redDragon",
|
||||||
|
"level": 1,
|
||||||
|
"hp": 10,
|
||||||
|
"attackPower": 35,
|
||||||
|
"defencePower": 36,
|
||||||
|
"monsterSkillID": "S001",
|
||||||
|
"patrolRange": 1,
|
||||||
|
"detectionRange": 1,
|
||||||
|
"chaseRange": 1,
|
||||||
|
"moveSpeed": 1,
|
||||||
|
"attackRange": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 18f338c4715910e46b8df365a52142db
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
51
Gameton-06/Assets/Gameton/Scripts/GameData/MonsterData.cs
Normal file
51
Gameton-06/Assets/Gameton/Scripts/GameData/MonsterData.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
public class MonsterData
|
||||||
|
{
|
||||||
|
// 몬스터 아이디
|
||||||
|
public int id;
|
||||||
|
// 몬스터 명 or 프리팹 명?
|
||||||
|
public string name;
|
||||||
|
// 몬스터 레벨
|
||||||
|
public int level;
|
||||||
|
// 몬스터 타입 ex : melee, ranged
|
||||||
|
public string monsterType;
|
||||||
|
// 몬스터 체력
|
||||||
|
public int hp;
|
||||||
|
// 기본 공격력
|
||||||
|
public int attackPower;
|
||||||
|
// 기본 방어력
|
||||||
|
public int defensivePower;
|
||||||
|
// 몬스터 스킬 ID
|
||||||
|
public string monsterSkillID;
|
||||||
|
// 패트롤 범위
|
||||||
|
public float patrolRange;
|
||||||
|
// 인식 범위
|
||||||
|
public float detectionRange;
|
||||||
|
// 추적 범위
|
||||||
|
public float chaseRange;
|
||||||
|
// 공격 범위
|
||||||
|
public float attackRange;
|
||||||
|
|
||||||
|
public MonsterData(int id, string name, int level, string monsterType, int hp, int attackPower, int defensivePower, int monsterSkillID, float patrolRange, float detectionRange, float chaseRange, float attackRange)
|
||||||
|
{
|
||||||
|
id = id;
|
||||||
|
name = name;
|
||||||
|
level = level;
|
||||||
|
monsterType = monsterType;
|
||||||
|
hp = hp;
|
||||||
|
attackPower = attackPower;
|
||||||
|
defensivePower = defensivePower;
|
||||||
|
monsterSkillID = monsterSkillID;
|
||||||
|
patrolRange = patrolRange;
|
||||||
|
detectionRange = detectionRange;
|
||||||
|
chaseRange = chaseRange;
|
||||||
|
attackRange = attackRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace TON
|
|
||||||
{
|
|
||||||
[System.Serializable]
|
|
||||||
public class MonsterData
|
|
||||||
{
|
|
||||||
// 몬스터 아이디
|
|
||||||
public int id;
|
|
||||||
// 몬스터 명 or 프리팹 명?
|
|
||||||
public string name;
|
|
||||||
// 몬스터 타입 ex : melee, ranged
|
|
||||||
public string monsterType;
|
|
||||||
// 몬스터 체력
|
|
||||||
public int hp;
|
|
||||||
|
|
||||||
// 기본 공격력
|
|
||||||
public int attackPower;
|
|
||||||
// 기본 방어력
|
|
||||||
public int defensivePower;
|
|
||||||
|
|
||||||
public MonsterData(int id, string monsterType, string name, int hp, int attackPower, int defensivePower)
|
|
||||||
{
|
|
||||||
id = this.id;
|
|
||||||
monsterType = this.monsterType == "monster" ? "melle" : "ranged";
|
|
||||||
name = this.name;
|
|
||||||
hp = this.hp;
|
|
||||||
attackPower = this.attackPower;
|
|
||||||
defensivePower = this.defensivePower;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,72 +8,47 @@ namespace TON
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class MonsterDataManager : MonoBehaviour
|
public class MonsterDataManager : SingletonBase<MonsterDataManager>
|
||||||
{
|
{
|
||||||
public static MonsterDataManager Instance { get; private set; }
|
// 전체 몬스터 데이터 리스트
|
||||||
public Dictionary<int, MonsterData> monsterDataDict = new Dictionary<int, MonsterData>();
|
public List<MonsterData> monstersData { get; private set; }
|
||||||
|
|
||||||
// void Awake()
|
// 현재 선택된 몬스터 데이터
|
||||||
// {
|
public MonsterData currentMonster { get; private set; }
|
||||||
// if (Instance == null)
|
|
||||||
// {
|
|
||||||
// Instance = this;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// Destroy(gameObject);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// LoadMonsterData("monster_data.csv"); // CSV 파일 이름
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void LoadMonsterData(string fileName)
|
protected override void Awake()
|
||||||
// {
|
{
|
||||||
// List<string[]> data = ReadCSV(fileName);
|
base.Awake();
|
||||||
//
|
LoadMonsterData();
|
||||||
// // 첫 번째 행은 헤더이므로 건너뜀
|
}
|
||||||
// for (int i = 1; i < data.Count; i++)
|
|
||||||
// {
|
private void LoadMonsterData()
|
||||||
// string[] row = data[i];
|
{
|
||||||
// MonsterData monsterData = new MonsterData();
|
monstersData = JSONLoader.LoadFromResources<List<MonsterData>>("Monster");
|
||||||
//
|
if (monstersData == null)
|
||||||
// monsterData.id = int.Parse(row[0]);
|
{
|
||||||
// monsterData.name = row[1];
|
monstersData = new List<MonsterData>();
|
||||||
// monsterData.attackPower = int.Parse(row[2]);
|
Debug.LogError("몬스터 데이터 로드 실패");
|
||||||
// monsterData.health = int.Parse(row[3]);
|
}
|
||||||
// monsterData.speed = float.Parse(row[4]);
|
}
|
||||||
//
|
|
||||||
// monsterDataDict.Add(monsterData.id, monsterData);
|
public MonsterData GetMonsterData(int monsterId)
|
||||||
// }
|
{
|
||||||
// }
|
if (monsterId >= 0 && monsterId < monstersData.Count)
|
||||||
//
|
{
|
||||||
// List<string[]> ReadCSV(string fileName)
|
currentMonster = monstersData[monsterId];
|
||||||
// {
|
return currentMonster;
|
||||||
// List<string[]> data = new List<string[]>();
|
}
|
||||||
// TextAsset textAsset = Resources.Load<TextAsset>(fileName); // Resources 폴더에서 파일 로드
|
else
|
||||||
//
|
{
|
||||||
// using (StringReader reader = new StringReader(textAsset.text))
|
Debug.LogError($"유효하지 않은 몬스터 ID입니다: {monsterId}");
|
||||||
// {
|
return null;
|
||||||
// while (!reader.EndOfStream)
|
}
|
||||||
// {
|
}
|
||||||
// string line = reader.ReadLine();
|
|
||||||
// string[] row = line.Split(',');
|
public List<MonsterData> GetAllMonsterData()
|
||||||
// data.Add(row);
|
{
|
||||||
// }
|
return monstersData;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return data;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 몬스터 데이터 클래스
|
|
||||||
public class MonsterData
|
|
||||||
{
|
|
||||||
public int id;
|
|
||||||
public string name;
|
|
||||||
public int attackPower;
|
|
||||||
public int health;
|
|
||||||
public float speed;
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace TON
|
|
||||||
{
|
|
||||||
[System.Serializable]
|
|
||||||
|
|
||||||
public class MonsterSkillData
|
|
||||||
{
|
|
||||||
public int id; // 몬스터 id
|
|
||||||
public string skillType; // 스킬 타입(공격, 근거리, 원거리)
|
|
||||||
public int damage; // 스킬 피해량
|
|
||||||
public float coolTime; // 스킬 쿨타임
|
|
||||||
public float skillRange; // 스킬 범위(콜라이더 조정)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 68285054ac94bb741b8b33e422a9e28c
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Reference in New Issue
Block a user