提交
This commit is contained in:
@@ -557,7 +557,7 @@ public partial class MapManager : MonoBehaviour
|
||||
|
||||
|
||||
if (cellType < EditCellType.AudioTrigger)
|
||||
obj = _cellAsset;
|
||||
obj = null;
|
||||
else if (cellType == EditCellType.AudioTrigger)
|
||||
obj = Resources.Load("Prefabs/audioTriggerCenterPoint");
|
||||
else if (cellType == EditCellType.TriggerCell)
|
||||
@@ -714,26 +714,6 @@ public partial class MapManager : MonoBehaviour
|
||||
SetGameObjectActiveWithAllChild(cellsTrans, true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int y = 0; y < _cellRows; y++)
|
||||
{
|
||||
for (int x = 0; x < _cellCols; x++)
|
||||
{
|
||||
CellNode cell = GetCell(x, y);
|
||||
|
||||
GameObject go = Instantiate(_cellAsset) as GameObject;
|
||||
go.name = $"{x}_{y}"; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD><5F>
|
||||
go.transform.SetParent(cellsTrans, false);
|
||||
go.transform.localScale = new Vector3(((float)_cellWidth / CELLSCALE) - 0.1f, ((float)_cellHeight / CELLSCALE) - 0.1f, 1);
|
||||
//2d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Vector3 pos = cell.GetPos((float)_cellWidth / CELLSCALE, (float)_cellHeight / CELLSCALE);
|
||||
go.transform.localPosition = new Vector3(pos.x, pos.z, pos.y);
|
||||
go.layer = LayerMask.NameToLayer("MapCell");
|
||||
ShowCellType(go, cell.cellType);
|
||||
AddLayerCell(go, (CellLayer)cell.cellType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void HideCells()
|
||||
|
||||
@@ -5,6 +5,8 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
||||
using System.Security.Policy;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using UnityEditor;
|
||||
@@ -12,10 +14,14 @@ using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using static MapManager;
|
||||
|
||||
public partial class MapManager : MonoBehaviour
|
||||
{
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform mapRegion;
|
||||
public Dictionary<string, (int maxRow, int maxCol)> allMaps = new Dictionary<string, (int maxRow, int maxCol)>();
|
||||
public bool LoadObsXml()
|
||||
{
|
||||
if (_curOpenMapId < 0)
|
||||
@@ -83,51 +89,119 @@ public partial class MapManager : MonoBehaviour
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void LoadMapSprite()
|
||||
|
||||
public void LoadMapRegions(int mapId)
|
||||
{
|
||||
//map<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
GameObject map = new GameObject("map");
|
||||
int mapRownum = 11;
|
||||
int mapColumn = 14;
|
||||
_curOpenMapId = mapId;
|
||||
if (!allMaps.TryGetValue(mapId.ToString(),out var mapInfo))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD><DAA1><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
int mapRownum = mapInfo.maxRow;
|
||||
int mapColumn = mapInfo.maxCol;
|
||||
//ƽ<><C6BD>;
|
||||
float jpgscenew = 512f / 100;
|
||||
|
||||
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
|
||||
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, 0.48f, 0.32f);
|
||||
for (int row = 0; row < mapRownum; row++)
|
||||
{
|
||||
for (int col = 0; col < mapColumn; col++)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>v1000_r1_c1.jpg
|
||||
string filename = $"v{1000}_r{row + 1}_c{col + 1}";
|
||||
string filename = $"v{mapId}_r{row + 1}_c{col + 1}"; // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>v1000_r1_c1.jpg
|
||||
string spPath = PathUtil.GetMapTexure(1000, filename, "jpg");
|
||||
GameObject obj = new GameObject(filename);
|
||||
obj.transform.SetParent(map.transform);
|
||||
obj.transform.SetParent(mapRegion);
|
||||
SpriteRenderer sr = obj.AddComponent<SpriteRenderer>();
|
||||
float x = col * jpgscenew;
|
||||
float y = (mapRownum - row - 1) * jpgscenew;
|
||||
obj.transform.position = new Vector2(x, y);
|
||||
StartCoroutine(LoadSpriteT(spPath, obj,sr));
|
||||
|
||||
multithreadLoadTextrue(spPath,sr);
|
||||
}
|
||||
}
|
||||
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
|
||||
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, 0.48f, 0.32f);
|
||||
}
|
||||
public void ClearMapRegions()
|
||||
{
|
||||
ClearMapGrid();
|
||||
foreach (Transform child in mapRegion)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
private async void multithreadLoadTextrue(string fullPath,SpriteRenderer sr)
|
||||
{
|
||||
var texture = await loadASyncTexture2D(fullPath, this.GetCancellationTokenOnDestroy());
|
||||
if (texture != null)
|
||||
{
|
||||
sr.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 100f);
|
||||
}
|
||||
}
|
||||
|
||||
private UniTask<Texture2D> loadASyncTexture2D(string fullPath,CancellationToken token)
|
||||
{
|
||||
return UniTask.RunOnThreadPool(async () =>
|
||||
{
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
Debug.LogError($"File not found: {fullPath}");
|
||||
return null;
|
||||
}
|
||||
// <20><><EFBFBD>̳߳<DFB3><CCB3><EFBFBD><EFBFBD>첽<EFBFBD><ECB2BD>ȡ<EFBFBD>ļ<EFBFBD>
|
||||
byte[] bytes = await File.ReadAllBytesAsync(fullPath, token);
|
||||
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̴߳<DFB3><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
await UniTask.Yield(PlayerLoopTiming.Update);
|
||||
Texture2D texture = new Texture2D(2, 2); // <20><>ʼ<EFBFBD><CABC>С
|
||||
if (texture.LoadImage(bytes))
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Failed to load image from {fullPath}");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
IEnumerator LoadSpriteT(string spName, GameObject go, SpriteRenderer sprite)
|
||||
{
|
||||
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(spName))
|
||||
{
|
||||
yield return req.SendWebRequest();
|
||||
if (req.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
Texture2D tt = DownloadHandlerTexture.GetContent(req);
|
||||
if (tt == null)
|
||||
yield break;
|
||||
sprite.sprite = Sprite.Create(tt, new Rect(0, 0, tt.width, tt.height), Vector2.zero, 100f);
|
||||
}
|
||||
else
|
||||
if (File.Exists(spName))
|
||||
{
|
||||
byte[] bytes = File.ReadAllBytes(spName);
|
||||
Texture2D texture = new Texture2D(2, 2); // <20><>ʼ<EFBFBD><CABC>С<EFBFBD><D0A1><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (texture.LoadImage(bytes)) // <20><><EFBFBD><EFBFBD> JPG <20><> Texture2D
|
||||
{
|
||||
UIWindow.Instance.ShowMessage(req.error);
|
||||
}
|
||||
}
|
||||
sprite.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 100f);
|
||||
Debug.Log($"Loaded {spName} successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Failed to load image from {spName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"File not found: {spName}");
|
||||
}
|
||||
yield break;
|
||||
//using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(spName))
|
||||
//{
|
||||
// yield return req.SendWebRequest();
|
||||
// if (req.result == UnityWebRequest.Result.Success)
|
||||
// {
|
||||
// Texture2D tt = DownloadHandlerTexture.GetContent(req);
|
||||
// if (tt == null)
|
||||
// yield break;
|
||||
// sprite.sprite = Sprite.Create(tt, new Rect(0, 0, tt.width, tt.height), Vector2.zero, 100f);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// UIWindow.Instance.ShowMessage(req.error);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
internal void SaveCellsXml()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,9 @@ public partial class MapManager : MonoBehaviour
|
||||
public event Action onMapCreated;
|
||||
|
||||
public CellType cellType;
|
||||
public Map GenerateMap(float width, float height,float sideWidth, float sideHeight)
|
||||
public Map GenerateMap(float width, float height, float sideWidth, float sideHeight)
|
||||
{
|
||||
if (map != null)
|
||||
{
|
||||
map.Release();
|
||||
map = null;
|
||||
}
|
||||
ClearMapGrid();
|
||||
map = new Map(width, height, sideWidth, sideHeight);
|
||||
map.SetMapId(1000);
|
||||
//默认设置半透明0.3
|
||||
@@ -28,6 +24,25 @@ public partial class MapManager : MonoBehaviour
|
||||
onMapCreated?.Invoke();
|
||||
return map;
|
||||
}
|
||||
public void ClearMapGrid()
|
||||
{
|
||||
if (map != null)
|
||||
{
|
||||
map.Release();
|
||||
map = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void HideMapGrid()
|
||||
{
|
||||
if(map != null && map.mapGrid != null)
|
||||
map.mapGrid.gameObject.SetActive(false);
|
||||
}
|
||||
public void ShowMapGrid()
|
||||
{
|
||||
if (map != null && map.mapGrid != null)
|
||||
map.mapGrid.gameObject.SetActive(true);
|
||||
}
|
||||
public void ChangeGridAlpha(float alpha)
|
||||
{
|
||||
if (map == null)
|
||||
|
||||
@@ -47,7 +47,7 @@ public partial class MapManager : MonoBehaviour
|
||||
private int _cellCols;
|
||||
//public CellNode[,] cellNodes;
|
||||
|
||||
private int _curOpenMapId;
|
||||
public int _curOpenMapId;
|
||||
|
||||
private Material _cellMoveMat;
|
||||
private Material _cellObsMat;
|
||||
@@ -73,24 +73,10 @@ public partial class MapManager : MonoBehaviour
|
||||
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");
|
||||
@@ -102,7 +88,6 @@ public partial class MapManager : MonoBehaviour
|
||||
_cellTeleportMat = Resources.Load<Material>("Materials/cellTeleportMat");
|
||||
_cellNpcMat = Resources.Load<Material>("Materials/cellNpcMat");
|
||||
_cellPathNodeMat = Resources.Load<Material>("Materials/cellPathNodeMat");
|
||||
UIWindow.Instance.uiCreateMap.onCreatedMapCallback += OnCreatedMap;
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
@@ -122,7 +107,6 @@ public partial class MapManager : MonoBehaviour
|
||||
}
|
||||
|
||||
_StartEditor = true;
|
||||
_curEditCellType = EditCellType.None;
|
||||
}
|
||||
|
||||
public void CloseEditor()
|
||||
@@ -136,80 +120,15 @@ public partial class MapManager : MonoBehaviour
|
||||
_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();
|
||||
|
||||
ClearMapRegions();
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
@@ -228,7 +147,6 @@ public partial class MapManager : MonoBehaviour
|
||||
_StartEditor = false;
|
||||
_brushRadius = 0;
|
||||
_brushCellType = CellType.None;
|
||||
cellsNode = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -238,175 +156,8 @@ public partial class MapManager : MonoBehaviour
|
||||
if (bHoverUI)
|
||||
return;
|
||||
UpdateCamera();
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -209,7 +209,6 @@ public class UICellEditor : MonoBehaviour
|
||||
//<2F>༭<EFBFBD><E0BCAD>Ч
|
||||
public void OnShowEffectsToggleChange()
|
||||
{
|
||||
UIWindow.Instance.uiCreateMap.MapBG.GetComponent<CanvasGroup>().blocksRaycasts = true;
|
||||
MapManager.Instance.HideCells();
|
||||
UIWindow.Instance.ShowMouseOver();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ public class UICellInfo : MonoBehaviour
|
||||
private void Start()
|
||||
{
|
||||
MapManager.Instance.onLoadFinishedCallback = OnLoadFinished;
|
||||
UIWindow.Instance.uiCreateMap.onCreatedMapCallback += OnCreatedMap;
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
@@ -82,41 +81,12 @@ public class UICellInfo : MonoBehaviour
|
||||
|
||||
public void ShowCells()
|
||||
{
|
||||
if (!bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (MapManager.Instance.CellRows <= 0)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
UIWindow.Instance.uiCreateMap.MapBG.GetComponent<CanvasGroup>().blocksRaycasts = false;
|
||||
MapManager.Instance.CreateCells();
|
||||
|
||||
txtMoveCells.text = MapManager.Instance.GetLayCellCount(CellLayer.Move).ToString();
|
||||
MapManager.Instance.ShowMapGrid();
|
||||
}
|
||||
|
||||
public void HideCells()
|
||||
{
|
||||
if (!bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (MapManager.Instance.CellRows <= 0)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
UIWindow.Instance.uiCreateMap.MapBG.GetComponent<CanvasGroup>().blocksRaycasts = true;
|
||||
MapManager.Instance.HideCells();
|
||||
|
||||
MapManager.Instance.HideMapGrid();
|
||||
}
|
||||
|
||||
public void CalculationCells()
|
||||
|
||||
@@ -105,31 +105,7 @@ public class UIEditMapConfig : MonoBehaviour
|
||||
}
|
||||
|
||||
private void OnInputFieldClicked(BaseEventData data)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼID<49><44><EFBFBD>õ<EFBFBD>ͼһ<CDBC>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
//TODO: <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
||||
if (data.selectedObject.name.Equals("InputReturnPoint"))
|
||||
{
|
||||
if (!txtReturnMapId.text.Equals(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||||
{
|
||||
MapManager.Instance.RemoveSpecialPoint(MapManager.EditCellType.ReturnCell);
|
||||
return;
|
||||
}
|
||||
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.ReturnCell);
|
||||
}
|
||||
//else if (data.selectedObject.name.Equals("InputRelivePoint"))
|
||||
//{
|
||||
// if (!txtReliveMapId.text.Equals(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||||
// {
|
||||
// MapManager.Instance.RemoveSpecialPoint(MapManager.EditCellType.ReliveCell);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// MapManager.Instance.SetEditCellType(MapManager.EditCellType.ReliveCell);
|
||||
//}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -257,12 +233,6 @@ public class UIEditMapConfig : MonoBehaviour
|
||||
|
||||
bool CheckValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ͼID");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(txtMapName.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>");
|
||||
@@ -467,9 +437,7 @@ public class UIEditMapConfig : MonoBehaviour
|
||||
config.time = Convert.ToInt32(item.txtTime.text);
|
||||
mc.conditionsConfig.Add(config);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
mc.SaveXML(mapId);
|
||||
mc.SaveXML(MapManager.Instance._curOpenMapId);
|
||||
}
|
||||
|
||||
public void LoadMapConfig(int mapId)
|
||||
@@ -483,9 +451,6 @@ public class UIEditMapConfig : MonoBehaviour
|
||||
txtReturnMapId.text = mc.returnMapId.ToString();
|
||||
txtReturnMapCellPoint.text = $"{mc.returnMapCellPoint.x},{mc.returnMapCellPoint.y}";
|
||||
|
||||
if (txtReturnMapId.text.Equals(UIWindow.Instance.uiCreateMap.txtMapID.text))
|
||||
MapManager.Instance.CreateSpecialPoint(mc.returnMapCellPoint.x, mc.returnMapCellPoint.y, MapManager.EditCellType.ReturnCell);
|
||||
|
||||
if ((mc.roleMode & RoleMode.PK) != 0)
|
||||
togModePK.isOn = true;
|
||||
if ((mc.roleMode & RoleMode.ShiZu) != 0)
|
||||
|
||||
@@ -94,7 +94,7 @@ public class UIFuBensPanel : MonoBehaviour
|
||||
mc.fubenConfigs.Add(monster);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class UIJuBaoPanel : MonoBehaviour
|
||||
mc.jubaoConfigs.Add(jubao);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -9,11 +10,9 @@ using UnityEngine.UI;
|
||||
///<2F><><EFBFBD>ܣ<EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>رյ<D8B1>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public class UIMapPanel : MonoBehaviour
|
||||
{
|
||||
public List<string> allMaps = new List<string>();
|
||||
public Dropdown dropMap;
|
||||
private int _curOpenMapId;
|
||||
private bool _saving;
|
||||
|
||||
public int CurOpenMapId => _curOpenMapId;
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -21,50 +20,85 @@ public class UIMapPanel : MonoBehaviour
|
||||
{
|
||||
_saving = false;
|
||||
_curOpenMapId = -1;
|
||||
|
||||
UIWindow.Instance.uiCreateMap.onCreatedMapCallback += OnCreatedMap;
|
||||
}
|
||||
|
||||
void OnDataLoaded()
|
||||
{
|
||||
string[] AllFilePath = Directory.GetDirectories(Application.dataPath + "/GameAssets/Maps");
|
||||
for (int i = 0; i < AllFilePath.Length; i++)
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD>ͼ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
string mapsDirectory = Path.Combine(Application.dataPath, "GameAssets", "Maps");
|
||||
if (!Directory.Exists(mapsDirectory))
|
||||
{
|
||||
string[] pathSplit = AllFilePath[i].Split('/');
|
||||
string[] pathSplit2 = pathSplit[pathSplit.Length - 1].Split('\\');
|
||||
allMaps.Add(pathSplit2[pathSplit2.Length - 1]);
|
||||
Debug.LogError($"Maps directory not found: {mapsDirectory}");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] mapFolders = Directory.GetDirectories(mapsDirectory);
|
||||
foreach (string folderPath in mapFolders)
|
||||
{
|
||||
string[] pathSplit = folderPath.Split(Path.DirectorySeparatorChar);
|
||||
string mapId = pathSplit[pathSplit.Length - 1]; // <20><><EFBFBD><EFBFBD> "v1000"
|
||||
|
||||
string textureDirectory = Path.Combine(folderPath, "Texture");
|
||||
if (Directory.Exists(textureDirectory))
|
||||
{
|
||||
string[] imageFiles = Directory.GetFiles(textureDirectory, "*.jpg");
|
||||
int maxRow = 0;
|
||||
int maxCol = 0;
|
||||
string pattern = $@"{mapId}_r(\d+)_c(\d+)"; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ƥ<EFBFBD><C6A5> v1000_rXX_cYY
|
||||
Regex regex = new Regex(pattern);
|
||||
|
||||
foreach (string filePath in imageFiles)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(filePath); // <20><><EFBFBD><EFBFBD> "v1000_r11_c14"
|
||||
Match match = regex.Match(fileName);
|
||||
if (match.Success)
|
||||
{
|
||||
if (int.TryParse(match.Groups[1].Value, out int row) && int.TryParse(match.Groups[2].Value, out int col))
|
||||
{
|
||||
maxRow = Mathf.Max(maxRow, row);
|
||||
maxCol = Mathf.Max(maxCol, col);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Filename {fileName} does not match expected pattern: {pattern}");
|
||||
}
|
||||
}
|
||||
|
||||
if (maxRow > 0 && maxCol > 0)
|
||||
{
|
||||
MapManager.Instance.allMaps[mapId] = (maxRow, maxCol);
|
||||
Debug.Log($"Map {mapId} loaded with max dimensions: {maxRow}x{maxCol}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"No valid dimensions found for map {mapId}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Texture directory not found for map {mapId}: {textureDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ScanMap()
|
||||
{
|
||||
allMaps.Clear();
|
||||
{
|
||||
MapManager.Instance.allMaps.Clear();
|
||||
|
||||
OnDataLoaded();
|
||||
|
||||
dropMap.options.Clear();
|
||||
|
||||
for (int i=0; i<allMaps.Count; i++)
|
||||
{
|
||||
foreach (var map in MapManager.Instance.allMaps)
|
||||
{
|
||||
Dropdown.OptionData od = new Dropdown.OptionData();
|
||||
od.text = allMaps[i];
|
||||
od.text = map.Key;
|
||||
dropMap.options.Add(od);
|
||||
}
|
||||
|
||||
dropMap.value = 1;
|
||||
dropMap.value = 0; //Ϊ<><CEAA>Ĭ<EFBFBD><C4AC>ѡ<EFBFBD>е<EFBFBD>һ<EFBFBD><D2BB>
|
||||
}
|
||||
|
||||
private void OnCreatedMap(int mapId, int mapWidth, int mapHeight)
|
||||
{
|
||||
ScanMap();
|
||||
allMaps.Add(mapId.ToString());
|
||||
Dropdown.OptionData od = new Dropdown.OptionData();
|
||||
od.text = mapId.ToString();
|
||||
dropMap.options.Add(od);
|
||||
dropMap.value = dropMap.options.Count - 1;
|
||||
}
|
||||
|
||||
public void OpenMap()
|
||||
{
|
||||
if(dropMap.options.Count == 0)
|
||||
@@ -82,18 +116,18 @@ public class UIMapPanel : MonoBehaviour
|
||||
int mapId = 0;
|
||||
|
||||
mapId = Convert.ToInt32(dropMap.options[dropMap.value].text);
|
||||
UIWindow.Instance.uiCreateMap.LoadMapRegions(mapId);
|
||||
UIWindow.Instance.uiCellInfo.LoadCells();
|
||||
UIWindow.Instance.uiCellInfo.ShowCells();
|
||||
UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId);
|
||||
UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId);
|
||||
UIWindow.Instance.uiNpcsPanel.LoadNpcsConfig(mapId);
|
||||
UIWindow.Instance.uiTriggersPanel.LoadTriggersConfig(mapId);
|
||||
UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId);
|
||||
UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId);
|
||||
//UIWindow.Instance.uiCreateMap.LoadMapRegions(mapId);
|
||||
//UIWindow.Instance.uiCellInfo.LoadCells();
|
||||
//UIWindow.Instance.uiCellInfo.ShowCells();
|
||||
//UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId);
|
||||
//UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId);
|
||||
//UIWindow.Instance.uiNpcsPanel.LoadNpcsConfig(mapId);
|
||||
//UIWindow.Instance.uiTriggersPanel.LoadTriggersConfig(mapId);
|
||||
//UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId);
|
||||
//UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId);
|
||||
|
||||
_curOpenMapId = mapId;
|
||||
//MapManager.Instance.LoadMapSprite();
|
||||
MapManager.Instance.LoadMapRegions(_curOpenMapId);
|
||||
}
|
||||
|
||||
public void CloseMap()
|
||||
@@ -105,7 +139,7 @@ public class UIMapPanel : MonoBehaviour
|
||||
|
||||
public bool HasMap(string mapId)
|
||||
{
|
||||
return allMaps.Find(s => s == mapId) != null;
|
||||
return MapManager.Instance.allMaps.ContainsKey(mapId);
|
||||
}
|
||||
|
||||
public void ResetMap()
|
||||
@@ -145,7 +179,7 @@ public class UIMapPanel : MonoBehaviour
|
||||
{
|
||||
_saving = true;
|
||||
Debug.Log("<22><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
|
||||
UIWindow.Instance.uiCreateMap.SaveRegions();
|
||||
//UIWindow.Instance.uiCreateMap.SaveRegions();
|
||||
UIWindow.Instance.uiCellEditor.SaveCells();
|
||||
UIWindow.Instance.uiEditMapConfig.SaveMapConfig();
|
||||
UIWindow.Instance.uiMonstersPanel.SaveMonsterConfig();
|
||||
|
||||
@@ -372,7 +372,7 @@ public class UIMonsterPanel : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class UIMonstersPanel_old : MonoBehaviour
|
||||
mc.monsterConfigs.Add(monster);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class UINpcsPanel : MonoBehaviour
|
||||
nc.npcConfigs.Add(npc);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
nc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,9 +82,9 @@ public class UITriggerPanel : MonoBehaviour
|
||||
t.eventId = Convert.ToInt32(item.txtEvent.text);
|
||||
|
||||
ts.triggersConfig.Add(t);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
}
|
||||
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
ts.SaveXML(mapId);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ public class UIWindow : MonoBehaviour
|
||||
public UIMapPanel uiMapPanel;
|
||||
public UICellInfo uiCellInfo;
|
||||
public UICellEditor uiCellEditor;
|
||||
public UICreateMap uiCreateMap;
|
||||
public UIEditMapConfig uiEditMapConfig;
|
||||
public UITeleportPanel uiTeleportPanel;
|
||||
public UIRelivesPanel uiRelivesPanel;
|
||||
@@ -55,7 +54,6 @@ public class UIWindow : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
uiCreateMap.onCreatedMapCallback += OnCreatedMap;
|
||||
uiMonstersPanel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user