2025-10-08 16:31:53 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2025-10-08 20:06:51 +08:00
|
|
|
using System.Diagnostics;
|
2025-10-08 16:31:53 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
[CreateAssetMenu(fileName = "HomeMapSO", menuName = "GameData/HomeMap")]
|
|
|
|
|
public class HomeMapSO : ScriptableObject
|
|
|
|
|
{
|
|
|
|
|
public Vector2Int map_size = new Vector2Int(10, 10);
|
|
|
|
|
public List<GridData> grid_list = new List<GridData>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// enum
|
|
|
|
|
public enum RoomType
|
|
|
|
|
{
|
2025-10-08 20:06:51 +08:00
|
|
|
None = 0,
|
|
|
|
|
Placeholder = 1,
|
|
|
|
|
BugStatueRoom = 2,
|
2025-10-08 16:31:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// serializable
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class GridData
|
|
|
|
|
{
|
|
|
|
|
public Vector2Int position;
|
2025-10-08 20:06:51 +08:00
|
|
|
public bool has_room = false;
|
|
|
|
|
public int room_id = -1;
|
|
|
|
|
public RoomType room_type = RoomType.None;
|
2025-10-08 16:31:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// function
|
|
|
|
|
// 生成默认地图数据
|
|
|
|
|
public void initialize_map_data()
|
|
|
|
|
{
|
|
|
|
|
grid_list.Clear();
|
|
|
|
|
for (var x = -map_size.x / 2; x <= map_size.x / 2; x++)
|
|
|
|
|
{
|
|
|
|
|
for (var y = -map_size.y / 2; y <= map_size.y / 2; y++)
|
|
|
|
|
{
|
|
|
|
|
grid_list.Add(new GridData
|
|
|
|
|
{
|
|
|
|
|
position = new Vector2Int(x, y),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取某个位置的数据
|
|
|
|
|
public GridData get_data_by_position(Vector2Int position)
|
|
|
|
|
{
|
|
|
|
|
return grid_list.Find(item => item.position == position);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-08 20:06:51 +08:00
|
|
|
// 通过has_room字段来获取数据
|
|
|
|
|
public List<Vector2Int> get_position_by_has_room()
|
|
|
|
|
{
|
|
|
|
|
return grid_list.FindAll(item => item.has_room).ConvertAll(item => item.position);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-08 16:31:53 +08:00
|
|
|
// 标记建造点
|
2025-10-08 20:06:51 +08:00
|
|
|
public void create_room(Vector2Int position, RoomType room_type = RoomType.None)
|
2025-10-08 16:31:53 +08:00
|
|
|
{
|
2025-10-08 20:06:51 +08:00
|
|
|
void _create_a_room(Vector2Int _position, RoomType _room_type)
|
|
|
|
|
{
|
|
|
|
|
var grid = get_data_by_position(_position);
|
|
|
|
|
grid.has_room = true;
|
|
|
|
|
grid.room_type = _room_type;
|
|
|
|
|
grid.room_id = int.Parse($"{_position.x}{_position.y}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (room_type == RoomType.None)
|
|
|
|
|
{
|
|
|
|
|
_create_a_room(position, RoomType.None);
|
|
|
|
|
}
|
|
|
|
|
else if (room_type == RoomType.BugStatueRoom)
|
|
|
|
|
{
|
|
|
|
|
_create_a_room(position, RoomType.BugStatueRoom);
|
|
|
|
|
_create_a_room(position + new Vector2Int(0, 1), RoomType.Placeholder);
|
|
|
|
|
}
|
2025-10-08 16:31:53 +08:00
|
|
|
}
|
|
|
|
|
}
|