Retire le UI du UnitTree quand on clique sur n'importe quoi d'autre Co-authored-by: Ader Alisma 01 <adeder22@hotmail.com> Reviewed-on: #9 Reviewed-by: EliaGingras1 <william-gin1@hotmail.com>
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class DeselectManager : SingletonBehaviour<DeselectManager>
|
|
{
|
|
private GameObject _allyUpgrade;
|
|
[SerializeField]
|
|
private Canvas _canvas;
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButton(0) && _allyUpgrade != null)
|
|
{
|
|
// Vérifie si click est sur un enfant d'AllyUpgrade
|
|
PointerEventData pointerData = new PointerEventData(EventSystem.current)
|
|
{
|
|
position = Input.mousePosition
|
|
};
|
|
List<RaycastResult> results = new List<RaycastResult>();
|
|
GraphicRaycaster raycaster = _canvas.GetComponent<GraphicRaycaster>();
|
|
raycaster.Raycast(pointerData, results);
|
|
foreach (RaycastResult result in results)
|
|
{
|
|
if (result.gameObject.transform.IsChildOf(_allyUpgrade.transform))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
SetAllyUpgrade(null);
|
|
}
|
|
}
|
|
|
|
public void SetAllyUpgrade(GameObject allyUpgradeInstance)
|
|
{
|
|
if (_allyUpgrade == null)
|
|
{
|
|
_allyUpgrade = allyUpgradeInstance;
|
|
|
|
}
|
|
else if (_allyUpgrade != allyUpgradeInstance)
|
|
{
|
|
Destroy(_allyUpgrade);
|
|
_allyUpgrade = allyUpgradeInstance;
|
|
}
|
|
}
|
|
}
|