@@ -20,6 +20,8 @@ namespace Ichni.Editor
|
||||
public GameObject hoveredUI;
|
||||
public EventSystem eventSystem;
|
||||
public List<GraphicRaycaster> graphicRaycasters;
|
||||
private List<SelectionConnector> lastHitConnectors = new List<SelectionConnector>();
|
||||
private int currentSelectIndex = 0;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -260,15 +262,31 @@ namespace Ichni.Editor
|
||||
|
||||
private void ClickSelectElement()
|
||||
{
|
||||
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame && !isPointerOverUI)
|
||||
{
|
||||
Vector2 mousePosition = Mouse.current.position.ReadValue();
|
||||
Ray ray = EditorManager.instance.cameraManager.currentCamera.ScreenPointToRay(mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, float.MaxValue, LayerMask.GetMask("Selectable")))
|
||||
RaycastHit[] hits = Physics.RaycastAll(ray, 500f, LayerMask.GetMask("Selectable"));
|
||||
|
||||
var hitConnectors = hits
|
||||
.Select(hit => hit.collider.GetComponent<SelectionConnector>())
|
||||
.Where(connector => connector != null)
|
||||
.ToList();
|
||||
|
||||
if (hitConnectors.Count == 0) return;
|
||||
|
||||
// 如果点击对象列表变化,重置索引
|
||||
if (!Enumerable.SequenceEqual(hitConnectors, lastHitConnectors))
|
||||
{
|
||||
SelectionConnector connector = hit.collider.GetComponent<SelectionConnector>();//TODO: 对于Hold这种复杂的元素,需要使用连接脚本进行获取
|
||||
(connector.connectedGameElement as IHaveSelectSubmodule)?.selectSubmodule.SelectGameElement();
|
||||
lastHitConnectors = hitConnectors;
|
||||
currentSelectIndex = 0;
|
||||
}
|
||||
|
||||
var connector = lastHitConnectors[currentSelectIndex];
|
||||
(connector.connectedGameElement as IHaveSelectSubmodule)?.selectSubmodule.SelectGameElement();
|
||||
|
||||
currentSelectIndex = (currentSelectIndex + 1) % lastHitConnectors.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user