168 lines
5.7 KiB
C#
168 lines
5.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(fileName = "HomeMapSO", menuName = "GameData/HomeMap")]
|
|
public class HomeMapSO : ScriptableObject
|
|
{
|
|
public Vector2Int mapSize = new Vector2Int(10, 10);
|
|
public List<GridData> gridList = new List<GridData>();
|
|
|
|
|
|
// enum
|
|
public enum RoomType
|
|
{
|
|
None = 0,
|
|
PlaceholderRoom = 1,
|
|
StatueRoom = 2,
|
|
AreaRoom = 3,
|
|
CageRoom = 4,
|
|
SingleRoom = 5,
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class GridData // 每个格子的数据
|
|
{
|
|
public Vector2Int position;
|
|
public bool hasRoom = false;
|
|
public int roomID = 0;
|
|
public RoomType roomType = RoomType.None;
|
|
}
|
|
|
|
// public bool m_recv_judge_room_placeholder_is_trigger(Vector2Int position, RoomType room_type)
|
|
// {
|
|
// switch (room_type)
|
|
// {
|
|
// case RoomType.CageRoom:
|
|
// List<Vector2Int> placeholder_room_list = new List<Vector2Int>()
|
|
// {
|
|
// new Vector2Int(1, 0),
|
|
// };
|
|
// return _self_judge_placeholder_has_room(placeholder_room_list, position);
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
//
|
|
// return true;
|
|
//
|
|
// bool _self_judge_placeholder_has_room(List<Vector2Int> placeholder_room_list, Vector2Int position)
|
|
// {
|
|
// foreach (var item in placeholder_room_list)
|
|
// {
|
|
// if (self_get_data_by_position(item + position).hasRoom)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
//
|
|
// return false;
|
|
// }
|
|
// }
|
|
|
|
public void m_recv_initialize_map_data()
|
|
{
|
|
gridList.Clear();
|
|
for (var x = -mapSize.x; x <= mapSize.x + 1; x++) // 创建地图数据 x + 1 保证默认房间两侧对称
|
|
{
|
|
for (var y = -mapSize.y; y <= mapSize.y; y++)
|
|
{
|
|
gridList.Add(new GridData { position = new Vector2Int(x, y) });
|
|
}
|
|
}
|
|
}
|
|
|
|
// 获取某个位置的数据
|
|
private GridData m_self_get_grid_data_by_position(Vector2Int position)
|
|
{
|
|
return gridList.Find(item => item.position == position);
|
|
}
|
|
|
|
// 通过has_room字段来获取数据
|
|
public List<Vector2Int> m_recv_get_position_by_has_room()
|
|
{
|
|
return gridList.FindAll(item => item.hasRoom).ConvertAll(item => item.position);
|
|
}
|
|
|
|
public void m_recv_create_a_room(Vector2Int position, MapPlacerItem map_placer_item)
|
|
{
|
|
if (map_placer_item.m_recv_get_placeholder_position_list().Count > 0)
|
|
{
|
|
foreach (var item in map_placer_item.m_recv_get_placeholder_position_list())
|
|
{
|
|
mm_self_create_a_room(item + position, RoomType.PlaceholderRoom);
|
|
}
|
|
}
|
|
|
|
mm_self_create_a_room(position, map_placer_item.roomType);
|
|
|
|
return;
|
|
|
|
void mm_self_create_a_room(Vector2Int _position, RoomType _room_type)
|
|
{
|
|
GridData grid = m_self_get_grid_data_by_position(_position);
|
|
grid.hasRoom = true;
|
|
grid.roomType = _room_type;
|
|
grid.roomID = mmm_self_general_id(position);
|
|
}
|
|
|
|
int mmm_self_general_id(Vector2Int _position) // 生成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;
|
|
}
|
|
}
|
|
|
|
// 标记建造点
|
|
// public void m_recv_create_room(Vector2Int position, RoomType room_type = RoomType.None,
|
|
// bool reverse_position = false)
|
|
// {
|
|
// switch (room_type)
|
|
// {
|
|
// // case RoomType.None:
|
|
// // _self_create_a_room(position, RoomType.None);
|
|
// // break;
|
|
// // case RoomType.StatueRoom:
|
|
// // _self_create_a_room(position, RoomType.StatueRoom);
|
|
// // _self_create_a_room(position + new Vector2Int(1, 0), RoomType.PlaceholderRoom);
|
|
// // _self_create_a_room(position + new Vector2Int(0, -1), RoomType.PlaceholderRoom);
|
|
// // _self_create_a_room(position + new Vector2Int(1, -1), RoomType.PlaceholderRoom);
|
|
// // break;
|
|
// // case RoomType.SingleRoom:
|
|
// // _self_create_a_room(position, RoomType.SingleRoom);
|
|
// // break;
|
|
// // case RoomType.PlaceholderRoom:
|
|
// // case RoomType.AreaRoom:
|
|
// // case RoomType.CageRoom:
|
|
// // default:
|
|
// // break;
|
|
// }
|
|
//
|
|
// return;
|
|
//
|
|
// void _self_create_a_room(Vector2Int _position, RoomType _room_type)
|
|
// {
|
|
// GridData grid = self_get_data_by_position(_position);
|
|
// grid.hasRoom = true;
|
|
// grid.roomType = _room_type;
|
|
// grid.roomID = __self_general_id();
|
|
//
|
|
// int __self_general_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;
|
|
// }
|
|
// }
|
|
} |