第一次提交
This commit is contained in:
246
Assets/Scripts/UI/UICellEditor.cs
Normal file
246
Assets/Scripts/UI/UICellEditor.cs
Normal file
@@ -0,0 +1,246 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// <20>༭<EFBFBD><E0BCAD><EFBFBD><EFBFBD> - <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
|
||||
/// <20><><EFBFBD>ܣ<EFBFBD><DCA3>༭<EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ѱ·<D1B0><C2B7><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>ӷֲ<D3B7><D6B2><EFBFBD>ʾ
|
||||
/// </summary>
|
||||
public class UICellEditor : MonoBehaviour
|
||||
{
|
||||
public Toggle togEdit;
|
||||
public GameObject editPanel;
|
||||
public InputField txtBrushRadius;
|
||||
public Dropdown dropCellType;
|
||||
public Button btnSetBrush;
|
||||
public Button btnSaveCells;
|
||||
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ·
|
||||
public Toggle togPathTest;
|
||||
public GameObject pathTestPanel;
|
||||
public InputField txtStartPos; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public InputField txtEndPos; //<2F>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
[HideInInspector]
|
||||
public InputField curActiveInput;
|
||||
#endregion
|
||||
|
||||
#region ͼ<EFBFBD><EFBFBD><EFBFBD>༭
|
||||
public Toggle togLayer;
|
||||
public GameObject layerPanel;
|
||||
public Toggle[] showgLayers;
|
||||
private int _layers;
|
||||
#endregion
|
||||
|
||||
public Toggle togEffects;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_layers = 0;
|
||||
editPanel.SetActive(false);
|
||||
pathTestPanel.SetActive(false);
|
||||
layerPanel.SetActive(false);
|
||||
AddInputNameClickEvent(txtStartPos);
|
||||
AddInputNameClickEvent(txtEndPos);
|
||||
UIWindow.Instance.HideMouseOver();
|
||||
}
|
||||
|
||||
private void AddInputNameClickEvent(InputField input) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
|
||||
{
|
||||
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
|
||||
UnityAction<BaseEventData> selectEvent = OnInputFieldClicked;
|
||||
EventTrigger.Entry onClick = new EventTrigger.Entry()
|
||||
{
|
||||
eventID = EventTriggerType.PointerClick
|
||||
};
|
||||
|
||||
onClick.callback.AddListener(selectEvent);
|
||||
eventTrigger.triggers.Add(onClick);
|
||||
}
|
||||
|
||||
private void OnInputFieldClicked(BaseEventData data)
|
||||
{
|
||||
if (data.selectedObject.name.Equals("InputStartCell"))
|
||||
{
|
||||
curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
MapManager.Instance.SetCurPathNodePointIdx(-1);
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.PathNodeCell);
|
||||
}
|
||||
else if (data.selectedObject.name.Equals("InputEndCell"))
|
||||
{
|
||||
curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
MapManager.Instance.SetCurPathNodePointIdx(-100);
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.PathNodeCell);
|
||||
}
|
||||
}
|
||||
|
||||
public void FindPath()
|
||||
{
|
||||
if(string.IsNullOrEmpty(txtStartPos.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] tmp = txtStartPos.text.Split(',');
|
||||
if(tmp.Length != 2)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
if(!APIs.IsUInt(tmp[0]))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
if (!APIs.IsUInt(tmp[1]))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2Int startPos = new Vector2Int(Convert.ToInt32(tmp[0]), Convert.ToInt32(tmp[1]));
|
||||
|
||||
if (string.IsNullOrEmpty(txtEndPos.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
tmp = txtEndPos.text.Split(',');
|
||||
if (tmp.Length != 2)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
if (!APIs.IsUInt(tmp[0]))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
if (!APIs.IsUInt(tmp[1]))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2Int endPos = new Vector2Int(Convert.ToInt32(tmp[0]), Convert.ToInt32(tmp[1]));
|
||||
|
||||
MapManager.Instance.FindPath(startPos, endPos);
|
||||
}
|
||||
|
||||
//<2F>༭<EFBFBD><E0BCAD><EFBFBD><EFBFBD>
|
||||
public void OnEditToggleChange()
|
||||
{
|
||||
if (togEdit.isOn)
|
||||
{
|
||||
if (!UIWindow.Instance.uiCellInfo.bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
editPanel.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
editPanel.SetActive(false);
|
||||
MapManager.Instance.CloseEditor();
|
||||
}
|
||||
}
|
||||
|
||||
//Ѱ·<D1B0><C2B7><EFBFBD><EFBFBD>
|
||||
public void OnPathTestToggleChange()
|
||||
{
|
||||
if (togPathTest.isOn)
|
||||
{
|
||||
if (!UIWindow.Instance.uiCellInfo.bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
pathTestPanel.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
pathTestPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
//ͼ<><CDBC><EFBFBD>༭
|
||||
public void OnLayerToggleChange()
|
||||
{
|
||||
if (togLayer.isOn)
|
||||
{
|
||||
if (!UIWindow.Instance.uiCellInfo.bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
layerPanel.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
layerPanel.SetActive(false);
|
||||
MapManager.Instance.ShowCells();
|
||||
}
|
||||
}
|
||||
|
||||
//ͼ<><CDBC><EFBFBD>༭
|
||||
public void OnShowLayerToggleChange()
|
||||
{
|
||||
MapManager.CellLayer[] layers = (MapManager.CellLayer[])Enum.GetValues(typeof(MapManager.CellLayer));
|
||||
_layers = 0;
|
||||
for (int i= showgLayers.Length - 1; i>=0; i--)
|
||||
{
|
||||
if (showgLayers[i].isOn)
|
||||
_layers |= (int)layers[i];
|
||||
}
|
||||
|
||||
MapManager.Instance.ShowCells();
|
||||
MapManager.Instance.HideCellsExcludeLayers(_layers);
|
||||
}
|
||||
|
||||
//<2F>༭<EFBFBD><E0BCAD>Ч
|
||||
public void OnShowEffectsToggleChange()
|
||||
{
|
||||
UIWindow.Instance.uiCreateMap.MapBG.GetComponent<CanvasGroup>().blocksRaycasts = true;
|
||||
MapManager.Instance.HideCells();
|
||||
UIWindow.Instance.ShowMouseOver();
|
||||
}
|
||||
|
||||
public void SetBrush()
|
||||
{
|
||||
if (!UIWindow.Instance.uiCellInfo.bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
float brushRadius = Convert.ToSingle(txtBrushRadius.text);
|
||||
MapManager.CellType type = (MapManager.CellType)(1 << dropCellType.value);
|
||||
MapManager.Instance.SetBrush(brushRadius, type);
|
||||
MapManager.Instance.StartEditor();
|
||||
}
|
||||
|
||||
public void CleanSafe()
|
||||
{
|
||||
MapManager.Instance.CleanSafe();
|
||||
}
|
||||
|
||||
public void SaveCells()
|
||||
{
|
||||
if (!UIWindow.Instance.uiCellInfo.bMapOpened)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
||||
return;
|
||||
}
|
||||
|
||||
MapManager.Instance.SaveCellsXml();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user