92 lines
3.3 KiB
C#
Raw Normal View History

2025-10-08 16:31:53 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2025-10-13 17:51:19 +08:00
using UnityEngine.UIElements;
2025-10-08 16:31:53 +08:00
2025-10-15 00:36:54 +08:00
[CreateAssetMenu(fileName = "HomeMapSO", menuName = "GameData/HomeMapSO")]
2025-10-08 16:31:53 +08:00
public class HomeMapSO : ScriptableObject
{
2025-10-09 22:33:05 +08:00
public Vector2Int mapSize = new Vector2Int(10, 10);
2025-10-15 00:36:54 +08:00
public List<GridData> underGroundGridList = new List<GridData>();
public List<GridData> onTheGroundGridList = 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,
2025-10-15 00:36:54 +08:00
CageNormalRoom = 3,
CageSpecialRoom = 4,
WeaponRoom = 5,
StorageRoom = 6,
MissionRoom = 7,
TeamEditorRoom = 8,
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;
2025-10-12 02:32:13 +08:00
public int roomID = 0;
public RoomType roomType = RoomType.None;
2025-10-15 00:36:54 +08:00
public bool isLock = true;
2025-10-08 16:31:53 +08:00
}
2025-10-15 00:36:54 +08:00
public void m_recv_initialize_map_grid_data()
2025-10-13 17:51:19 +08:00
{
2025-10-15 00:36:54 +08:00
underGroundGridList.Clear();
onTheGroundGridList.Clear();
2025-10-12 02:32:13 +08:00
for (var x = -mapSize.x; x <= mapSize.x + 1; x++) // 创建地图数据 x + 1 保证默认房间两侧对称
2025-10-08 16:31:53 +08:00
{
2025-10-15 00:36:54 +08:00
for (var y = -mapSize.y; y <= 0; y++) // 地面上的坐标不生成
2025-10-08 16:31:53 +08:00
{
2025-10-15 00:36:54 +08:00
underGroundGridList.Add(new GridData { position = new Vector2Int(x, y) });
2025-10-08 16:31:53 +08:00
}
2025-10-15 00:36:54 +08:00
for (var y = 0; y <= mapSize.y; y++) // 地面下的坐标不生成
{
onTheGroundGridList.Add(new GridData { position = new Vector2Int(x, y) });
}
2025-10-13 17:51:19 +08:00
}
2025-10-08 16:31:53 +08:00
}
2025-10-15 00:36:54 +08:00
private GridData m_self_get_grid_data_by_position(Vector2Int position, bool pull_under_position = false)
{
2025-10-15 00:36:54 +08:00
return pull_under_position
? underGroundGridList.Find(item => item.position == position)
: onTheGroundGridList.Find(item => item.position == position);
}
2025-10-15 00:36:54 +08:00
public void m_recv_create_a_room_SO_message(RoomPrefabItem room_prefab_item, bool is_lock = false, bool create_under_ground_room = true)
2025-10-08 16:31:53 +08:00
{
2025-10-15 00:36:54 +08:00
foreach (Vector2Int position in room_prefab_item.m_recv_get_placeholder_position_list())
{
2025-10-15 00:36:54 +08:00
mm_self_set_a_room_message(room_prefab_item.m_recv_get_position() + position, RoomType.PlaceholderRoom, is_lock);
}
2025-10-09 22:33:05 +08:00
2025-10-15 00:36:54 +08:00
mm_self_set_a_room_message(room_prefab_item.m_recv_get_position(), room_prefab_item.m_recv_get_room_type(), is_lock);
2025-10-09 22:33:05 +08:00
return;
2025-10-15 00:36:54 +08:00
void mm_self_set_a_room_message(Vector2Int _position, RoomType _room_type, bool _is_lock)
2025-10-09 22:33:05 +08:00
{
2025-10-15 00:36:54 +08:00
GridData grid = m_self_get_grid_data_by_position(_position, pull_under_position: create_under_ground_room);
2025-10-12 02:32:13 +08:00
grid.roomType = _room_type;
2025-10-15 00:36:54 +08:00
grid.roomID = mmm_self_general_id();
grid.isLock = _is_lock;
return;
2025-10-12 02:32:13 +08:00
2025-10-15 00:36:54 +08:00
int mmm_self_general_id() // 生成id
{
string id_string = $"{_position.x}{_position.y}";
bool is_negative = id_string.Contains("-");
id_string = id_string.Replace("-", "");
id_string = int.Parse(id_string).ToString("D5");
id_string = $"1{id_string}";
int id = int.Parse(id_string);
if (is_negative) id = -id;
return id;
}
2025-10-09 22:33:05 +08:00
}
2025-10-08 16:31:53 +08:00
}
}