添加
This commit is contained in:
@@ -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>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,7 @@ public partial class MapManager : MonoBehaviour
|
||||
if (bHoverUI)
|
||||
return;
|
||||
UpdateCamera();
|
||||
UpdateCellPos();
|
||||
}
|
||||
|
||||
|
||||
|
||||
38
Assets/Scripts/Map/SceneArea.cs
Normal file
38
Assets/Scripts/Map/SceneArea.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16fab2e09ef3ffa4582b982dc9775080
|
||||
guid: da8bfab8f0be79c4c9e2da7d5086428b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
33
Assets/Scripts/Map/UtilityClass.cs
Normal file
33
Assets/Scripts/Map/UtilityClass.cs
Normal 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
|
||||
11
Assets/Scripts/Map/UtilityClass.cs.meta
Normal file
11
Assets/Scripts/Map/UtilityClass.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7680110b20a47ca47a799c1b152ae93c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,6 +6,7 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using static MapManager;
|
||||
|
||||
public class UIMonsterItem : MonoBehaviour
|
||||
{
|
||||
@@ -44,6 +45,19 @@ public class UIMonsterItem : MonoBehaviour
|
||||
btnClickSelf.onClick.AddListener(OnClickSelf);
|
||||
btnCopy.onClick.AddListener(OnCopySelf);
|
||||
btnHide.onClick.AddListener(OnHideSelf);
|
||||
txtPos.onEndEdit.AddListener(OnEndEditPos);
|
||||
}
|
||||
|
||||
private void OnEndEditPos(string arg0)
|
||||
{
|
||||
if (!UtilityClass.IsPosValidFormat(arg0))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>ʽ x,y");
|
||||
txtPos.text = $"{monster.pos.x},{monster.pos.y}";
|
||||
return;
|
||||
}
|
||||
monster.pos = UtilityClass.GetVector2Pos(arg0);
|
||||
MapManager.Instance.CreateSpecialPoint(monster.pos.x, monster.pos.y, MapManager.EditCellType.MonsterArea);
|
||||
}
|
||||
|
||||
//public void SetItem(int idx, MonstersConfig.MonsterConfig m)
|
||||
@@ -70,6 +84,10 @@ public class UIMonsterItem : MonoBehaviour
|
||||
txtMonsterID.text = monster.id.ToString();
|
||||
txtName.text = monster.id.ToString();
|
||||
paths = monster.paths;
|
||||
txtPos.text = monster.pos.ToString();
|
||||
//ˢ<>³<EFBFBD><C2B3><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
|
||||
MapManager.Instance.SetMonsterPoint(monster.itemIdx, monster.radius, monster.id, monster.num);
|
||||
MapManager.Instance.CreateSpecialPoint(monster.pos.x, monster.pos.y, EditCellType.MonsterArea);
|
||||
}
|
||||
|
||||
public void SetGroup(int group)
|
||||
@@ -118,6 +136,7 @@ public class UIMonsterItem : MonoBehaviour
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.MonsterArea);
|
||||
}
|
||||
|
||||
|
||||
private void OnPathInputFieldClicked(BaseEventData data)
|
||||
{
|
||||
UIWindow.Instance.uiMonstersPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
/*
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
@@ -51,6 +52,50 @@ public class UIMonsterPanel : MonoBehaviour
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
btnAddGroup.onClick.AddListener(OnAddGroup);
|
||||
btnDeleteGroup.onClick.AddListener(OnDeleteGroup);
|
||||
txtMonsterID.onEndEdit.AddListener(OnEditorMonsterId);
|
||||
txtName.onEndEdit.AddListener(OnEditorMonsterName);
|
||||
txtRadius.onEndEdit.AddListener(OnEditorMonsterRadius);
|
||||
txtCount.onEndEdit.AddListener(OnEditorMonsterCount);
|
||||
}
|
||||
|
||||
private void OnEditorMonsterCount(string arg0)
|
||||
{
|
||||
if (!int.TryParse(arg0, out var intValue))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ȷ");
|
||||
return;
|
||||
}
|
||||
_curMonsterItem.monster.id = intValue;
|
||||
_curMonsterItem.RefreshItem();
|
||||
}
|
||||
|
||||
private void OnEditorMonsterRadius(string arg0)
|
||||
{
|
||||
if (!int.TryParse(arg0, out var intValue))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ȷ");
|
||||
return;
|
||||
}
|
||||
_curMonsterItem.monster.radius = intValue;
|
||||
_curMonsterItem.RefreshItem();
|
||||
}
|
||||
|
||||
private void OnEditorMonsterName(string arg0)
|
||||
{
|
||||
if (_curMonsterItem == null) return;
|
||||
_curMonsterItem.RefreshItem();
|
||||
}
|
||||
|
||||
private void OnEditorMonsterId(string arg0)
|
||||
{
|
||||
if (_curMonsterItem == null) return;
|
||||
if (!int.TryParse(arg0, out var intValue))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ȷ");
|
||||
return;
|
||||
}
|
||||
_curMonsterItem.monster.id = intValue;
|
||||
_curMonsterItem.RefreshItem();
|
||||
}
|
||||
|
||||
private void OnClickClose()
|
||||
@@ -159,6 +204,10 @@ public class UIMonsterPanel : MonoBehaviour
|
||||
|
||||
MonstersConfig.MonsterConfig monster = new MonstersConfig.MonsterConfig();
|
||||
monster.itemIdx = ++itemIdx;
|
||||
monster.radius = 1;
|
||||
monster.id = 0;
|
||||
monster.num = 0;
|
||||
monster.pos = MapManager.Instance.map.selector.getMapGrid(Camera.main.transform.position);
|
||||
item.SetItem(monster);
|
||||
item.OnClick = OnClickItem;
|
||||
item.OnCopyItem = OnCopyItem;
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
using HxGame.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIMonstersPanel_old : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public InputField curActiveInput;
|
||||
|
||||
[HideInInspector]
|
||||
public List<string> curActiveList;
|
||||
|
||||
public Transform itemParent;
|
||||
public Button btnAdd;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
btnAdd.onClick.AddListener(AddItem);
|
||||
}
|
||||
|
||||
void AddItem()
|
||||
{
|
||||
UnityEngine.Object obj = Resources.Load("Prefabs/monsterItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("monsterItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIMonsterItem_old item = go.GetComponent<UIMonsterItem_old>();
|
||||
item.itemIdx = itemParent.childCount;
|
||||
}
|
||||
|
||||
public void AddItem(HxGame.Data.MonstersConfig.MonsterConfig monster)
|
||||
{
|
||||
UnityEngine.Object obj = Resources.Load("Prefabs/monsterItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("monsterItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIMonsterItem_old item = go.GetComponent<UIMonsterItem_old>();
|
||||
item.itemIdx = itemParent.childCount;
|
||||
item.txtID.text = monster.id.ToString();
|
||||
item.dropType.value = (int)monster.createMode;
|
||||
item.dropPatrol.value = (int)monster.patrolMode;
|
||||
item.txtPos.text = $"{monster.pos.x},{monster.pos.y}";
|
||||
item.txtRadius.text = monster.radius.ToString();
|
||||
item.txtNum.text = monster.num.ToString();
|
||||
|
||||
if(monster.createMode == CreateMonsterMode.Death)
|
||||
item.txtTime.text = monster.delayTime.ToString();
|
||||
else
|
||||
item.txtTime.text = monster.strTime;
|
||||
item.paths = monster.paths;
|
||||
|
||||
MapManager.Instance.SetMonsterPoint(item.itemIdx,monster.radius, monster.id, monster.num);
|
||||
MapManager.Instance.CreateSpecialPoint(monster.pos.x, monster.pos.y, MapManager.EditCellType.MonsterArea);
|
||||
|
||||
MapManager.Instance.SetCurMonsterPathIdx(item.pathIdx);
|
||||
for (int i = 0; i < item.paths.Count; i++)
|
||||
{
|
||||
string[] pos = item.paths[i].Split('_');
|
||||
int x = Convert.ToInt32(pos[0]);
|
||||
int y = Convert.ToInt32(pos[1]);
|
||||
item.txtPath.text += $"[{item.paths[i].Replace('_', ',')}]";
|
||||
MapManager.Instance.AddMonsterPathSize();
|
||||
MapManager.Instance.CreateSpecialPoint(x, y, MapManager.EditCellType.MonsterPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveMonsterConfig()
|
||||
{
|
||||
//ˢ<><CBA2>
|
||||
int x, y;
|
||||
MonstersConfig mc = new MonstersConfig();
|
||||
|
||||
for (int i = 0; i < itemParent.childCount; i++)
|
||||
{
|
||||
UIMonsterItem_old item = itemParent.GetChild(i).GetComponent<UIMonsterItem_old>();
|
||||
if (!item.CheckValid())
|
||||
return;
|
||||
|
||||
MonstersConfig.MonsterConfig monster = new HxGame.Data.MonstersConfig.MonsterConfig();
|
||||
monster.id = Convert.ToInt32(item.txtID.text);
|
||||
monster.createMode = (CreateMonsterMode)item.dropType.value;
|
||||
monster.patrolMode = (PatrolMode)item.dropPatrol.value;
|
||||
|
||||
string[] tmp = item.txtPos.text.Split(',');
|
||||
if (tmp.Length != 2)
|
||||
return;
|
||||
|
||||
x = Convert.ToInt32(tmp[0]);
|
||||
y = Convert.ToInt32(tmp[1]);
|
||||
monster.pos = new Vector2Int(x, y);
|
||||
monster.radius = Convert.ToInt32(item.txtRadius.text);
|
||||
monster.num = Convert.ToInt32(item.txtNum.text);
|
||||
|
||||
if(monster.createMode == CreateMonsterMode.Death)
|
||||
monster.delayTime = Convert.ToInt32(item.txtTime.text);
|
||||
else
|
||||
monster.strTime = item.txtTime.text;
|
||||
|
||||
monster.paths = item.paths;
|
||||
mc.monsterConfigs.Add(monster);
|
||||
}
|
||||
|
||||
int mapId = MapManager.Instance._curOpenMapId;
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
public void LoadMonsterConfig(int mapId)
|
||||
{
|
||||
MonstersConfig mc = new MonstersConfig();
|
||||
if (!mc.LoadXML(mapId))
|
||||
return;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
for (int i = 0; i < mc.monsterConfigs.Count; i++)
|
||||
{
|
||||
MonstersConfig.MonsterConfig monster = mc.monsterConfigs[i];
|
||||
AddItem(monster);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
int count = itemParent.childCount;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
DestroyImmediate(itemParent.GetChild(0).gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user