Commit 44190dd0 authored by 18손재민's avatar 18손재민

맵 에디터 알파 버전 만듬. 현재 맵 사이즈를 확장하는 것은 그냥 확장하면 되지만, 축소하고자 할 경우 축소될 영역에 있는 오브젝트들은 다 제거하고 축소해야 함.

parent 53b86277
fileFormatVersion: 2
guid: f6226b2548447a54486acfc694a44e4d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 06619682524bc5149b5c3092da0722f2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -15,7 +15,7 @@ GameObject: ...@@ -15,7 +15,7 @@ GameObject:
- component: {fileID: 7449840556337937162} - component: {fileID: 7449840556337937162}
m_Layer: 0 m_Layer: 0
m_Name: MapEditorTile m_Name: MapEditorTile
m_TagString: Untagged m_TagString: EditorOnly
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
...@@ -104,3 +104,4 @@ MonoBehaviour: ...@@ -104,3 +104,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8cae5dd6b76966642887959d57d32206, type: 3} m_Script: {fileID: 11500000, guid: 8cae5dd6b76966642887959d57d32206, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
mapPos: {x: 0, y: 0}
...@@ -9,7 +9,7 @@ GameObject: ...@@ -9,7 +9,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 6014610519130626206} - component: {fileID: 6014610519130626206}
- component: {fileID: 1971589825} - component: {fileID: 3268100033343711389}
m_Layer: 0 m_Layer: 0
m_Name: MapManager m_Name: MapManager
m_TagString: Untagged m_TagString: Untagged
...@@ -31,7 +31,7 @@ Transform: ...@@ -31,7 +31,7 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1971589825 --- !u!114 &3268100033343711389
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
...@@ -40,12 +40,14 @@ MonoBehaviour: ...@@ -40,12 +40,14 @@ MonoBehaviour:
m_GameObject: {fileID: 6014610519130626400} m_GameObject: {fileID: 6014610519130626400}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5ad2f39c48d82964f86cd2d6e1e94641, type: 3} m_Script: {fileID: 11500000, guid: 9c46ee6a780f2c3428a79748eadabea8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
isMapEditingOn: 0
floor: {fileID: 19711883686801522, guid: 71931eea896a59a4683986cfd369b8ee, type: 3} floor: {fileID: 19711883686801522, guid: 71931eea896a59a4683986cfd369b8ee, type: 3}
wall: {fileID: 3736402816908646744, guid: a4dcd71ec9f819f4e88c7b5ac24f4b0d, type: 3} wall: {fileID: 3736402816908646744, guid: a4dcd71ec9f819f4e88c7b5ac24f4b0d, type: 3}
player: {fileID: 0}
currentMap: {fileID: 0} currentMap: {fileID: 0}
surface: {fileID: 0}
stage: stage:
- {fileID: 630498074781569474, guid: 759f352c81f1b5a40b2d8d241cdf273b, type: 3} - {fileID: 5554172594464001467, guid: 20fb0f72e3df40c488f15711aa30ac6e, type: 3}
tile: {fileID: 7449840556337937162, guid: 90d0ab9f40a0ddc4c871130319d86cd5, type: 3}
This diff is collapsed.
...@@ -435,11 +435,6 @@ PrefabInstance: ...@@ -435,11 +435,6 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: TestTools value: TestTools
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1444571407667829093, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1444571408780882984, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f, - target: {fileID: 1444571408780882984, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
...@@ -509,38 +504,6 @@ PrefabInstance: ...@@ -509,38 +504,6 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: MapManager value: MapManager
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: stage.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: player
value:
objectReference: {fileID: 0}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: surface
value:
objectReference: {fileID: 2102809461}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: stage.Array.data[1]
value:
objectReference: {fileID: 791563843738455658, guid: d023f0193ec85eb4abdc3e04bb4d7778,
type: 3}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: stage.Array.data[0]
value:
objectReference: {fileID: 5554172594464001467, guid: 20fb0f72e3df40c488f15711aa30ac6e,
type: 3}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: currentMap
value:
objectReference: {fileID: 0}
- target: {fileID: 6014610519130626206, guid: 11285456de5f1854d947bea83275646f, - target: {fileID: 6014610519130626206, guid: 11285456de5f1854d947bea83275646f,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
...@@ -596,6 +559,11 @@ PrefabInstance: ...@@ -596,6 +559,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3268100033343711389, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: surface
value:
objectReference: {fileID: 2102809461}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 11285456de5f1854d947bea83275646f, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 11285456de5f1854d947bea83275646f, type: 3}
--- !u!1001 &7277015660625800392 --- !u!1001 &7277015660625800392
......
...@@ -21,7 +21,7 @@ public class Map : MonoBehaviour ...@@ -21,7 +21,7 @@ public class Map : MonoBehaviour
/// <returns></returns> /// <returns></returns>
public Floor GetFloorAtPos(int x, int y) public Floor GetFloorAtPos(int x, int y)
{ {
if ((x >= 0 ? x > maxMapSize / 2 - 1 : x < maxMapSize / 2) || (y >= 0 ? y > maxMapSize / 2 - 1 : y < maxMapSize / 2)) if ((x >= 0 ? (x > maxMapSize / 2) : (x < -maxMapSize / 2)) || (y >= 0 ? (y > maxMapSize / 2) : (y < -maxMapSize / 2)))
{ {
Debug.Log("Input size exceeds map's max size."); Debug.Log("Input size exceeds map's max size.");
return null; return null;
...@@ -56,7 +56,7 @@ public class Map : MonoBehaviour ...@@ -56,7 +56,7 @@ public class Map : MonoBehaviour
/// <param name="y">Y position of floor.</param> /// <param name="y">Y position of floor.</param>
public void CreateFloor(int x, int y) public void CreateFloor(int x, int y)
{ {
if ((x >= 0 ? (x > maxMapSize / 2 - 1) : (x < -maxMapSize / 2)) || (y >= 0 ? (y > maxMapSize / 2 - 1) : (y < -maxMapSize / 2))) if ((x >= 0 ? (x > maxMapSize / 2) : (x < -maxMapSize / 2)) || (y >= 0 ? (y > maxMapSize / 2) : (y < -maxMapSize / 2)))
{ {
Debug.Log("Input size exceeds map's max size."); Debug.Log("Input size exceeds map's max size.");
return; return;
...@@ -101,7 +101,7 @@ public class Map : MonoBehaviour ...@@ -101,7 +101,7 @@ public class Map : MonoBehaviour
/// <param name="y">Y position of floor.</param> /// <param name="y">Y position of floor.</param>
public void RemoveFloor(int x, int y) public void RemoveFloor(int x, int y)
{ {
if ((x >= 0 ? x > maxMapSize / 2 - 1 : x < maxMapSize / 2) || (y >= 0 ? y > maxMapSize / 2 - 1 : y < maxMapSize / 2)) if ((x >= 0 ? (x > maxMapSize / 2) : (x < -maxMapSize / 2)) || (y >= 0 ? (y > maxMapSize / 2) : (y < -maxMapSize / 2)))
{ {
Debug.Log("Input size exceeds map's max size."); Debug.Log("Input size exceeds map's max size.");
return; return;
...@@ -131,9 +131,24 @@ public class Map : MonoBehaviour ...@@ -131,9 +131,24 @@ public class Map : MonoBehaviour
/// <param name="floor2"></param> /// <param name="floor2"></param>
public void CreateWall(Floor floor1, Floor floor2) public void CreateWall(Floor floor1, Floor floor2)
{ {
if(floor1 == null || floor2 == null)
{
Debug.Log("There is no floor near the wall.");
return;
}
else if(floor1.mapPos == floor2.mapPos)
{
Debug.Log("Two floors are same.");
return;
}
Vector2 wallPos = (Vector2)(floor1.mapPos + floor2.mapPos) / 2; Vector2 wallPos = (Vector2)(floor1.mapPos + floor2.mapPos) / 2;
if (!wallGrid.ContainsKey(wallPos)) if (!wallGrid.ContainsKey(wallPos))
{ {
if(Mathf.Abs(floor1.mapPos.x - floor2.mapPos.x) > 1 || Mathf.Abs(floor1.mapPos.y - floor2.mapPos.y) > 1)
{
Debug.Log("Two floors are not adjacent floors.");
return;
}
wallGrid.Add(wallPos, Instantiate(MapManager.inst.wall, new Vector3(wallPos.x, 0, wallPos.y), Quaternion.identity, walls.transform).GetComponent<Wall>()); wallGrid.Add(wallPos, Instantiate(MapManager.inst.wall, new Vector3(wallPos.x, 0, wallPos.y), Quaternion.identity, walls.transform).GetComponent<Wall>());
wallGrid[wallPos].SetmapPos(wallPos); wallGrid[wallPos].SetmapPos(wallPos);
wallGrid[wallPos].transform.LookAt(floor1.transform); wallGrid[wallPos].transform.LookAt(floor1.transform);
...@@ -185,7 +200,6 @@ public class Map : MonoBehaviour ...@@ -185,7 +200,6 @@ public class Map : MonoBehaviour
private void LoadObjects() private void LoadObjects()
{ {
Debug.Log(floors.transform.childCount);
for(int i = 0; i < floors.transform.childCount; i++) for(int i = 0; i < floors.transform.childCount; i++)
{ {
Floor floor = floors.transform.GetChild(i).GetComponent<Floor>(); Floor floor = floors.transform.GetChild(i).GetComponent<Floor>();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using UnityEngine.AI; using UnityEngine.UI;
public class MapEditor : SingletonBehaviour<MapEditor> public class MapEditor : SingletonBehaviour<MapEditor>
{ {
...@@ -11,6 +11,19 @@ public class MapEditor : SingletonBehaviour<MapEditor> ...@@ -11,6 +11,19 @@ public class MapEditor : SingletonBehaviour<MapEditor>
public Map currentMap; public Map currentMap;
public Map[] stage; public Map[] stage;
public MapEditorTile tile; public MapEditorTile tile;
public enum TileMode { None, Floor, Wall };
TileMode currentMode;
public Text modeSign;
public GameObject clickSign;
public GameObject startSign;
public GameObject mapSizeSetter;
public GameObject mapEditorTiles;
Vector2Int[] wallInputFloors;
bool isWallClicked;
bool isEditorStarted;
bool isCreateMode;
bool isStartPositionSetter;
public void LoadMap(Map _newMap) public void LoadMap(Map _newMap)
{ {
...@@ -29,37 +42,134 @@ public class MapEditor : SingletonBehaviour<MapEditor> ...@@ -29,37 +42,134 @@ public class MapEditor : SingletonBehaviour<MapEditor>
string localPath = "Assets/SavedMap_" + time.ToShortDateString() + "-" + time.Hour + "-" + time.Minute + "-" + time.Second + ".prefab"; string localPath = "Assets/SavedMap_" + time.ToShortDateString() + "-" + time.Hour + "-" + time.Minute + "-" + time.Second + ".prefab";
if (AssetDatabase.LoadAssetAtPath(localPath, typeof(GameObject))) if (AssetDatabase.LoadAssetAtPath(localPath, typeof(GameObject)))
Debug.Log("Object with same name already exists."); Debug.Log("Object with same name already exists.");
else if(currentMap.startFloor == null)
Debug.Log("There is no start floor.");
else else
{ {
PrefabUtility.SaveAsPrefabAsset(_newMap.gameObject, localPath); PrefabUtility.SaveAsPrefabAsset(_newMap.gameObject, localPath);
Debug.Log("Map saved at " + localPath); Debug.Log("Map saved at " + localPath);
} }
} }
public void SaveCurrentMap()
{
SaveMap(currentMap);
}
public void SetMapSize()
{
InputField xInput = mapSizeSetter.transform.Find("x").GetComponent<InputField>();
InputField yInput = mapSizeSetter.transform.Find("y").GetComponent<InputField>();
int x = int.Parse(xInput.text);
int y = int.Parse(yInput.text);
int xMax = x % 2 == 0 ? x / 2 - 1 : x / 2;
int yMax = y % 2 == 0 ? y / 2 - 1 : y / 2;
for(int i = 0; i < mapEditorTiles.transform.childCount; i++)
Destroy(mapEditorTiles.transform.GetChild(i).gameObject);
currentMap.maxMapSize = Mathf.Max(x, y);
for (int i = -x / 2; i <= xMax; i++)
for (int j = -y / 2; j <= yMax; j++)
Instantiate(tile, new Vector3(i, -0.3f, j), Quaternion.identity, mapEditorTiles.transform).GetComponent<MapEditorTile>().mapPos = new Vector2(i, j);
mapSizeSetter.SetActive(false);
isEditorStarted = true;
}
public void ResizeMap()
{
mapSizeSetter.SetActive(true);
isEditorStarted = false;
}
public void SwitchMode(int mode)
{
currentMode = (TileMode)mode;
SetModeSign();
}
public void SetCreateMode(bool mode)
{
isCreateMode = mode;
SetModeSign();
}
void SetModeSign()
{
string sign = "Mode : " + currentMode.ToString();
if (isStartPositionSetter)
modeSign.text = "Set start position";
else if (isCreateMode)
modeSign.text = sign + " Create";
else
modeSign.text = sign + " Destroy";
}
public void SetStartPosition()
{
if(!isStartPositionSetter)
isStartPositionSetter = true;
else
isStartPositionSetter = false;
SetModeSign();
}
private void Awake() private void Awake()
{ {
MapManager.inst.isMapEditingOn = true;
clickSign.SetActive(false);
startSign.SetActive(false);
isEditorStarted = false;
isCreateMode = true;
isStartPositionSetter = false;
} }
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
LoadMap(stage[0]); LoadMap(stage[0]);
for (int i = 0; i < 10; i++) wallInputFloors = new Vector2Int[2];
for (int j = 0; j < 10; j++) isWallClicked = false;
Instantiate(tile, new Vector3(i, 0, j), Quaternion.identity).GetComponent<MapEditorTile>().mapPos = new Vector2(i, j); SwitchMode(0);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (Input.GetMouseButtonDown(0)) if (isEditorStarted && Input.GetMouseButtonDown(0))
{ {
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; RaycastHit hit;
if (Physics.Raycast(mouseRay, out hit)) if (Physics.Raycast(mouseRay, out hit))
{ {
Debug.Log(hit.collider.gameObject.transform.position); Debug.Log(hit.transform.position);
Vector2Int clickedPos = new Vector2Int((int)hit.transform.position.x, (int)hit.transform.position.z);
if (isStartPositionSetter)
{
currentMap.startFloor = currentMap.GetFloorAtPos(clickedPos);
startSign.SetActive(true);
startSign.transform.position = currentMap.startFloor.transform.position + new Vector3(0, 1, 0);
isStartPositionSetter = false;
SetModeSign();
}
else if(currentMode == TileMode.Floor)
{
if (isCreateMode)
currentMap.CreateFloor(clickedPos);
else
currentMap.RemoveFloor(clickedPos);
}
else if(currentMode == TileMode.Wall)
{
if (!isWallClicked)
{
clickSign.SetActive(true);
wallInputFloors[0] = clickedPos;
clickSign.transform.position = new Vector3(clickedPos.x, 1, clickedPos.y);
isWallClicked = true;
}
else
{
wallInputFloors[1] = clickedPos;
if (isCreateMode)
currentMap.CreateWall(currentMap.GetFloorAtPos(wallInputFloors[0]), currentMap.GetFloorAtPos(wallInputFloors[1]));
else
currentMap.RemoveWall(currentMap.GetFloorAtPos(wallInputFloors[0]), currentMap.GetFloorAtPos(wallInputFloors[1]));
clickSign.SetActive(false);
isWallClicked = false;
}
}
} }
} }
} }
......
...@@ -13,7 +13,7 @@ public class MapEditorCamera : MonoBehaviour ...@@ -13,7 +13,7 @@ public class MapEditorCamera : MonoBehaviour
void CameraZoom() void CameraZoom()
{ {
float mouseWheel = -Input.GetAxis("Mouse ScrollWheel"); float mouseWheel = -Input.GetAxis("Mouse ScrollWheel");
transform.position += new Vector3(0, mouseWheel * 5, 0); Camera.main.orthographicSize += mouseWheel * 2;
} }
// Start is called before the first frame update // Start is called before the first frame update
......
...@@ -6,6 +6,7 @@ using UnityEngine.AI; ...@@ -6,6 +6,7 @@ using UnityEngine.AI;
public class MapManager : SingletonBehaviour<MapManager> public class MapManager : SingletonBehaviour<MapManager>
{ {
public bool isMapEditingOn;
public Floor floor; public Floor floor;
public Wall wall; public Wall wall;
public GameObject player; public GameObject player;
...@@ -36,7 +37,8 @@ public class MapManager : SingletonBehaviour<MapManager> ...@@ -36,7 +37,8 @@ public class MapManager : SingletonBehaviour<MapManager>
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
//LoadMap(stage[0]); if(!isMapEditingOn)
LoadMap(stage[0]);
} }
// Update is called once per frame // Update is called once per frame
......
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