92 lines
3.3 KiB
C#
92 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
[CreateAssetMenu(fileName = "HomeMapSO", menuName = "GameData/HomeMapSO")]
|
|
public class HomeMapSO : ScriptableObject
|
|
{
|
|
public Vector2Int mapSize = new Vector2Int(10, 10);
|
|
public List<GridData> underGroundGridList = new List<GridData>();
|
|
public List<GridData> onTheGroundGridList = new List<GridData>();
|
|
|
|
// enum
|
|
public enum RoomType
|
|
{
|
|
None = 0,
|
|
PlaceholderRoom = 1,
|
|
StatueRoom = 2,
|
|
CageNormalRoom = 3,
|
|
CageSpecialRoom = 4,
|
|
WeaponRoom = 5,
|
|
StorageRoom = 6,
|
|
MissionRoom = 7,
|
|
TeamEditorRoom = 8,
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class GridData // 每个格子的数据
|
|
{
|
|
public Vector2Int position;
|
|
public int roomID = 0;
|
|
public RoomType roomType = RoomType.None;
|
|
public bool isLock = true;
|
|
}
|
|
|
|
public void m_recv_initialize_map_grid_data()
|
|
{
|
|
underGroundGridList.Clear();
|
|
onTheGroundGridList.Clear();
|
|
for (var x = -mapSize.x; x <= mapSize.x + 1; x++) // 创建地图数据 x + 1 保证默认房间两侧对称
|
|
{
|
|
for (var y = -mapSize.y; y <= 0; y++) // 地面上的坐标不生成
|
|
{
|
|
underGroundGridList.Add(new GridData { position = new Vector2Int(x, y) });
|
|
}
|
|
|
|
for (var y = 0; y <= mapSize.y; y++) // 地面下的坐标不生成
|
|
{
|
|
onTheGroundGridList.Add(new GridData { position = new Vector2Int(x, y) });
|
|
}
|
|
}
|
|
}
|
|
|
|
private GridData m_self_get_grid_data_by_position(Vector2Int position, bool pull_under_position = false)
|
|
{
|
|
return pull_under_position
|
|
? underGroundGridList.Find(item => item.position == position)
|
|
: onTheGroundGridList.Find(item => item.position == position);
|
|
}
|
|
|
|
public void m_recv_create_a_room_SO_message(RoomPrefabItem room_prefab_item, bool is_lock = false, bool create_under_ground_room = true)
|
|
{
|
|
foreach (Vector2Int position in room_prefab_item.m_recv_get_placeholder_position_list())
|
|
{
|
|
mm_self_set_a_room_message(room_prefab_item.m_recv_get_position() + position, RoomType.PlaceholderRoom, is_lock);
|
|
}
|
|
|
|
mm_self_set_a_room_message(room_prefab_item.m_recv_get_position(), room_prefab_item.m_recv_get_room_type(), is_lock);
|
|
return;
|
|
|
|
void mm_self_set_a_room_message(Vector2Int _position, RoomType _room_type, bool _is_lock)
|
|
{
|
|
GridData grid = m_self_get_grid_data_by_position(_position, pull_under_position: create_under_ground_room);
|
|
grid.roomType = _room_type;
|
|
grid.roomID = mmm_self_general_id();
|
|
grid.isLock = _is_lock;
|
|
return;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |