Compare commits
No commits in common. "f571fbf5807ebcaecc741b34a6c933449edc03c9" and "3a4ec88cbcb45e529ac8f72d490e24f7c34e0f15" have entirely different histories.
f571fbf580
...
3a4ec88cbc
@ -4675,7 +4675,6 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 4c63e60a445cf4549999d898b25ab0ea, type: 3}
|
m_Script: {fileID: 11500000, guid: 4c63e60a445cf4549999d898b25ab0ea, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_canvas: {fileID: 1092900231}
|
|
||||||
--- !u!1 &1761692192
|
--- !u!1 &1761692192
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
71
Assets/Scripts/Ally/AllyUpgrade.cs
Normal file
71
Assets/Scripts/Ally/AllyUpgrade.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class AllyUpgrade : MonoBehaviour, IPointerClickHandler
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
private GameObject _upgradeUI;
|
||||||
|
[SerializeField]
|
||||||
|
private List<UnitUpgrade> _upgradeList = new List<UnitUpgrade>();
|
||||||
|
private GameObject _instance = null;
|
||||||
|
|
||||||
|
public void OnPointerClick(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (eventData.button == 0) //Left click
|
||||||
|
{
|
||||||
|
if (!_instance)
|
||||||
|
{
|
||||||
|
GameObject sceneCanvas = GameObject.Find("Canvas");
|
||||||
|
if (sceneCanvas != null)
|
||||||
|
{
|
||||||
|
Canvas canvas = sceneCanvas.GetComponent<Canvas>();
|
||||||
|
if (canvas == null)
|
||||||
|
{
|
||||||
|
Debug.Log("Canvas introuvable...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_instance = Instantiate(_upgradeUI, Camera.main.WorldToScreenPoint(transform.position), Quaternion.identity, canvas.transform);
|
||||||
|
AssignUpgrades(canvas);
|
||||||
|
DeselectManager.Instance.SetAllyUpgrade(_instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Destroy(_instance);
|
||||||
|
_instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssignUpgrades(Canvas canvas)
|
||||||
|
{
|
||||||
|
// Assign upgrade Prefabs
|
||||||
|
for (int i = 0; i < _instance.transform.childCount - 1; i++)
|
||||||
|
{
|
||||||
|
if (_upgradeList.Count > i && _upgradeList[i] != null)
|
||||||
|
{
|
||||||
|
GameObject upgradeEnfant = _instance.transform.Find("Upgrade" + (i + 1)).gameObject;
|
||||||
|
if (upgradeEnfant.TryGetComponent<UpgradePlacementButton>(out UpgradePlacementButton button))
|
||||||
|
{
|
||||||
|
button.Initialize(_upgradeList[i], gameObject, canvas);
|
||||||
|
//button.GetComponent<Selectable>().Select();
|
||||||
|
//button.gameObject.AddComponent<DeselectedAction>().Init(_instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (_instance != null)
|
||||||
|
{
|
||||||
|
Debug.Log("Destroying upgrade UI");
|
||||||
|
Destroy(_instance);
|
||||||
|
_instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/Ally/AllyUpgrade.cs.meta
Normal file
11
Assets/Scripts/Ally/AllyUpgrade.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: edcd1782caa73a747b1f060d18ce0f18
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -1,49 +1,47 @@
|
|||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
public class DeselectManager : SingletonBehaviour<DeselectManager>
|
public class DeselectManager : SingletonBehaviour<DeselectManager>
|
||||||
{
|
{
|
||||||
private GameObject _allyUpgrade;
|
private GameObject _allyUpgrade;
|
||||||
[SerializeField]
|
|
||||||
private Canvas _canvas;
|
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetMouseButton(0) && _allyUpgrade != null)
|
if (Input.GetMouseButton(0))
|
||||||
{
|
{
|
||||||
// Vérifie si click est sur un enfant d'AllyUpgrade
|
// Verifie var si click est sur un enfant d'AllyUpgrade
|
||||||
PointerEventData pointerData = new PointerEventData(EventSystem.current)
|
|
||||||
{
|
GameObject selectedObject = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
|
||||||
position = Input.mousePosition
|
if (selectedObject != null && _allyUpgrade != null && selectedObject.transform.IsChildOf(_allyUpgrade.transform))
|
||||||
};
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("Called to deselect from Observer");
|
||||||
|
if (_allyUpgrade != null)
|
||||||
|
{
|
||||||
Destroy(_allyUpgrade);
|
Destroy(_allyUpgrade);
|
||||||
_allyUpgrade = null;
|
_allyUpgrade = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetAllyUpgrade(GameObject allyUpgradeInstance)
|
public void SetAllyUpgrade(GameObject allyUpgradeInstance)
|
||||||
{
|
{
|
||||||
if (_allyUpgrade == null)
|
if (_allyUpgrade == null)
|
||||||
{
|
{
|
||||||
_allyUpgrade = allyUpgradeInstance;
|
_allyUpgrade = allyUpgradeInstance;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (_allyUpgrade != allyUpgradeInstance)
|
else if (_allyUpgrade != allyUpgradeInstance)
|
||||||
{
|
{
|
||||||
Destroy(_allyUpgrade);
|
Destroy(_allyUpgrade);
|
||||||
_allyUpgrade = allyUpgradeInstance;
|
_allyUpgrade = allyUpgradeInstance;
|
||||||
}
|
}
|
||||||
|
Debug.Log("AllyUpgrade set: " + _allyUpgrade?.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user