完成阻隔点
This commit is contained in:
@@ -67,6 +67,7 @@ public partial class MapManager : MonoBehaviour
|
||||
return;
|
||||
map.mapGrid.gameObject.SetActive(!map.mapGrid.activeInHierarchy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -79,6 +80,57 @@ public partial class MapManager : MonoBehaviour
|
||||
int posIndex = Mathf.FloorToInt(pos.x + Mathf.FloorToInt(pos.z) * map.horizontalNumber);
|
||||
return map.selector.GetGridData()[posIndex].barrier;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否打开了地图
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool isOpenMap(bool isTips = true)
|
||||
{
|
||||
if (map == null || map.selector == null)
|
||||
{
|
||||
if (isTips) UIWindow.Instance.ShowMessage("当前没有可编辑地图,请打开地图!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void SaveMapObs()
|
||||
{
|
||||
if (!MapManager.Instance.isOpenMap()) return;
|
||||
string path = PathUtil.GetObsPath(MapManager.Instance._curOpenMapId, "Obs");
|
||||
string tmp = path.Substring(0, path.LastIndexOf('/'));
|
||||
if (!Directory.Exists(tmp))
|
||||
Directory.CreateDirectory(tmp);
|
||||
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
|
||||
{
|
||||
BinaryWriter bw = new BinaryWriter(fs);
|
||||
Map.Serialize(MapManager.Instance.map, bw);
|
||||
bw.Close();
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public bool LoadMapObs(int mapId)
|
||||
{
|
||||
string path = PathUtil.GetObsPath(MapManager.Instance._curOpenMapId, "Obs");
|
||||
if (!File.Exists(path))
|
||||
return false;
|
||||
if (map != null)
|
||||
{
|
||||
map.Release();
|
||||
map = null;
|
||||
}
|
||||
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
BinaryReader br = new BinaryReader(fs);
|
||||
map = Map.Deserialize(br);
|
||||
br.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public partial class Map
|
||||
{
|
||||
@@ -87,8 +139,6 @@ public partial class Map
|
||||
public int mapId { get; private set; }
|
||||
public float width { get; private set; }
|
||||
public float height { get; private set; }
|
||||
|
||||
public float sideLength { get; private set; }
|
||||
public float sideWidth { get; private set; }
|
||||
public float sideHeight { get; private set; }
|
||||
public int horizontalNumber { get { return (int)(width / sideWidth); } }
|
||||
@@ -98,8 +148,6 @@ public partial class Map
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.sideLength = sideLength;
|
||||
|
||||
this.sideWidth = sideWidth;
|
||||
this.sideHeight = sideHeight;
|
||||
mapGrid = CreateMapGrid();
|
||||
@@ -164,11 +212,11 @@ public partial class Map
|
||||
{
|
||||
int width = map.selector.horizontalNumber;
|
||||
int height = map.selector.verticalNumber;
|
||||
int sideLength = (int)(map.sideLength * 100);
|
||||
bw.Write(map.mapId);
|
||||
bw.Write(width);
|
||||
bw.Write(height);
|
||||
bw.Write(sideLength);
|
||||
bw.Write((int)Mathf.Round(map.sideWidth * 100)); // 四舍五入确保精度
|
||||
bw.Write((int)Mathf.Round(map.sideHeight * 100)); // 四舍五入确保精度
|
||||
GridSelector.RenderData[] data = map.selector.GetGridData();
|
||||
for (int i = 0, length = data.Length; i < length; i++)
|
||||
{
|
||||
@@ -181,10 +229,9 @@ public partial class Map
|
||||
int mapId = br.ReadInt32();
|
||||
int horizontalNumber = br.ReadInt32();
|
||||
int verticalNumber = br.ReadInt32();
|
||||
//服务器那边是用的边长的100倍的int
|
||||
float sideWidth = br.ReadInt32() / 100f;
|
||||
float sideHeight = br.ReadInt32() / 100f;
|
||||
var map = MapManager.Instance.GenerateMap((int)(horizontalNumber * sideWidth), (int)(verticalNumber * sideHeight), sideWidth, sideHeight);
|
||||
float sideWidth = br.ReadInt32() / 100f; // 读取时直接除以 100
|
||||
float sideHeight = br.ReadInt32() / 100f; // 读取时直接除以 100
|
||||
var map = MapManager.Instance.GenerateMap(horizontalNumber * sideWidth, verticalNumber * sideHeight, sideWidth, sideHeight);
|
||||
map.SetMapId(mapId);
|
||||
GridSelector.RenderData[] data = map.selector.GetGridData();
|
||||
for (int i = 0; i < horizontalNumber * verticalNumber; i++) {
|
||||
|
||||
Reference in New Issue
Block a user