95 lines
2.8 KiB
C#
Raw Normal View History

2025-10-08 16:31:53 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
2025-10-09 04:03:32 +08:00
using Unity.VisualScripting;
2025-10-08 16:31:53 +08:00
using UnityEngine;
[CreateAssetMenu(fileName = "HomeMapSO", menuName = "GameData/HomeMap")]
public class HomeMapSO : ScriptableObject
{
2025-10-09 22:33:05 +08:00
public Vector2Int mapSize = new Vector2Int(10, 10);
public List<GridData> gridList = new List<GridData>();
2025-10-08 16:31:53 +08:00
// enum
public enum RoomType
{
None = 0,
2025-10-09 22:33:05 +08:00
PlaceholderRoom = 1,
StatueRoom = 2,
AreaRoom = 3,
CageRoom = 4,
SingleRoom = 5,
2025-10-08 16:31:53 +08:00
}
[System.Serializable]
2025-10-09 22:33:05 +08:00
public class GridData // 每个格子的数据
2025-10-08 16:31:53 +08:00
{
public Vector2Int position;
public bool has_room = false;
public int room_id = -1;
public RoomType room_type = RoomType.None;
2025-10-08 16:31:53 +08:00
}
2025-10-10 00:53:27 +08:00
public void m_recv_initialize_map_data()
2025-10-08 16:31:53 +08:00
{
2025-10-09 22:33:05 +08:00
gridList.Clear();
for (var x = -mapSize.x / 2; x <= mapSize.x / 2; x++)
2025-10-08 16:31:53 +08:00
{
2025-10-09 22:33:05 +08:00
for (var y = -mapSize.y / 2; y <= mapSize.y / 2; y++)
2025-10-08 16:31:53 +08:00
{
2025-10-09 22:33:05 +08:00
gridList.Add(new GridData
2025-10-08 16:31:53 +08:00
{
position = new Vector2Int(x, y),
});
}
}
}
// 获取某个位置的数据
2025-10-09 22:33:05 +08:00
private GridData self_get_data_by_position(Vector2Int position)
2025-10-08 16:31:53 +08:00
{
2025-10-09 22:33:05 +08:00
return gridList.Find(item => item.position == position);
2025-10-08 16:31:53 +08:00
}
// 通过has_room字段来获取数据
2025-10-10 00:53:27 +08:00
public List<Vector2Int> m_recv_get_position_by_has_room()
{
2025-10-09 22:33:05 +08:00
return gridList.FindAll(item => item.has_room).ConvertAll(item => item.position);
}
2025-10-08 16:31:53 +08:00
// 标记建造点
2025-10-10 00:53:27 +08:00
public void m_recv_create_room(Vector2Int position, RoomType room_type = RoomType.None)
2025-10-08 16:31:53 +08:00
{
2025-10-09 04:03:32 +08:00
switch (room_type)
{
2025-10-09 04:03:32 +08:00
case RoomType.None:
2025-10-09 22:33:05 +08:00
_self_create_a_room(position, RoomType.None);
2025-10-09 04:03:32 +08:00
break;
2025-10-09 22:33:05 +08:00
case RoomType.StatueRoom:
_self_create_a_room(position, RoomType.StatueRoom);
_self_create_a_room(position + new Vector2Int(0, 1), RoomType.PlaceholderRoom);
_self_create_a_room(position + new Vector2Int(-1, 1), RoomType.PlaceholderRoom);
_self_create_a_room(position + new Vector2Int(-1, 0), RoomType.PlaceholderRoom);
2025-10-09 04:03:32 +08:00
break;
2025-10-10 00:53:27 +08:00
case RoomType.SingleRoom:
_self_create_a_room(position, RoomType.SingleRoom);
break;
2025-10-09 22:33:05 +08:00
case RoomType.PlaceholderRoom:
case RoomType.AreaRoom:
case RoomType.CageRoom:
2025-10-09 04:03:32 +08:00
default:
break;
}
2025-10-09 22:33:05 +08:00
return;
void _self_create_a_room(Vector2Int _position, RoomType _room_type)
{
GridData grid = self_get_data_by_position(_position);
grid.has_room = true;
grid.room_type = _room_type;
grid.room_id = int.Parse($"{_position.x}{_position.y}");
}
2025-10-08 16:31:53 +08:00
}
}