完善编辑器

This commit is contained in:
tangbin
2025-07-19 12:48:11 +08:00
parent 2df2efaa3e
commit b8b50ec90b
27 changed files with 360 additions and 124 deletions

View File

@@ -53,4 +53,16 @@ public partial class MapManager : MonoBehaviour
newPosition.y = Mathf.Clamp(y, 0, mapRealHeight);
Camera.main.transform.position = new Vector3(x, y, -10);
}
public Vector2Int GetCameraPos()
{
Vector2Int pos = new Vector2Int();
pos.x = (int)Camera.main.transform.position.x;
pos.y = (int)Camera.main.transform.position.y;
pos.x = Mathf.Clamp(pos.x, 0, (int)mapRealWidth);
pos.y = Mathf.Clamp(pos.y, 0, (int)mapRealHeight);
pos.x = (int)(pos.x / map.sideWidth);
pos.y = (int)(pos.y / map.sideHeight);
return pos;
}
}

View File

@@ -151,7 +151,6 @@ public partial class MapManager : MonoBehaviour
Destroy(child.gameObject);
}
UIWindow.Instance.uiCellInfo.CloseMap();
UIWindow.Instance.uiMonstersPanel.RemoveAll();
ClearMapRegions();
Cleanup();
}
@@ -171,6 +170,8 @@ public partial class MapManager : MonoBehaviour
_StartEditor = false;
_brushRadius = 0;
_brushCellType = CellType.None;
UIWindow.Instance.uiEditMapConfig.Cleanup();
}

View File

@@ -16,8 +16,9 @@ public class UIAudioTriggerItem : UIBaseItem
public int itemIdx;
// Start is called before the first frame update
void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;

View File

@@ -1,13 +1,23 @@
using Cysharp.Threading.Tasks.Triggers;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static MapManager;
public class UIBaseItem : MonoBehaviour
{
public SceneArea sceneArea { get; set; }
public EditCellType editCellType { get; set; }
public EditCellType editCellType { get; set; }
public Button btnClickSelf; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
protected virtual void Awake()
{
if (btnClickSelf == null) return;
btnClickSelf.onClick.AddListener(OnClickItemSelf);
}
public virtual void SetItemPos(Vector2Int pos) {
}

View File

@@ -80,7 +80,7 @@ public class UIEditMapConfig : MonoBehaviour
UIWindow.Instance.uiTeleportPanel.RemoveAll();
UIWindow.Instance.uiAudioTriggerPanel.RemoveAll();
UIWindow.Instance.uiSellAreasPanel.RemoveAll();
//UIWindow.Instance.uiMonstersPanel.RemoveAll();
UIWindow.Instance.uiMonstersPanel.RemoveAll();
UIWindow.Instance.uiNpcsPanel.RemoveAll();
UIWindow.Instance.uiTriggersPanel.RemoveAll();
UIWindow.Instance.uiConditionsPanel.RemoveAll();
@@ -116,7 +116,7 @@ public class UIEditMapConfig : MonoBehaviour
else
{
UIWindow.Instance.uiTeleportPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.TeleportCell);
MapManager.Instance?.HideSpecialPoint(MapManager.EditCellType.TeleportCell);
}
}
@@ -130,7 +130,7 @@ public class UIEditMapConfig : MonoBehaviour
else
{
UIWindow.Instance.uiRelivesPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.ReliveCell);
MapManager.Instance?.HideSpecialPoint(MapManager.EditCellType.ReliveCell);
}
}
@@ -144,7 +144,7 @@ public class UIEditMapConfig : MonoBehaviour
else
{
UIWindow.Instance.uiMonstersPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.MonsterArea);
MapManager.Instance?.HideSpecialPoint(MapManager.EditCellType.MonsterArea);
}
}
@@ -158,7 +158,7 @@ public class UIEditMapConfig : MonoBehaviour
else
{
UIWindow.Instance.uiNpcsPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.NpcCell);
MapManager.Instance?.HideSpecialPoint(MapManager.EditCellType.NpcCell);
}
}
@@ -172,7 +172,7 @@ public class UIEditMapConfig : MonoBehaviour
else
{
UIWindow.Instance.uiAudioTriggerPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.AudioTrigger);
MapManager.Instance?.HideSpecialPoint(MapManager.EditCellType.AudioTrigger);
}
}
@@ -186,7 +186,7 @@ public class UIEditMapConfig : MonoBehaviour
else
{
UIWindow.Instance.uiTriggersPanel.gameObject.SetActive(false);
MapManager.Instance.HideSpecialPoint(MapManager.EditCellType.TriggerCell);
MapManager.Instance?.HideSpecialPoint(MapManager.EditCellType.TriggerCell);
}
}

View File

@@ -21,8 +21,9 @@ public class UIFuBenItem : UIBaseItem
public int itemIdx;
// Start is called before the first frame update
void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;

View File

@@ -23,8 +23,9 @@ public class UIJuBaoItem : UIBaseItem
public int itemIdx;
// Start is called before the first frame update
void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;

View File

@@ -12,6 +12,7 @@ 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 ToggleGroup mapEditorGroup;
public Dropdown dropMap;
private int _curOpenMapId;
private bool _saving;
@@ -137,6 +138,10 @@ public class UIMapPanel : MonoBehaviour
{
MapManager.Instance.CloseMap();
_curOpenMapId = -1;
foreach (var toggle in mapEditorGroup.ActiveToggles())
{
toggle.isOn = false;
}
}
public bool HasMap(string mapId)

View File

@@ -27,7 +27,6 @@ public class UIMonsterItem : UIBaseItem
public Button btnDel; //ɾ<><C9BE>
public Button btnCopy; //<2F><><EFBFBD><EFBFBD>
public Button btnHide; //<2F><><EFBFBD><EFBFBD>
public Button btnClickSelf; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
public List<string> paths;
//public int itemIdx;
public int pathIdx;
@@ -36,12 +35,12 @@ public class UIMonsterItem : UIBaseItem
public MonstersConfig.MonsterConfig monster;
// Start is called before the first frame update
void Awake()
protected override void Awake()
{
base.Awake();
groupId = -1;
btnDel.onClick.AddListener(RemoveSelf);
paths = new List<string>();
btnClickSelf.onClick.AddListener(OnClickSelf);
btnCopy.onClick.AddListener(OnCopySelf);
btnHide.onClick.AddListener(OnHideSelf);
txtPos.onEndEdit.AddListener(OnEndEditPos);
@@ -147,15 +146,6 @@ public class UIMonsterItem : UIBaseItem
}
return true;
}
private void OnClickSelf()
{
if (OnClick == null)
return;
OnClick(this);
OnClickItemSelf();
}
private void OnCopySelf()
{
if (OnCopyItem == null)

View File

@@ -16,11 +16,12 @@ public class UINpcItem : UIBaseItem
public Button btnDel; //ɾ<><C9BE>
public List<string> paths;
public int itemIdx;
public int pathIdx;
// Start is called before the first frame update
void Awake()
{
public int pathIdx;
// Start is called before the first frame update
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
AddInputNameClickEvent(txtPath, true);
btnDel.onClick.AddListener(RemoveSelf);
@@ -65,17 +66,18 @@ public class UINpcItem : UIBaseItem
{
base.SetItemPos(pos);
txtPos.text = pos.ToString();
}
private void OnDestroy()
{
if (sceneArea == null) return;
DestroyImmediate(sceneArea.gameObject);
}
private void RemoveSelf()
{
DestroyImmediate(gameObject);
}
private void OnDestroy()
{
if (sceneArea == null) return;
DestroyImmediate(sceneArea.gameObject);
}
public bool CheckValid()
{
if (string.IsNullOrEmpty(txtID.text))

View File

@@ -35,8 +35,12 @@ public class UINpcsPanel : MonoBehaviour
GameObject go = Instantiate(obj) as GameObject; ;
go.transform.SetParent(itemParent, false);
int size = MapManager.Instance.AddNpcPointSize();
Vector2Int newPos = MapManager.Instance.GetCameraPos();
UINpcItem item = go.GetComponent<UINpcItem>();
item.SetItemPos(newPos);
item.itemIdx = size;
item.editCellType = MapManager.EditCellType.NpcCell;
MapManager.Instance.CreateSpecialPoint(newPos, item);
}
public void AddItem(NpcConfig nc)

View File

@@ -17,8 +17,9 @@ public class UIReliveItem : UIBaseItem
public int reliveIdx;
// Start is called before the first frame update
void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
reliveIdx = 0;
@@ -52,7 +53,16 @@ public class UIReliveItem : UIBaseItem
DestroyImmediate(gameObject);
MapManager.Instance.RemoveReliveCenterPoint(reliveIdx);
}
public override void SetItemPos(Vector2Int pos)
{
base.SetItemPos(pos);
txtPos.text = pos.ToString();
}
private void OnDestroy()
{
if (sceneArea == null) return;
DestroyImmediate(sceneArea.gameObject);
}
public bool CheckValid()
{
if (string.IsNullOrEmpty(txtMapId.text))

View File

@@ -25,11 +25,14 @@ public class UIRelivesPanel : MonoBehaviour
UIWindow.Instance.ShowMessage("reliveItem.prefabʧ<62><CAA7>");
return;
}
Vector2Int newPos = MapManager.Instance.GetCameraPos();
GameObject go = Instantiate(obj) as GameObject; ;
go.transform.SetParent(itemParent, false);
UIReliveItem item = go.GetComponent<UIReliveItem>();
item.reliveIdx = itemParent.childCount;
item.editCellType = MapManager.EditCellType.ReliveCell;
item.SetItemPos(newPos);
MapManager.Instance.CreateSpecialPoint(newPos, item);
}
public void AddItem(int reliveType, int mapId, Vector2Int pos, int radius, int realMapId)
@@ -52,7 +55,7 @@ public class UIRelivesPanel : MonoBehaviour
if (mapId != realMapId)
return;
item.editCellType = MapManager.EditCellType.ReliveCell;
MapManager.Instance.SetReliveCenterPoint(item.reliveIdx, radius);
MapManager.Instance.CreateSpecialPoint(pos, item);
}

View File

@@ -15,8 +15,9 @@ public class UISellAreaItem : UIBaseItem
public int itemIdx;
// Start is called before the first frame update
void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;

View File

@@ -12,9 +12,9 @@ public class UITeleportItem : UIBaseItem
public InputField txtNextMapPos; //<2F>¼<EFBFBD><C2BC><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
public Button btnDel; //ɾ<><C9BE>
public int itemIdx;
private void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
//AddInputNameClickEvent(txtNextMapPos);
btnDel.onClick.AddListener(RemoveSelf);
@@ -46,7 +46,16 @@ public class UITeleportItem : UIBaseItem
DestroyImmediate(gameObject);
MapManager.Instance.RemoveTeleportPointSize(itemIdx);
}
public override void SetItemPos(Vector2Int pos)
{
base.SetItemPos(pos);
txtPos.text = pos.ToString();
}
private void OnDestroy()
{
if (sceneArea == null) return;
Destroy(sceneArea.gameObject);
}
public bool CheckValid()
{
if (string.IsNullOrEmpty(txtPos.text))

View File

@@ -24,14 +24,16 @@ public class UITeleportPanel : MonoBehaviour
UIWindow.Instance.ShowMessage("teleportItem.prefabʧ<62><CAA7>");
return;
}
GameObject go = Instantiate(obj) as GameObject; ;
go.transform.SetParent(itemParent, false);
int size = MapManager.Instance.AddTeleportPointSize();
Vector2Int newPos = MapManager.Instance.GetCameraPos();
UITeleportItem item = go.GetComponent<UITeleportItem>();
item.itemIdx = size;
var gridPos = MapManager.Instance.map.selector.getMapGrid(Camera.main.transform.position);
MapManager.Instance.CreateSpecialPoint(gridPos, item);
item.editCellType = MapManager.EditCellType.TeleportCell;
item.SetItemPos(newPos);
MapManager.Instance.CreateSpecialPoint(newPos, item);
}
public void AddItem(Vector2Int pos, int nextMapId, Vector2Int newMapPos)
@@ -52,6 +54,7 @@ public class UITeleportPanel : MonoBehaviour
item.txtPos.text = $"{pos.x},{pos.y}";
item.txtNextMapID.text = nextMapId.ToString();
item.txtNextMapPos.text = $"{newMapPos.x},{newMapPos.y}";
item.editCellType = MapManager.EditCellType.TriggerCell;
MapManager.Instance.CreateSpecialPoint(pos, item);
}

View File

@@ -16,8 +16,9 @@ public class UITriggerItem : UIBaseItem
public Button btnDel; //ɾ<><C9BE>
public int itemIdx;
private void Awake()
protected override void Awake()
{
base.Awake();
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;