Commit 410e7a47 authored by 18손재민's avatar 18손재민

json 파일로부터 맵 로드 기능 구현 완료, 오류 수정 중

parent ebe702c7
......@@ -46,6 +46,7 @@ MonoBehaviour:
isMapEditingOn: 0
surface: {fileID: 0}
currentMap: {fileID: 0}
emptyMap: {fileID: 630498074781569474, guid: 759f352c81f1b5a40b2d8d241cdf273b, type: 3}
floor: {fileID: 19711883686801522, guid: 71931eea896a59a4683986cfd369b8ee, type: 3}
normalWall: {fileID: 2953616027608884528, guid: a4dcd71ec9f819f4e88c7b5ac24f4b0d,
type: 3}
......@@ -69,4 +70,4 @@ MonoBehaviour:
players: []
player: {fileID: 494213313239918027, guid: 449b2ca4d925da541bb45c84b63aab98, type: 3}
stage:
- {fileID: 2496973653136699540, guid: dbb2e09c19fe5ad49b11a6b95e5ac9e8, type: 3}
- {fileID: 4900000, guid: b6ac683d8d1b9b44699880e1c2bf9828, type: 3}
......@@ -1138,7 +1138,12 @@ PrefabInstance:
type: 3}
propertyPath: stage.Array.data[0]
value:
objectReference: {fileID: 3529117415661273963, guid: 3d35fd3e6a494bc42921ce1cd03fc637,
objectReference: {fileID: 4900000, guid: 9bcb1c6d3d1a47046806d043fdde78d7, type: 3}
- target: {fileID: 3268100033343711389, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: emptyMap
value:
objectReference: {fileID: 630498074781569474, guid: 759f352c81f1b5a40b2d8d241cdf273b,
type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 11285456de5f1854d947bea83275646f, type: 3}
......@@ -1149,11 +1154,6 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7277015661519863741, guid: 20dee07e28273f049a9093ae4453912f,
type: 3}
propertyPath: m_NavMeshData
value:
objectReference: {fileID: 0}
- target: {fileID: 7277015661519863740, guid: 20dee07e28273f049a9093ae4453912f,
type: 3}
propertyPath: m_Name
......@@ -1219,5 +1219,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7277015661519863741, guid: 20dee07e28273f049a9093ae4453912f,
type: 3}
propertyPath: m_NavMeshData
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 20dee07e28273f049a9093ae4453912f, type: 3}
public enum TileMode
{
None, Floor, Normal, Mirror, StartFloor,
Briefcase, Camera, WMannequin, BMannequin, goalFloor
}
public enum ClearType
{
NFloor,
NTurret,
NCase,
NPlayer,
AllFloor,
AllTurret,
AllCase,
White,
Black
}
public enum WallType
{
NULL,
Normal,
Mirror
}
public enum ObjType
{
NULL,
Briefcase,
Camera,
Mannequin
}
\ No newline at end of file
fileFormatVersion: 2
guid: e65075a85c136f94082fa7468adae02f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,14 +2,6 @@
using System.Collections.Generic;
using UnityEngine;
public enum ObjType
{
NULL,
Briefcase,
Camera,
Mannequin
}
public interface IObject
{
void Init(Floor floor);
......
......@@ -12,9 +12,15 @@ public class GameManager : SingletonBehaviour<GameManager>
public int clearCounter = 0;
public static int nFloor, nTurret, nCase, nPlayer, aFloor, aTurret, aCase, white, black;
//Reset clear index to -1.
public void ResetClearIndex()
{
nFloor = nTurret = nCase = nPlayer = aFloor = aTurret = aCase = white = black = -1;
}
//Find and set the index of clear conditions of the map to clear type.
public void SetClearIndex(Map map)
{
for (int i = 0; i < 9; i++) clearIndex[i] = -1;
foreach (var child in map.clearConditions)
{
clearIndex[(int)child.type] = map.clearConditions.IndexOf(child);
......
......@@ -8,7 +8,7 @@ public class MapManager : SingletonBehaviour<MapManager>
{
public bool isMapEditingOn;
public NavMeshSurface surface;
public Map currentMap;
public Map currentMap, emptyMap;
[Header("Instances")]
public Floor floor;
public NormalWall normalWall;
......@@ -20,13 +20,70 @@ public class MapManager : SingletonBehaviour<MapManager>
public GameObject[] mannequins;
public List<GameObject> players;
public GameObject player;
public Map[] stage;
public TextAsset[] stage;
public BulletFactory bulletFactory;
public void LoadMap(Map _newMap)
/// <summary>
/// Load and make a map by map data json file.
/// </summary>
/// <param name="_newMap">The json file of the map data to be created.</param>
public void LoadMap(TextAsset _newMap)
{
//var loadedMapData = JsonConvert.DeserializeObject<MapEditor.MapSaveData>(_newMap.ToString());
//loadedMapData.
if (currentMap != null)
Destroy(currentMap.gameObject);
var loadedMapData = JsonConvert.DeserializeObject<MapEditor.MapSaveData>(_newMap.ToString());
currentMap = Instantiate(emptyMap, new Vector3(0, 0, 0), Quaternion.identity);
GameManager.inst.ResetClearIndex();
currentMap.InitiateMap();
currentMap.maxMapSize = (int)loadedMapData.objects[0].xPos;
for(int i = 1; i < loadedMapData.objects.Count; i++)
{
var temp = loadedMapData.objects[i];
switch (temp.tag)
{
case TileMode.Floor:
currentMap.CreateFloor(new Vector2Int((int)temp.xPos, (int)temp.yPos));
break;
case TileMode.Normal:
currentMap.CreateWall(new Vector2(temp.xPos, temp.yPos), WallType.Normal);
break;
case TileMode.Mirror:
currentMap.CreateWall(new Vector2(temp.xPos, temp.yPos), WallType.Mirror);
break;
case TileMode.StartFloor:
currentMap.startFloors.Add(currentMap.GetFloorAtPos(new Vector2Int((int)temp.xPos, (int)temp.yPos)));
break;
case TileMode.Briefcase:
currentMap.CreateObject(new Vector2Int((int)temp.xPos, (int)temp.yPos), ObjType.Briefcase);
break;
case TileMode.Camera:
currentMap.CreateObject(new Vector2Int((int)temp.xPos, (int)temp.yPos), ObjType.Camera);
break;
case TileMode.WMannequin:
currentMap.CreateObject(new Vector2Int((int)temp.xPos, (int)temp.yPos), ObjType.Mannequin, true);
break;
case TileMode.BMannequin:
currentMap.CreateObject(new Vector2Int((int)temp.xPos, (int)temp.yPos), ObjType.Mannequin, false);
break;
case TileMode.goalFloor:
currentMap.GetFloorAtPos(new Vector2Int((int)temp.xPos, (int)temp.yPos)).isGoalFloor = true;
break;
default:
break;
}
}
for (int i = 0; i < loadedMapData.clears.Count; i++)
{
var temp = loadedMapData.clears[i];
currentMap.clearConditions.Add(new ClearCondition(temp.type, temp.goal));
}
GameManager.inst.SetClearIndex(currentMap);
surface.BuildNavMesh();
GameManager.inst.uiGenerator.GenerateAllClearUI();
for (int i = 0; i < currentMap.startFloors.Count; i++)
PlayerController.inst.CreatePlayer(currentMap.startFloors[i]);
for (int i = 0; i < currentMap.initialBullets.Count; i++)
PlayerController.inst.bulletList.Add(currentMap.initialBullets[i]);
/*if (currentMap != null)
......
......@@ -2,18 +2,6 @@
using System.Collections.Generic;
using UnityEngine;
public enum ClearType
{
NFloor,
NTurret,
NCase,
NPlayer,
AllFloor,
AllTurret,
AllCase,
White,
Black
}
[System.Serializable]
public class ClearCondition
......@@ -24,12 +12,12 @@ public class ClearCondition
public bool isDone = false;
public ClearStatusUI assignedClearUI;
/*public ClearCondition(ClearType _type, int _goal)
public ClearCondition(ClearType _type, int _goal)
{
type = _type;
goal = _goal;
count = 0;
}*/
}
public void IsDone(int _count = 0, int _goal = 0)
{
......
......@@ -297,7 +297,7 @@ public class Map : MonoBehaviour
private void Awake()
{
LoadObjects();
//LoadObjects();
}
// Start is called before the first frame update
......
......@@ -2,13 +2,6 @@
using System.Collections.Generic;
using UnityEngine;
public enum WallType
{
NULL,
Normal,
Mirror
}
public class Wall : MonoBehaviour
{
/// <summary>
......
......@@ -16,19 +16,33 @@ public class MapEditor : SingletonBehaviour<MapEditor>
tag = _tag; xPos = _pos.x; yPos = _pos.y;
}
}
public class clearData
{
public ClearType type;
public int goal;
public clearData(ClearType _type, int _goal)
{
type = _type; goal = _goal;
}
}
public class MapSaveData
{
public List<objectData> objects;
public List<clearData> clears;
public MapSaveData()
{
objects = new List<objectData>();
clears = new List<clearData>();
}
public void AddObject(TileMode _tag, Vector2 _pos)
{
objects.Add(new objectData(_tag, _pos));
}
public void AddClears(ClearType _type, int _goal)
{
clears.Add(new clearData(_type, _goal));
}
}
public enum TileMode { None, Floor, Normal, Mirror, StartFloor, Briefcase, Camera, WMannequin, BMannequin, goalFloor };
public Map currentMap;
public Map[] stage;
public MapEditorTile tile;
......@@ -57,7 +71,7 @@ public class MapEditor : SingletonBehaviour<MapEditor>
public void SaveMap(Map _newMap)
{
System.DateTime time = System.DateTime.Now;
string localPath = Application.dataPath + time.ToShortDateString() + "-" + time.Hour + "-" + time.Minute + "-" + time.Second + ".json";
string localPath = "Assets/" + time.ToShortDateString() + "-" + time.Hour + "-" + time.Minute + "-" + time.Second + ".json";
if(currentMap.startFloors.Count == 0)
Debug.Log("There is no start floor.");
else
......@@ -99,6 +113,8 @@ public class MapEditor : SingletonBehaviour<MapEditor>
mapSaveData.AddObject(TileMode.BMannequin, temp.GetPos());
}
}
for(int i = 0; i < currentMap.clearConditions.Count; i++)
mapSaveData.AddClears(currentMap.clearConditions[i].type, currentMap.clearConditions[i].goal);
File.WriteAllText(localPath, JsonConvert.SerializeObject(mapSaveData));
Debug.Log("Map saved at " + localPath);}
}
......
......@@ -44,10 +44,6 @@ public class TestTools : MonoBehaviour
{
MapManager.inst.currentMap.RemoveObject(new Vector2Int(int.Parse(xInput.text), int.Parse(yInput.text)));
}
public void LoadMap()
{
MapManager.inst.LoadMap(MapManager.inst.stage[1]);
}
// Start is called before the first frame update
void Start()
......
{"objects":[{"tag":0,"xPos":25.0,"yPos":0.0},{"tag":1,"xPos":-1.0,"yPos":0.0},{"tag":1,"xPos":-1.0,"yPos":1.0},{"tag":1,"xPos":0.0,"yPos":0.0},{"tag":1,"xPos":-1.0,"yPos":-1.0},{"tag":1,"xPos":0.0,"yPos":-1.0},{"tag":1,"xPos":2.0,"yPos":2.0},{"tag":1,"xPos":-2.0,"yPos":-2.0},{"tag":1,"xPos":-2.0,"yPos":2.0},{"tag":1,"xPos":2.0,"yPos":-2.0},{"tag":4,"xPos":-1.0,"yPos":0.0}]}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment