Browse Source

feat(Scripts): add map generator

tags/0.1.0
mx05 2 years ago
parent
commit
134aace99a
2 changed files with 48 additions and 1 deletions
  1. +46
    -0
      interface/Assets/Scripts/MapManager.cs
  2. +2
    -1
      interface/Assets/Scripts/MessageReceiver.cs

+ 46
- 0
interface/Assets/Scripts/MapManager.cs View File

@@ -8,6 +8,14 @@ public class MapManager : MonoBehaviour
// Start is called before the first frame update
private bool mapFinished;
private MessageOfMap map;
private int rowCount = 50;
private int colCount = 50;

public GameObject wall;
public GameObject grass;
public GameObject land;
public GameObject door;
public GameObject window;
void Start()
{
mapFinished = false;
@@ -19,8 +27,46 @@ public class MapManager : MonoBehaviour
if (!mapFinished && MessageReceiver.map != null)
{
map = MessageReceiver.map;
Debug.Log("valid map");
//Debug.Log("valid map");
mapFinished = true;
ShowMap(map);
}
}

private void ShowMap(MessageOfMap map)
{
var position = new Vector3(-24.5f, 12.25f, 12.25f);
var block = new GameObject();
for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < colCount; j++)
{
position.x = position.x + 1;
block = ShowBlock(map.Row[i].Col[j]);
if (block != null)
{
Instantiate(block, position, new Quaternion(0, 0, 0, 0));
}
}
position.x = -24.5f;
position.z=position.y = position.y - 0.5f;
}

}

private GameObject ShowBlock(PlaceType obj)
{
switch(obj)
{
case PlaceType.Land:return land;
case PlaceType.Grass:return grass;
case PlaceType.Wall:return wall;
case PlaceType.Door3: return door;
case PlaceType.Door5: return door;
case PlaceType.Door6: return door;
case PlaceType.Window: return window;
default:return null;
}
}
}

+ 2
- 1
interface/Assets/Scripts/MessageReceiver.cs View File

@@ -5,7 +5,7 @@ using Grpc.Core;
using Google.Protobuf;
using Protobuf;
using System.Data;
using UnityEditor.U2D.Path;
//using UnityEditor.U2D.Path;

public class MessageReceiver : MonoBehaviour
{
@@ -27,6 +27,7 @@ public class MessageReceiver : MonoBehaviour
if (isMap)
{
map = responseVal.ObjMessage[0].MapMessage;
//Debug.Log(map.ToString());
isMap = false;
}
}


Loading…
Cancel
Save