This commit is contained in:
tangbin
2025-06-22 15:21:25 +08:00
parent 89d395440a
commit 1cb6dc502f
22 changed files with 2241 additions and 7346 deletions

View File

@@ -84,6 +84,8 @@ public class GridSelector : MonoBehaviour
{
return getMapGrid(new Vector2(pos.x,pos.y));
}
public Vector2Int getMapGrid(Vector2 pos)
{
var grid = new Vector2Int();
@@ -91,6 +93,10 @@ public class GridSelector : MonoBehaviour
grid.y = Mathf.FloorToInt(pos.y / map.sideHeight);
return grid;
}
public Vector2 getPosByGrid(Vector2Int grid)
{
return new Vector2(grid.x * map.sideWidth + map.sideWidth/2, grid.y * map.sideHeight + map.sideHeight / 2);
}
private void Awake()
{
mapRenderer = GetComponent<MeshRenderer>();

View File

@@ -3,7 +3,10 @@ using HxGame.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public partial class MapManager : MonoBehaviour
@@ -83,12 +86,6 @@ public partial class MapManager : MonoBehaviour
public void SetEditCellType(EditCellType type)
{
if(cellsNode == null || cellsNode.Length == 0)
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>");
return;
}
_curEditCellType = type;
}
@@ -148,6 +145,7 @@ public partial class MapManager : MonoBehaviour
_curPathNodePointIdx = idx;
}
//<2F><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
public void SetCurAudioTriggerCenterPoint(int idx, int radius)
{
@@ -401,13 +399,14 @@ public partial class MapManager : MonoBehaviour
return cellName;
}
public void ShowSpecialPoint(EditCellType cellType)
{
int size = 0;
string cellName = GetSpecialName(cellType, out size);
if(cellType == EditCellType.MonsterArea)
//TODO tb <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SetEditCellType(cellType);
if (cellType == EditCellType.MonsterArea)
{
}
}
@@ -471,15 +470,11 @@ public partial class MapManager : MonoBehaviour
DestroyImmediate(mapAreaParent.Find(cellName).gameObject);
}
}
public void CreateSpecialPoint(int x, int y, EditCellType cellType)
{
if (_curOpenMapId <= 0)
return;
UnityEngine.Object obj = null;
if (cellType < EditCellType.AudioTrigger)
obj = null;
else if (cellType == EditCellType.AudioTrigger)
@@ -500,66 +495,57 @@ public partial class MapManager : MonoBehaviour
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>cell.prefabʧ<62><CAA7>");
return;
}
string cellName = string.Empty;
Material mat = null;
Vector3 localScale = Vector3.zero;
int Idx = 0;
switch (cellType)
{
case EditCellType.ReturnCell:
cellName = "<22>سǵ<D8B3>";
mat = _cellReturnMat;
break;
case EditCellType.TeleportCell:
cellName = $"<22><><EFBFBD>͵<EFBFBD>{_curTeleportPointIdx}";
mat = _cellTeleportMat;
Idx = _curTeleportPointIdx;
break;
case EditCellType.NpcCell:
cellName = $"Npc{_curNpcPointIdx}";
mat = _cellNpcMat;
Idx = _curNpcPointIdx;
break;
case EditCellType.PathNodeCell:
cellName = $"PathNode{_curPathNodePointIdx}";
mat = _cellPathNodeMat;
Idx = _curPathNodePointIdx;
break;
case EditCellType.AudioTrigger:
cellName = $"<22><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>{_curAudioTriggerCenterPoint.areaIdx}";
localScale = new Vector3(0.9f * _curAudioTriggerCenterPoint.radius * 2, 0.9f * _curAudioTriggerCenterPoint.radius * 2, 1);
Idx = _curAudioTriggerCenterPoint.areaIdx;
break;
case EditCellType.TriggerCell:
cellName = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{_curTriggerCenterPoint.areaIdx}";
localScale = new Vector3(0.9f * _curTriggerCenterPoint.radius * 2, 0.9f * _curTriggerCenterPoint.radius * 2, 1);
Idx = _curTriggerCenterPoint.areaIdx;
break;
case EditCellType.ReliveCell:
cellName = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{_curReliveCenterPoint.areaIdx}";
localScale = new Vector3(0.9f * _curReliveCenterPoint.radius * 2, 0.9f * _curReliveCenterPoint.radius * 2, 1);
break;
case EditCellType.SellArea:
cellName = $"<22><>̯<EFBFBD><CCAF>{_curSellAreaCenterPoint.areaIdx}";
localScale = new Vector3(0.9f * _curSellAreaCenterPoint.radius * 2, 0.9f * _curSellAreaCenterPoint.radius * 2, 1);
Idx = _curReliveCenterPoint.areaIdx;
break;
case EditCellType.MonsterArea:
cellName = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{_curMonsterPoint.areaIdx}";
localScale = new Vector3(0.9f * _curMonsterPoint.radius * 2, 0.9f * _curMonsterPoint.radius * 2, 1);
if (localScale == Vector3.forward)
localScale = new Vector3(0.5f, 0.5f, 1);
Idx = _curMonsterPoint.areaIdx;
break;
case EditCellType.FuBenArea:
cellName = $"<22><><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>{_curFuBenPoint.areaIdx}";
localScale = new Vector3(0.9f * _curFuBenPoint.radius * 2, 0.9f * _curFuBenPoint.radius * 2, 1);
Idx = _curMonsterPoint.areaIdx;
break;
case EditCellType.JuBaoArea:
cellName = $"<22>۱<EFBFBD><DBB1><EFBFBD>{_curJuBaoPoint.areaIdx}";
localScale = new Vector3(0.9f * _curJuBaoPoint.radius * 2, 0.9f * _curJuBaoPoint.radius * 2, 1);
Idx = _curJuBaoPoint.areaIdx;
break;
case EditCellType.NpcPath:
cellName = $"NpcPath{_curNpcPointIdx}{GetCurNpcPathIdx()}";
mat = _cellPathNodeMat;
Idx = _curNpcPointIdx;
break;
case EditCellType.MonsterPath:
cellName = $"MonsterPath{_curMonsterPoint.areaIdx}{GetCurMonsterPathIdx()}";
mat = _cellPathNodeMat;
Idx = _curMonsterPoint.areaIdx;
break;
}
@@ -572,42 +558,34 @@ public partial class MapManager : MonoBehaviour
{
go = Instantiate(obj) as GameObject;
go.transform.SetParent(mapAreaParent, false);
go.transform.localScale = new Vector3(((float)_cellWidth / CELLSCALE) - 0.1f, ((float)_cellHeight / CELLSCALE) - 0.1f, 1);
}
CellNode cell = GetCell(x, y);
Vector3 pos = cell.GetPos((float)_cellWidth / CELLSCALE, (float)_cellHeight / CELLSCALE);
go.transform.localPosition = new Vector3(pos.x, pos.z, pos.y);
var sceneArea = go.GetComponent<SceneArea>();
sceneArea.SetSceneAreaData(cellType, Idx);
sceneArea.SetAreaPos(new Vector2Int(x, y));
go.name = cellName;
if (cellType < EditCellType.AudioTrigger)
go.GetComponent<MeshRenderer>().material = mat;
else
go.transform.localScale = localScale;
if(cellType == EditCellType.MonsterArea)
{
go.transform.Find("Name").GetComponent<Text>().text = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{_curMonsterPoint.areaIdx}";
go.transform.Find("ID").GetComponent<Text>().text = "ID:" + _curMonsterPoint.id.ToString();
go.transform.Find("Num").GetComponent<Text>().text = "Num:" + _curMonsterPoint.num.ToString();
go.transform.Find("Name").GetComponent<TextMeshPro>().text = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{_curMonsterPoint.areaIdx}";
go.transform.Find("ID").GetComponent<TextMeshPro>().text = "ID:" + _curMonsterPoint.id.ToString();
go.transform.Find("Num").GetComponent<TextMeshPro>().text = "Num:" + _curMonsterPoint.num.ToString();
float scaleX = MapManager.Instance.map.sideWidth * _curMonsterPoint.radius * 2;
float scaleY = MapManager.Instance.map.sideHeight * _curMonsterPoint.radius * 2;
go.transform.localScale = new Vector3(scaleX,scaleY,1);
}
else if (cellType == EditCellType.FuBenArea)
{
go.transform.Find("Order").GetComponent<Text>().text = _curFuBenPoint.areaIdx.ToString();
go.transform.Find("ID").GetComponent<Text>().text = "ID:" + _curFuBenPoint.id.ToString();
go.transform.Find("Num").GetComponent<Text>().text = "Num:" + _curFuBenPoint.num.ToString();
go.transform.Find("Order").GetComponent<TextMeshPro>().text = _curFuBenPoint.areaIdx.ToString();
go.transform.Find("ID").GetComponent<TextMeshPro>().text = "ID:" + _curFuBenPoint.id.ToString();
go.transform.Find("Num").GetComponent<TextMeshPro>().text = "Num:" + _curFuBenPoint.num.ToString();
}
else if (cellType == EditCellType.JuBaoArea)
{
go.transform.Find("ID").GetComponent<Text>().text = "ID:" + _curJuBaoPoint.id.ToString();
//go.transform.Find("Num").GetComponent<Text>().text = "Num:" + _curJuBaoPoint.num.ToString();
go.transform.Find("ID").GetComponent<TextMeshPro>().text = "ID:" + _curJuBaoPoint.id.ToString();
}
else if(cellType == EditCellType.TriggerCell)
{
go.transform.GetChild(0).GetComponent<Text>().text = _curTriggerCenterPoint.text;
go.transform.GetChild(0).GetComponent<TextMeshPro>().text = _curTriggerCenterPoint.text;
}
}
public int GetLayCellCount(CellType lay)
@@ -991,4 +969,51 @@ public partial class MapManager : MonoBehaviour
cells.Clear();
}
public bool isDragging = false;
public Vector3 downPos;
public SceneArea currentComponent;
private void UpdateCellPos()
{
if (Input.GetMouseButtonDown(0))
{
if (EventSystem.current.IsPointerOverGameObject())
return;
int hitLayer = (1 << LayerMask.NameToLayer("MapCell"));
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector2 rayOrigin = ray.origin;
Vector2 rayDirection = ray.direction;
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, rayDirection, Mathf.Infinity, hitLayer);
if (hit.collider != null)
{
var mouseComponent = hit.collider.transform.GetComponent<SceneArea>();
if (mouseComponent != null)
{
if (mouseComponent.editCellType != _curEditCellType)
return;
mouseComponent.OnPointerClick();
currentComponent = mouseComponent;
}
downPos = Input.mousePosition;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק
if (Input.GetMouseButton(0))
{
if (Input.mousePosition != downPos || isDragging)
{
isDragging = true;
// <20><><EFBFBD><EFBFBD> AreaComponent <20><><EFBFBD><EFBFBD>ק<EFBFBD><D7A7><EFBFBD><EFBFBD>
currentComponent?.OnPointerDrag(Input.mousePosition);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
if (Input.GetMouseButtonUp(0))
{
currentComponent?.OnPointerUp();
isDragging = false;
currentComponent = null;
}
}
}

View File

@@ -162,6 +162,7 @@ public partial class MapManager : MonoBehaviour
if (bHoverUI)
return;
UpdateCamera();
UpdateCellPos();
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using static MapManager;
public class SceneArea : MonoBehaviour
{
public EditCellType editCellType;
public int Idx;
public void SetSceneAreaData(EditCellType editCellType,int idx)
{
this.editCellType = editCellType;
Idx = idx;
}
public void OnPointerClick()
{
Debug.Log($"ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
}
public void OnPointerDrag(Vector3 mousePosition)
{
Vector2Int pos = MapManager.Instance.map.selector.GetMouseByCell();
SetAreaPos(pos);
}
public void OnPointerUp()
{
Debug.Log($"<22>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD><EFBFBD>...");
}
public void SetAreaPos(Vector2Int pos)
{
Vector3 realpos = MapManager.Instance.map.selector.getPosByGrid(pos);
transform.position = realpos;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da8bfab8f0be79c4c9e2da7d5086428b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
public static class UtilityClass
{
public static bool IsPosValidFormat(string value)
{
// 使用正则表达式判断格式是否为 x,y正整数
string pattern = @"^\d+,\d+$";
return Regex.IsMatch(value, pattern);
}
public static bool IsNumValidFormat(string value)
{
// 使用正则表达式判断是否为正整数
string pattern = @"^\d+$";
return Regex.IsMatch(value, pattern);
}
public static Vector2Int GetVector2Pos(string value)
{
if (IsPosValidFormat(value))
{
string[] parts = value.Split(',');
int x = int.Parse(parts[0]);
int y = int.Parse(parts[1]);
return new Vector2Int(x, y);
}
return Vector2Int.zero;
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7680110b20a47ca47a799c1b152ae93c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: