2025-10-08 16:31:53 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class MapVisualizer : MonoBehaviour
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// public variables
|
|
|
|
|
[Tooltip("地图SO数据")] public HomeMapSO SO_HomeMap;
|
|
|
|
|
[Tooltip("坐标起始点")] public GameObject startPositionObject;
|
|
|
|
|
[Tooltip("初始房间预制体")] public GameObject defaultRoomPrefab;
|
2025-10-08 20:06:51 +08:00
|
|
|
|
|
|
|
|
public int cellSize = 2;
|
2025-10-08 16:31:53 +08:00
|
|
|
// private variables
|
|
|
|
|
|
|
|
|
|
// Game runtime function
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
this.initialize_room_data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public function
|
|
|
|
|
|
2025-10-08 20:06:51 +08:00
|
|
|
|
2025-10-08 16:31:53 +08:00
|
|
|
// private function
|
|
|
|
|
// 初始化房间数据
|
|
|
|
|
private void initialize_room_data()
|
|
|
|
|
{
|
|
|
|
|
SO_HomeMap.initialize_map_data();
|
2025-10-08 20:06:51 +08:00
|
|
|
create_room(position: new Vector2Int(0, 0),
|
2025-10-08 16:31:53 +08:00
|
|
|
room_type: HomeMapSO.RoomType.BugStatueRoom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个房间
|
2025-10-08 20:06:51 +08:00
|
|
|
private void create_room(Vector2Int position, HomeMapSO.RoomType room_type)
|
2025-10-08 16:31:53 +08:00
|
|
|
{
|
2025-10-08 20:06:51 +08:00
|
|
|
SO_HomeMap.create_room(position, room_type);
|
2025-10-08 16:31:53 +08:00
|
|
|
GameObject room = Instantiate<GameObject>(
|
|
|
|
|
defaultRoomPrefab,
|
2025-10-08 20:06:51 +08:00
|
|
|
position: startPositionObject.transform.position +
|
|
|
|
|
new Vector3(position.x * cellSize, position.y * cellSize, 0),
|
2025-10-08 16:31:53 +08:00
|
|
|
rotation: Quaternion.identity);
|
|
|
|
|
room.transform.SetParent(startPositionObject.transform);
|
|
|
|
|
}
|
|
|
|
|
}
|