第一次提交
This commit is contained in:
71
Assets/Scripts/Map/CellNode.cs
Normal file
71
Assets/Scripts/Map/CellNode.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace HxGame
|
||||
{
|
||||
public enum CELL_SIDE
|
||||
{
|
||||
TopLeft = 0,
|
||||
Top = 1,
|
||||
TopRight = 2,
|
||||
BottomRight = 3,
|
||||
Bottom = 4,
|
||||
BottomLeft = 5,
|
||||
Left = 6,
|
||||
Right = 7
|
||||
}
|
||||
|
||||
|
||||
public class CellNode
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//private readonly int _row;
|
||||
//private readonly int _column;
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _index;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD> <20><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>赲<EFBFBD><E8B5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public MapManager.CellType cellType = MapManager.CellType.Obstacle;
|
||||
|
||||
public int X { get { return _x; } }
|
||||
public int Y { get { return _y; } }
|
||||
public int index { get { return _index; } }
|
||||
|
||||
float[] _crossCost;
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>ģ<EFBFBD>Ĭ<EFBFBD><C4AC>1.
|
||||
/// </summary>
|
||||
public float[] crossCost
|
||||
{
|
||||
get { return _crossCost; }
|
||||
set { _crossCost = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20>˵<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD>顣<EFBFBD><E9A1A3><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FindPath cellGroupMask<73><6B><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʹ<EFBFBD><CAB9>
|
||||
/// </summary>
|
||||
public int group = 1;
|
||||
|
||||
|
||||
//<2F><><EFBFBD>ڱ༭<DAB1><E0BCAD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF>߿<EFBFBD><DFBF>ܲ<EFBFBD><DCB2>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
||||
public Vector3 GetPos(float width, float height)
|
||||
{
|
||||
float x = _x * width + width / 2;
|
||||
float z = _y * height + height / 2;
|
||||
return new Vector3(x, 0.03f, z);
|
||||
}
|
||||
|
||||
public CellNode(int x, int y, int index, MapManager.CellType type)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_index = index;
|
||||
|
||||
if (type == MapManager.CellType.Safe)
|
||||
cellType |= MapManager.CellType.Safe;
|
||||
else
|
||||
cellType = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/Scripts/Map/CellNode.cs.meta
Normal file
11
Assets/Scripts/Map/CellNode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eca2c9b86b496c24f967f40d0016b1ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1092
Assets/Scripts/Map/MapManager.Cell.cs
Normal file
1092
Assets/Scripts/Map/MapManager.Cell.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Assets/Scripts/Map/MapManager.Cell.cs.meta
Normal file
11
Assets/Scripts/Map/MapManager.Cell.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f4e98dd80004ec4d98001f3d74500d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
81
Assets/Scripts/Map/MapManager.Load.cs
Normal file
81
Assets/Scripts/Map/MapManager.Load.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using HxGame;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static MapManager;
|
||||
|
||||
public partial class MapManager : MonoBehaviour
|
||||
{
|
||||
public bool LoadObsXml()
|
||||
{
|
||||
if (_curOpenMapId < 0)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return false;
|
||||
}
|
||||
|
||||
string path = string.Empty;
|
||||
|
||||
path = PathUtil.GetXmlPath(_curOpenMapId, "Obs");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
xmlDocument.Load(path);
|
||||
|
||||
XmlNode xmlRoot = xmlDocument.SelectSingleNode("Item");
|
||||
|
||||
string ID = xmlRoot.Attributes.GetNamedItem("ID").Value;
|
||||
mapWidth = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("MapWidth").Value);
|
||||
mapHeight = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("MapHeight").Value);
|
||||
|
||||
int cellCount = 0;
|
||||
|
||||
_cellWidth = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("CellWidth").Value);
|
||||
_cellHeight = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("CellHeight").Value);
|
||||
_cellRows = mapHeight / _cellHeight;
|
||||
_cellCols = mapWidth / _cellWidth;
|
||||
cellCount = _cellRows * _cellCols;
|
||||
|
||||
|
||||
string strData = xmlRoot.Attributes.GetNamedItem("Value").Value;
|
||||
|
||||
//0,0,1,0;0,1,1,1;0,2,1,2;
|
||||
string[] values = strData.Split(';');
|
||||
if(values.Length != cellCount)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
|
||||
cellsNode = new CellNode[cellCount];
|
||||
for (int i=0; i<cellCount; i++)
|
||||
{
|
||||
string[] strCell = values[i].Split(',');
|
||||
|
||||
if (strCell.Length != 3)
|
||||
continue;
|
||||
|
||||
int y = Convert.ToInt32(strCell[0]);
|
||||
int x = Convert.ToInt32(strCell[1]);
|
||||
int type = Convert.ToInt32(strCell[2]);
|
||||
|
||||
//<2F><>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD>֮ǰ<D6AE>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
CellType celltype = (CellType)type;
|
||||
if ((celltype & CellType.HadRole) > 0)
|
||||
celltype ^= CellType.HadRole;
|
||||
|
||||
cellsNode[i] = new CellNode(x, y, i, celltype);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Map/MapManager.Load.cs.meta
Normal file
11
Assets/Scripts/Map/MapManager.Load.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbddbe857c688354fb82d684104ed45c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Scripts/Map/MapManager.Path.cs
Normal file
61
Assets/Scripts/Map/MapManager.Path.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using HxGame;
|
||||
using HxGame.PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class MapManager : MonoBehaviour
|
||||
{
|
||||
PathFinderHelper _pathFinderHelper = null;
|
||||
|
||||
public void FindPath(Vector2Int startPos, Vector2Int endPos)
|
||||
{
|
||||
CellNode startCell = GetCell(startPos.x, startPos.y);
|
||||
CellNode endCell = GetCell(endPos.x, endPos.y);
|
||||
|
||||
if (startCell == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
|
||||
if (endCell == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pathFinderHelper == null)
|
||||
{
|
||||
_pathFinderHelper = new PathFinderHelper(cellsNode, _cellRows, _cellCols);
|
||||
}
|
||||
|
||||
GetSpecialName(EditCellType.PathNodeCell, out int size);
|
||||
|
||||
for(int i=1; i<=size; i++)
|
||||
{
|
||||
SetCurPathNodePointIdx(i);
|
||||
RemoveSpecialPoint(EditCellType.PathNodeCell);
|
||||
}
|
||||
_pathNodePointSize = 0;
|
||||
|
||||
List<int> route = _pathFinderHelper.FindPath(startCell.index, endCell.index, 0, 0, 1);
|
||||
|
||||
for (int i = 0; i < route.Count; i++)
|
||||
{
|
||||
CellNode cell = GetCell(route[i]);
|
||||
size = AddPathNodePointSize();
|
||||
SetCurPathNodePointIdx(size);
|
||||
|
||||
CreateSpecialPoint(cell.X, cell.Y, EditCellType.PathNodeCell);
|
||||
|
||||
Debug.Log("<22><><EFBFBD><EFBFBD> <20><>" + route[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private int OnCrossCellNode(int cellIndex)
|
||||
{
|
||||
Debug.Log("<22><><EFBFBD><EFBFBD> <20><>" + cellIndex);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Map/MapManager.Path.cs.meta
Normal file
11
Assets/Scripts/Map/MapManager.Path.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfa2982480aa9c84ca5311fb20dc7991
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
495
Assets/Scripts/Map/MapManager.cs
Normal file
495
Assets/Scripts/Map/MapManager.cs
Normal file
@@ -0,0 +1,495 @@
|
||||
using HxGame;
|
||||
using HxGame.Data;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public partial class MapManager : MonoBehaviour
|
||||
{
|
||||
public enum CellType
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><>Ч<EFBFBD><D0A7>
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// <20>ƶ<EFBFBD>
|
||||
/// </summary>
|
||||
Move = 1,
|
||||
|
||||
/// <summary>
|
||||
/// <20>赲
|
||||
/// </summary>
|
||||
Obstacle = 2,
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
Hide = 4,
|
||||
|
||||
/// <summary>
|
||||
/// <20>н<EFBFBD>ɫռ<C9AB>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>̬<EFBFBD>仯ʱ<E4BBAF><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
HadRole = 8,
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ȫ<EFBFBD><C8AB>
|
||||
/// </summary>
|
||||
Safe = 16,
|
||||
|
||||
/// <summary>
|
||||
/// <20><>̯<EFBFBD><CCAF><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
Stall = 32,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CellLayer
|
||||
{
|
||||
Move = 1, //<2F>ƶ<EFBFBD>
|
||||
Obstacle = 2, //<2F>赲
|
||||
Hide = 4, //<2F><><EFBFBD><EFBFBD>
|
||||
Safe = 16, //<2F><>ȫ<EFBFBD><C8AB>
|
||||
Stall = 32, //<2F><>̯
|
||||
Audio = 64, //<2F><>Ч
|
||||
Trigger = 128, //<2F><><EFBFBD><EFBFBD>
|
||||
Monster = 256 //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
//<2F><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public const int CELLSCALE = 100;
|
||||
|
||||
public delegate void LoadFinishedCallback();
|
||||
public LoadFinishedCallback onLoadFinishedCallback;
|
||||
//public delegate void CloseMapCallback();
|
||||
//public CloseMapCallback onCloseMapCallback;
|
||||
|
||||
private static MapManager _mapManager = null;
|
||||
public static MapManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapManager == null)
|
||||
_mapManager = FindObjectOfType<MapManager>();
|
||||
|
||||
return _mapManager;
|
||||
}
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public int mapWidth = 0;
|
||||
[HideInInspector]
|
||||
public int mapHeight = 0;
|
||||
|
||||
private int _maxWidth; //<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
private int _maxHeight; //<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
|
||||
private int _cellWidth;
|
||||
private int _cellHeight;
|
||||
private int _cellRows;
|
||||
private int _cellCols;
|
||||
//public CellNode[,] cellNodes;
|
||||
|
||||
private int _curOpenMapId;
|
||||
|
||||
private Material _cellMoveMat;
|
||||
private Material _cellObsMat;
|
||||
private Material _cellHideMat;
|
||||
private Material _cellDefaultMat;
|
||||
private Material _cellReturnMat; //<2F>سǵ<D8B3>
|
||||
private Material _cellReliveMat; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
private Material _cellTeleportMat; //<2F><><EFBFBD>͵<EFBFBD>
|
||||
private Material _cellNpcMat; //npcλ<63><CEBB>
|
||||
private Material _cellPathNodeMat; //pathNode
|
||||
private Material _cellTriggerMat; //trigger
|
||||
|
||||
private bool _StartEditor;
|
||||
private float _brushRadius;
|
||||
private CellType _brushCellType;
|
||||
|
||||
public int CellRows { get { return _cellRows; } }
|
||||
public int CellCols { get { return _cellCols; } }
|
||||
|
||||
public int CellWidth { get { return _cellWidth; } }
|
||||
public int CellHeight { get { return _cellHeight; } }
|
||||
|
||||
public int MaxWidth { get { return _maxWidth; } }
|
||||
public int MaxHeight { get { return _maxHeight; } }
|
||||
|
||||
private UnityEngine.Object _cellAsset = null;
|
||||
private GameObject _curPathObj = null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_cellAsset = Resources.Load("Prefabs/Cell");
|
||||
if (_cellAsset == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>cell.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (CellLayer layer in Enum.GetValues(typeof(CellLayer)))
|
||||
{
|
||||
List<GameObject> gos = new List<GameObject>();
|
||||
_layCellsMap.Add(layer, gos);
|
||||
}
|
||||
|
||||
_cellMoveMat = Resources.Load<Material>("Materials/cellMoveMat");
|
||||
_cellObsMat = Resources.Load<Material>("Materials/cellObsMat");
|
||||
_cellHideMat = Resources.Load<Material>("Materials/cellHideMat");
|
||||
_cellDefaultMat = Resources.Load<Material>("Materials/cellDefaultMat");
|
||||
|
||||
_cellReturnMat = Resources.Load<Material>("Materials/cellReturnMat");
|
||||
_cellReliveMat = Resources.Load<Material>("Materials/cellReliveMat");
|
||||
_cellTriggerMat = Resources.Load<Material>("Materials/cellTriggerMat");
|
||||
_cellTeleportMat = Resources.Load<Material>("Materials/cellTeleportMat");
|
||||
_cellNpcMat = Resources.Load<Material>("Materials/cellNpcMat");
|
||||
_cellPathNodeMat = Resources.Load<Material>("Materials/cellPathNodeMat");
|
||||
UIWindow.Instance.uiCreateMap.onCreatedMapCallback += OnCreatedMap;
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
private void OnCreatedMap(int mapId, int mapWidth, int mapHeight)
|
||||
{
|
||||
this.mapWidth = mapWidth;
|
||||
this.mapHeight = mapHeight;
|
||||
_curOpenMapId = mapId;
|
||||
}
|
||||
|
||||
public void StartEditor()
|
||||
{
|
||||
if (_curOpenMapId < 0)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
_StartEditor = true;
|
||||
_curEditCellType = EditCellType.None;
|
||||
}
|
||||
|
||||
public void CloseEditor()
|
||||
{
|
||||
_StartEditor = false;
|
||||
}
|
||||
|
||||
public void SetBrush(float radius, CellType type)
|
||||
{
|
||||
_brushRadius = radius;
|
||||
_brushCellType = type;
|
||||
}
|
||||
|
||||
public void SaveCellsXml()
|
||||
{
|
||||
|
||||
if(cellsNode.Length == 0)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
string path = PathUtil.GetXmlPath(_curOpenMapId, "Obs");
|
||||
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
XmlDocument xml = new XmlDocument();
|
||||
XmlDeclaration node = xml.CreateXmlDeclaration("1.0", "utf-8", "no");
|
||||
xml.AppendChild(node);
|
||||
XmlElement Root = xml.CreateElement("Item");
|
||||
xml.AppendChild(Root);
|
||||
|
||||
Root.SetAttribute("ID", _curOpenMapId.ToString());
|
||||
Root.SetAttribute("MapWidth", mapWidth.ToString());
|
||||
Root.SetAttribute("MapHeight", mapHeight.ToString());
|
||||
Root.SetAttribute("CellWidth", _cellWidth.ToString());
|
||||
Root.SetAttribute("CellHeight", _cellHeight.ToString());
|
||||
|
||||
|
||||
CellNode cell = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
//tempSafeAreasConfig.Clear();
|
||||
|
||||
for (int row = 0; row < _cellRows; row++)
|
||||
{
|
||||
for (int col = 0; col < _cellCols; col++)
|
||||
{
|
||||
cell = GetCell(col, row);
|
||||
if(cell == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD>ϰ<EFBFBD>ȫ<EFBFBD><C8AB>ö<EFBFBD><C3B6>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//if (CheckIsSafeCell(cell))
|
||||
//{
|
||||
// cell.cellType |= CellType.Safe;
|
||||
//}
|
||||
|
||||
sb.Append(string.Format($"{row},{col},{(int)cell.cellType};"));
|
||||
}
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
|
||||
string Value = sb.ToString();
|
||||
Root.SetAttribute("Value", Value);
|
||||
|
||||
xml.Save(path);
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>xml<6D>ɹ<EFBFBD>.");
|
||||
}
|
||||
|
||||
|
||||
List<MapConfig.AreaConfig> tempSafeAreasConfig = new List<MapConfig.AreaConfig>();
|
||||
|
||||
public void CloseMap()
|
||||
{
|
||||
if (_curOpenMapId <= 0)
|
||||
return;
|
||||
|
||||
RemoveAllCells();
|
||||
UIWindow.Instance.uiCellInfo.CloseMap();
|
||||
UIWindow.Instance.uiCreateMap.CloseMap();
|
||||
UIWindow.Instance.uiMonstersPanel.RemoveAll();
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
mapWidth = 0;
|
||||
mapHeight = 0;
|
||||
_maxWidth = 0;
|
||||
_maxHeight = 0;
|
||||
_cellWidth = -1;
|
||||
_cellHeight = -1;
|
||||
_cellRows = -1;
|
||||
_cellCols = -1;
|
||||
_curOpenMapId = -1;
|
||||
|
||||
_StartEditor = false;
|
||||
_brushRadius = 0;
|
||||
_brushCellType = CellType.None;
|
||||
cellsNode = null;
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
bool bHoverUI = EventSystem.current != null && EventSystem.current.IsPointerOverGameObject();
|
||||
if (bHoverUI)
|
||||
return;
|
||||
|
||||
if (_curEditCellType != EditCellType.None)
|
||||
{
|
||||
EditSpecialMapPoint(_curEditCellType);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_StartEditor)
|
||||
return;
|
||||
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
EditCell();
|
||||
}
|
||||
}
|
||||
|
||||
private void EditCell()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hitInfo;
|
||||
if (Physics.Raycast(ray, out hitInfo))
|
||||
{
|
||||
GameObject gameObj = hitInfo.collider.gameObject;
|
||||
if (gameObj.layer != LayerMask.NameToLayer("MapCell"))
|
||||
return;
|
||||
|
||||
if (_brushRadius == 0)
|
||||
{
|
||||
CellType ct = SetCellType(gameObj.name, _brushCellType);
|
||||
ShowCellType(gameObj, ct);
|
||||
return;
|
||||
}
|
||||
|
||||
Collider[] hits = Physics.OverlapSphere(gameObj.transform.position, _brushRadius);// LayerMask.NameToLayer("MapCell")
|
||||
if (hits.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < hits.Length; i++)
|
||||
{
|
||||
CellType ct = SetCellType(hits[i].name, _brushCellType);
|
||||
ShowCellType(hits[i].gameObject, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EditSpecialMapPoint(EditCellType type)
|
||||
{
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
if(type == EditCellType.NpcPath)
|
||||
{
|
||||
if (_curPathObj == null)
|
||||
return;
|
||||
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveList.Add(_curPathObj.name);
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveInput.text += $"[{_curPathObj.name.Replace('_', ',')}]";
|
||||
AddNpcPathSize();
|
||||
_curPathObj = null;
|
||||
}
|
||||
else if (type == EditCellType.MonsterPath)
|
||||
{
|
||||
if (_curPathObj == null)
|
||||
return;
|
||||
|
||||
//UIWindow.Instance.uiMonstersPanel_old.curActiveList.Add(_curPathObj.name);
|
||||
//UIWindow.Instance.uiMonstersPanel_old.curActiveInput.text += $"[{_curPathObj.name.Replace('_', ',')}]";
|
||||
AddMonsterPathSize();
|
||||
_curPathObj = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_curEditCellType = EditCellType.None;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(type == EditCellType.NpcPath)
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
string last = $"NpcPath{_curNpcPointIdx}{GetCurNpcPathIdx()}";
|
||||
GameObject lastObj = GameObject.Find(last);
|
||||
DestroyImmediate(lastObj);
|
||||
_curEditCellType = EditCellType.None;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (type == EditCellType.MonsterPath)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
string last = $"MonsterPath{_curMonsterPoint.areaIdx}{GetCurMonsterPathIdx()}";
|
||||
GameObject lastObj = GameObject.Find(last);
|
||||
DestroyImmediate(lastObj);
|
||||
_curEditCellType = EditCellType.None;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hitInfo;
|
||||
|
||||
if (Physics.Raycast(ray, out hitInfo))
|
||||
{
|
||||
GameObject gameObj = hitInfo.collider.gameObject;
|
||||
if (gameObj.layer != LayerMask.NameToLayer("MapCell"))
|
||||
return;
|
||||
|
||||
string[] point = gameObj.name.Split('_');
|
||||
if (point.Length != 2)
|
||||
{
|
||||
if (Input.GetMouseButtonUp(1))
|
||||
{
|
||||
int xx = (int)((gameObj.transform.localPosition.x - _cellWidth / 100.0f / 2) / (_cellWidth / 100.0f));
|
||||
int yy = (int)((gameObj.transform.localPosition.y - _cellHeight / 100.0f / 2) / (_cellHeight / 100.0f));
|
||||
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveList.Remove($"{xx}_{yy}");
|
||||
DestroyImmediate(gameObj);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int x, y;
|
||||
x = Convert.ToInt32(point[0]); //<2F><>
|
||||
y = Convert.ToInt32(point[1]); //<2F><>
|
||||
CreateSpecialPoint(x, y, type);
|
||||
|
||||
_curPathObj = gameObj;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EditCellType.ReturnCell:
|
||||
UIWindow.Instance.uiEditMapConfig.txtReturnMapCellPoint.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.TeleportCell:
|
||||
UIWindow.Instance.uiTeleportPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.NpcCell:
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.PathNodeCell:
|
||||
UIWindow.Instance.uiCellEditor.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.TriggerCell:
|
||||
UIWindow.Instance.uiTriggersPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.AudioTrigger:
|
||||
UIWindow.Instance.uiAudioTriggerPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.ReliveCell:
|
||||
UIWindow.Instance.uiRelivesPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.SellArea:
|
||||
UIWindow.Instance.uiSellAreasPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.MonsterArea:
|
||||
UIWindow.Instance.uiMonstersPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.FuBenArea:
|
||||
UIWindow.Instance.uiFuBensPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
case EditCellType.JuBaoArea:
|
||||
UIWindow.Instance.uiJuBaosPanel.curActiveInput.text = gameObj.name.Replace('_', ',');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadSprite(string spName, GameObject go, int regionWidth=0, int regionHeight=0)
|
||||
{
|
||||
StartCoroutine(LoadSpriteCor(spName, go, regionWidth, regionHeight));
|
||||
}
|
||||
|
||||
IEnumerator LoadSpriteCor(string spName, GameObject go, int regionWidth, int regionHeight)
|
||||
{
|
||||
string spPath = PathUtil.GetTexture(_curOpenMapId, spName, "jpg");
|
||||
|
||||
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(spPath))
|
||||
{
|
||||
yield return req.SendWebRequest();
|
||||
if (req.result == UnityWebRequest.Result.ConnectionError)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage(req.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
Texture2D tt = DownloadHandlerTexture.GetContent(req);
|
||||
if (tt == null)
|
||||
yield break;
|
||||
|
||||
//<2F><><EFBFBD>ݻ<EFBFBD>ȡ<EFBFBD><C8A1>Texture<72><65><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>sprite
|
||||
//Sprite sprite = Sprite.Create((Texture2D)tt, new Rect(0, 0, tt.width, tt.height), new Vector2(0, 0));
|
||||
//sprite.name = spName;
|
||||
//go.GetComponent<Image>().sprite = sprite;
|
||||
tt.name = spName;
|
||||
go.GetComponent<RawImage>().texture = tt;
|
||||
go.GetComponent<RectTransform>().sizeDelta = new Vector2(regionWidth, regionHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Map/MapManager.cs.meta
Normal file
11
Assets/Scripts/Map/MapManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7cce2a4c6c6cc14f876c47961979fb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user