Commit 201277f9 authored by 15박보승's avatar 15박보승

Merge remote-tracking branch 'origin/map'

parents 33bb28ea b84d8cf3
This source diff could not be displayed because it is too large. You can view the blob instead.
{"objects":[{"tag":0,"xPos":10.0,"yPos":0.0},{"tag":3,"xPos":0.5,"yPos":-1.0},{"tag":1,"xPos":0.0,"yPos":0.0},{"tag":9,"xPos":0.0,"yPos":0.0},{"tag":1,"xPos":0.0,"yPos":-1.0},{"tag":4,"xPos":0.0,"yPos":-1.0}],"clears":[{"type":0,"goal":2}],"cases":[],"bullets":[1],"comments":""}
\ No newline at end of file
fileFormatVersion: 2
guid: 4b068fe8eb3b7914780b06dca7247d5d
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
{"objects":[{"tag":0,"xPos":125.0,"yPos":0.0},{"tag":2,"xPos":-1.0,"yPos":-1.5},{"tag":2,"xPos":-0.5,"yPos":-1.0},{"tag":3,"xPos":-1.0,"yPos":-0.5},{"tag":2,"xPos":0.5,"yPos":-1.0},{"tag":2,"xPos":1.0,"yPos":-1.5},{"tag":3,"xPos":1.0,"yPos":0.5},{"tag":2,"xPos":0.5,"yPos":1.0},{"tag":2,"xPos":1.5,"yPos":-2.0},{"tag":2,"xPos":-1.5,"yPos":1.0},{"tag":2,"xPos":2.0,"yPos":-0.5},{"tag":2,"xPos":1.5,"yPos":2.0},{"tag":2,"xPos":-1.5,"yPos":-2.0},{"tag":1,"xPos":0.0,"yPos":0.0},{"tag":1,"xPos":0.0,"yPos":1.0},{"tag":1,"xPos":-2.0,"yPos":-1.0},{"tag":1,"xPos":-2.0,"yPos":0.0},{"tag":1,"xPos":-1.0,"yPos":0.0},{"tag":1,"xPos":-1.0,"yPos":-1.0},{"tag":1,"xPos":-2.0,"yPos":-2.0},{"tag":1,"xPos":-1.0,"yPos":-2.0},{"tag":1,"xPos":0.0,"yPos":-1.0},{"tag":1,"xPos":0.0,"yPos":-2.0},{"tag":9,"xPos":0.0,"yPos":-2.0},{"tag":1,"xPos":1.0,"yPos":-2.0},{"tag":1,"xPos":1.0,"yPos":-1.0},{"tag":1,"xPos":2.0,"yPos":-1.0},{"tag":1,"xPos":2.0,"yPos":-2.0},{"tag":1,"xPos":1.0,"yPos":0.0},{"tag":1,"xPos":2.0,"yPos":0.0},{"tag":1,"xPos":1.0,"yPos":1.0},{"tag":1,"xPos":1.0,"yPos":2.0},{"tag":1,"xPos":0.0,"yPos":2.0},{"tag":1,"xPos":-1.0,"yPos":2.0},{"tag":1,"xPos":-1.0,"yPos":1.0},{"tag":1,"xPos":2.0,"yPos":1.0},{"tag":1,"xPos":-2.0,"yPos":1.0},{"tag":4,"xPos":-2.0,"yPos":-2.0},{"tag":6,"xPos":0.0,"yPos":0.0},{"tag":5,"xPos":2.0,"yPos":-2.0}],"clears":[{"type":0,"goal":1}],"cases":[0],"bullets":[1,1],"comments":""}
\ No newline at end of file
fileFormatVersion: 2
guid: ecdc62db53252b74e941be358fbe04fb
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -253,6 +253,16 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2028998455926151720, guid: 06619682524bc5149b5c3092da0722f2,
type: 3}
propertyPath: m_Options.m_Options.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2028998455926151720, guid: 06619682524bc5149b5c3092da0722f2,
type: 3}
propertyPath: m_Options.m_Options.Array.data[3].m_Text
value: Option C
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 06619682524bc5149b5c3092da0722f2, type: 3}
--- !u!1001 &463381731
......
......@@ -487,6 +487,16 @@ PrefabInstance:
propertyPath: categoryCounts.Array.data[1]
value: 4
objectReference: {fileID: 0}
- target: {fileID: 5996849666618765155, guid: 8115fd4d1a1025b4fb05e45fc5fa6578,
type: 3}
propertyPath: categoryCounts.Array.data[0]
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5996849666618765155, guid: 8115fd4d1a1025b4fb05e45fc5fa6578,
type: 3}
propertyPath: categoryCounts.Array.data[2]
value: 6
objectReference: {fileID: 0}
- target: {fileID: 5087174722634247129, guid: 8115fd4d1a1025b4fb05e45fc5fa6578,
type: 3}
propertyPath: m_AnchorMax.x
......
......@@ -86,7 +86,7 @@ public class MapManager : SingletonBehaviour<MapManager>
PlayerController.inst.CreatePlayer(currentMap.startFloors[i]);
for (int i = 0; i < loadedMapData.bullets.Count; i++)
PlayerController.inst.AddBullet(loadedMapData.bullets[i]);
if (loadedMapData.comments != null)
if (loadedMapData.comments != null && loadedMapData.comments != "")
{
currentMap.comments = loadedMapData.comments;
GameManager.inst.commentUIGenerator.SetComment(currentMap.comments);
......
......@@ -4,48 +4,49 @@ using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json;
using System.IO;
using UnityEngine.SceneManagement;
public class MapEditor : SingletonBehaviour<MapEditor>
{
public class objectData
public class ObjectData
{
public TileMode tag;
public float xPos, yPos;
public objectData(TileMode _tag, Vector2 _pos)
public ObjectData(TileMode _tag, Vector2 _pos)
{
tag = _tag; xPos = _pos.x; yPos = _pos.y;
}
}
public class clearData
public class ClearData
{
public ClearType type;
public int goal;
public clearData(ClearType _type, int _goal)
public ClearData(ClearType _type, int _goal)
{
type = _type; goal = _goal;
}
}
public class MapSaveData
{
public List<objectData> objects;
public List<clearData> clears;
public List<ObjectData> objects;
public List<ClearData> clears;
public List<BulletCode> cases;
public List<BulletCode> bullets;
public string comments = null;
public MapSaveData()
{
objects = new List<objectData>();
clears = new List<clearData>();
objects = new List<ObjectData>();
clears = new List<ClearData>();
cases = new List<BulletCode>();
bullets = new List<BulletCode>();
}
public void AddObject(TileMode _tag, Vector2 _pos)
{
objects.Add(new objectData(_tag, _pos));
objects.Add(new ObjectData(_tag, _pos));
}
public void AddClears(ClearType _type, int _goal)
{
clears.Add(new clearData(_type, _goal));
clears.Add(new ClearData(_type, _goal));
}
}
public Map currentMap;
......@@ -53,14 +54,18 @@ public class MapEditor : SingletonBehaviour<MapEditor>
TileMode currentMode;
BulletCode bulletMode;
public Text modeSign;
public GameObject startSign, goalSign, mapSizeSetter, mapEditorTiles;
public GameObject startSign, goalSign, mapSizeSetter, saveMapSelector, loadMapSelector, mapEditorTiles;
public Dropdown goalDropdown;
public InputField goalInputField;
public Dictionary<Floor, GameObject> startSigns, goalSigns;
public Material editNormalMat;
bool isEditorStarted;
public bool isEditorStarted;
bool isCreateMode;
public string mapName;
public void StartMap(Map _newMap)
{
currentMap = Instantiate(_newMap);
......@@ -71,14 +76,20 @@ public class MapEditor : SingletonBehaviour<MapEditor>
/// Saves map to Assets folder.
/// </summary>
/// <param name="_newMap"></param>
public void SaveMap(Map _newMap)
public void SaveMap()
{
saveMapSelector.SetActive(false);
Map _newMap = currentMap;
/* 맵 저장 시 반드시 승리 조건 작성할 것
* 목표가 '모든'일 경우 승리 목표는 초기 맵 기준으로 작성
*/
System.DateTime time = System.DateTime.Now;
string localPath = "Assets/" + time.ToShortDateString() + "-" + time.Hour + "-" + time.Minute + "-" + time.Second + ".json";
if(currentMap.startFloors.Count == 0)
var x = saveMapSelector.transform.Find("x").GetComponent<InputField>();
var y = saveMapSelector.transform.Find("y").GetComponent<InputField>();
mapName = x.text + "_" + y.text;
//System.DateTime time = System.DateTime.Now;
//string localPath = "Assets/" + time.ToShortDateString() + "-" + time.Hour + "-" + time.Minute + "-" + time.Second + ".json";
string localPath = "Assets/Resources/Stages/stage" + mapName + ".json";
if (currentMap.startFloors.Count == 0)
Debug.Log("There is no start floor.");
else
{
......@@ -126,13 +137,92 @@ public class MapEditor : SingletonBehaviour<MapEditor>
mapSaveData.AddClears(currentMap.clearConditions[i].type, currentMap.clearConditions[i].goal);
for (int i = 0; i < currentMap.initialBullets.Count; i++)
mapSaveData.bullets.Add(currentMap.initialBullets[i]);
mapSaveData.comments = currentMap.comments;
if (File.Exists(localPath))
{
Debug.Log("File Exists");
File.Delete(localPath);
}
File.WriteAllText(localPath, JsonConvert.SerializeObject(mapSaveData));
Debug.Log("Map saved at " + localPath);}
}
public void SaveCurrentMap()
public void LoadMap()
{
loadMapSelector.SetActive(false);
var x = loadMapSelector.transform.Find("x").GetComponent<InputField>();
var y = loadMapSelector.transform.Find("y").GetComponent<InputField>();
mapName = x.text + "_" + y.text;
TextAsset _newMap = Resources.Load("Stages/stage" + mapName) as TextAsset;
if(_newMap != null)
{
SaveMap(currentMap);
var loadedMapData = JsonConvert.DeserializeObject<MapEditor.MapSaveData>(_newMap.ToString());
InputField xInput = mapSizeSetter.transform.Find("x").GetComponent<InputField>();
InputField yInput = mapSizeSetter.transform.Find("y").GetComponent<InputField>();
xInput.text = loadedMapData.objects[0].xPos.ToString();
yInput.text = loadedMapData.objects[0].xPos.ToString();
SetMapSize();
for (int i = 0; i < loadedMapData.clears.Count; i++)
{
var temp = loadedMapData.clears[i];
currentMap.clearConditions.Add(new ClearCondition(temp.type, temp.goal));
}
int casesIndex = 0;
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);
if (currentMap.GetWallAtPos(new Vector2(temp.xPos, temp.yPos)) != null && currentMap.GetWallAtPos(new Vector2(temp.xPos, temp.yPos)).GetComponent<Wall>() is NormalWall)
currentMap.GetWallAtPos(new Vector2(temp.xPos, temp.yPos)).gameObject.GetComponent<MeshRenderer>().material = editNormalMat;
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)));
startSigns.Add(currentMap.GetFloorAtPos(new Vector2Int((int)temp.xPos, (int)temp.yPos)), Instantiate(startSign));
startSigns[currentMap.GetFloorAtPos(new Vector2Int((int)temp.xPos, (int)temp.yPos))].transform.position = new Vector3(temp.xPos, 2, temp.yPos);
break;
case TileMode.Briefcase:
currentMap.CreateObject(new Vector2Int((int)temp.xPos, (int)temp.yPos), ObjType.Briefcase, loadedMapData.cases[casesIndex++]);
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.SetGoalFloor(new Vector2Int((int)temp.xPos, (int)temp.yPos));
goalSigns.Add(currentMap.GetFloorAtPos(new Vector2Int((int)temp.xPos, (int)temp.yPos)), Instantiate(goalSign));
goalSigns[currentMap.GetFloorAtPos(new Vector2Int((int)temp.xPos, (int)temp.yPos))].transform.position = new Vector3(temp.xPos, 2, temp.yPos);
break;
default:
break;
}
}
for (int i = 0; i < loadedMapData.bullets.Count; i++) currentMap.initialBullets.Add(loadedMapData.bullets[i]);
if (loadedMapData.comments != null) currentMap.comments = loadedMapData.comments;
xInput.text = (currentMap.maxBorder.x - currentMap.minBorder.x + 1).ToString();
yInput.text = (currentMap.maxBorder.y - currentMap.minBorder.y + 1).ToString();
SetMapSize();
}
}
public void SetMapSize()
{
InputField xInput = mapSizeSetter.transform.Find("x").GetComponent<InputField>();
......@@ -153,6 +243,22 @@ public class MapEditor : SingletonBehaviour<MapEditor>
public void ResizeMap()
{
mapSizeSetter.SetActive(true);
saveMapSelector.SetActive(false);
loadMapSelector.SetActive(false);
isEditorStarted = false;
}
public void LoadMapButton()
{
mapSizeSetter.SetActive(false);
saveMapSelector.SetActive(false);
loadMapSelector.SetActive(true);
isEditorStarted = false;
}
public void SaveMapButton()
{
mapSizeSetter.SetActive(false);
saveMapSelector.SetActive(true);
loadMapSelector.SetActive(false);
isEditorStarted = false;
}
public void SwitchMode(int _tileMode)
......@@ -180,8 +286,36 @@ public class MapEditor : SingletonBehaviour<MapEditor>
}
public void AddBulletToPlayer(int bulletMode)
{
currentMap.initialBullets.Add((BulletCode)bulletMode);
//PlayerController.inst.bulletList.Add((BulletCode)bulletMode);
if (bulletMode < 0) currentMap.initialBullets.Clear();
else currentMap.initialBullets.Add((BulletCode)bulletMode);
}
public void TestMapStart()
{
if(mapName != "")
{
StageSelector.selectedStage = mapName;
SceneManager.LoadScene("PlayStage");
}
else
{
Debug.Log("Save Your Map!");
}
}
public void AddClearCondition()
{
ClearType c = (ClearType)System.Enum.Parse(typeof(ClearType), goalDropdown.options[goalDropdown.value].text);
int n = int.Parse(goalInputField.text);
if(n >= 0)
{
currentMap.clearConditions.Add(new ClearCondition(c, n));
}
}
public void ClearClearCondition()
{
currentMap.clearConditions.Clear();
}
private void Awake()
......@@ -200,36 +334,49 @@ public class MapEditor : SingletonBehaviour<MapEditor>
StartMap(currentMap);
SwitchMode(0);
SwitchBulletMode((int)BulletCode.None);
goalDropdown.options.Clear();
foreach(ClearType c in (ClearType[])System.Enum.GetValues(typeof(ClearType)))
{
goalDropdown.options.Add(new Dropdown.OptionData(c.ToString()));
}
goalDropdown.value = 0;
}
// Update is called once per frame
void Update()
{
if (isEditorStarted && Input.GetMouseButtonDown(0))
if (isEditorStarted && Input.GetMouseButton(0) && Input.mousePosition.x > 250 && Input.mousePosition.x < 1550)
{
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isWall = false;
if (Physics.Raycast(mouseRay, out hit))
{
Debug.Log(hit.transform.position);
Vector2Int clickedPos = Vector2Int.zero;
Vector2 wallPos = Vector2.zero;
if (hit.transform.tag == "wallSign")
{
wallPos = new Vector2(hit.transform.position.x, hit.transform.position.z);
isWall = true;
}
else
{
clickedPos = new Vector2Int((int)hit.transform.position.x, (int)hit.transform.position.z);
if(currentMode == TileMode.Floor)
isWall = false;
}
if(currentMode == TileMode.Floor && !isWall)
{
if (isCreateMode)
currentMap.CreateFloor(clickedPos);
else
currentMap.RemoveFloor(clickedPos);
}
else if(currentMode == TileMode.Normal || currentMode == TileMode.Mirror)
else if(currentMode == TileMode.Normal || currentMode == TileMode.Mirror && isWall)
{
if (isCreateMode)
{
Debug.Log(wallPos);
currentMap.CreateWall(wallPos, (WallType)((int)currentMode - 1));
if (currentMap.GetWallAtPos(wallPos) != null && currentMap.GetWallAtPos(wallPos).GetComponent<Wall>() is NormalWall)
currentMap.GetWallAtPos(wallPos).gameObject.GetComponent<MeshRenderer>().material = editNormalMat;
......@@ -237,7 +384,7 @@ public class MapEditor : SingletonBehaviour<MapEditor>
else
currentMap.RemoveWall(wallPos);
}
else if(currentMode == TileMode.StartFloor)
else if(currentMode == TileMode.StartFloor && !isWall)
{
if (isCreateMode)
{
......@@ -262,7 +409,7 @@ public class MapEditor : SingletonBehaviour<MapEditor>
}
}
}
else if(currentMode == TileMode.goalFloor)
else if(currentMode == TileMode.goalFloor && isWall)
{
if (isCreateMode)
{
......@@ -271,8 +418,7 @@ public class MapEditor : SingletonBehaviour<MapEditor>
else
{
currentMap.GetFloorAtPos(clickedPos).isGoalFloor = true;
goalSigns.Add(currentMap.GetFloorAtPos(clickedPos),
Instantiate(goalSign));
goalSigns.Add(currentMap.GetFloorAtPos(clickedPos), Instantiate(goalSign));
goalSigns[currentMap.GetFloorAtPos(clickedPos)].transform.position = new Vector3(clickedPos.x, 2, clickedPos.y);
}
}
......@@ -288,7 +434,7 @@ public class MapEditor : SingletonBehaviour<MapEditor>
}
}
}
else if((int)currentMode >= 5 && (int)currentMode <= 8)
else if((int)currentMode >= 5 && (int)currentMode <= 8 && isWall)
{
if (isCreateMode)
{
......
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