squash! Fin Tooltip
This commit is contained in:
parent
56b5dd3361
commit
f1a53cd9cf
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 20
|
||||
_cooldownInSeconds: 5
|
||||
_tooltipString:
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 350
|
||||
_food: 0
|
||||
_cooldownInSeconds: 30
|
||||
_tooltipString:
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 0
|
||||
_cooldownInSeconds: 1
|
||||
_tooltipString:
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 10
|
||||
_cooldownInSeconds: 2
|
||||
_tooltipString:
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 10
|
||||
_cooldownInSeconds: 4
|
||||
_tooltipString: Agressive farmer's association MOB
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 0
|
||||
_cooldownInSeconds: 1
|
||||
_tooltipString:
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 60
|
||||
_cooldownInSeconds: 15
|
||||
_tooltipString:
|
||||
|
||||
@ -16,3 +16,4 @@ MonoBehaviour:
|
||||
_rock: 0
|
||||
_food: 0
|
||||
_cooldownInSeconds: 60
|
||||
_tooltipString:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts/Ally/Tooltip.meta
Normal file
8
Assets/Scripts/Ally/Tooltip.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54b66411b2ca31042865510b55cf4608
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Ally/Tooltip/TooltipManager.cs
Normal file
32
Assets/Scripts/Ally/Tooltip/TooltipManager.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using GatherAndDefend.Events;
|
||||
using System;
|
||||
|
||||
public class TooltipManager : Singleton<TooltipManager>
|
||||
{
|
||||
private string _description;
|
||||
public string Description { get { return _description; } }
|
||||
private string _hp;
|
||||
public string Hp { get { return _hp; } }
|
||||
private string _damage;
|
||||
public string Damage { get { return _damage; } }
|
||||
private string _attackSpeed;
|
||||
public string AttackSpeed { get { return _attackSpeed; } }
|
||||
private bool _tooltipVisibility;
|
||||
public bool TooltipVisibility { get { return _tooltipVisibility; } }
|
||||
|
||||
public void ShowTooltip(string description, string hp, string dmg, string atkSpeed)
|
||||
{
|
||||
_tooltipVisibility = true;
|
||||
_description = description;
|
||||
_hp = hp;
|
||||
_damage = dmg;
|
||||
_attackSpeed = atkSpeed;
|
||||
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Invoke();
|
||||
}
|
||||
|
||||
internal void HideToolTip()
|
||||
{
|
||||
_tooltipVisibility = false;
|
||||
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Invoke();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Ally/Tooltip/TooltipManager.cs.meta
Normal file
11
Assets/Scripts/Ally/Tooltip/TooltipManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c319ef77aa02448488fc0f25f670426b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Scripts/Ally/Tooltip/TooltipText.cs
Normal file
46
Assets/Scripts/Ally/Tooltip/TooltipText.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using GatherAndDefend.Events;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class TooltipText : MonoBehaviour
|
||||
{
|
||||
private TooltipManager _tooltipManager;
|
||||
[SerializeField]
|
||||
private GameObject _tooltipPanel;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _tooltipDescription;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _tooltipHp;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _tooltipDmg;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _tooltipAttackSpeed;
|
||||
private const string EMPTY_STRING = "";
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_tooltipManager = TooltipManager.Instance;
|
||||
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Attach(OnEventUpdate);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void OnEventUpdate()
|
||||
{
|
||||
if (_tooltipManager.TooltipVisibility)
|
||||
{
|
||||
_tooltipPanel.SetActive(true);
|
||||
_tooltipDescription.text = _tooltipManager.Description;
|
||||
_tooltipHp.text = "Points de vie: " + (_tooltipManager.Hp.Equals("0") ? "1" : _tooltipManager.Hp);
|
||||
_tooltipDmg.text = "Dommage: " + _tooltipManager.Damage;
|
||||
_tooltipAttackSpeed.text = "Vitesse d'attaque: " + _tooltipManager.AttackSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tooltipPanel.SetActive(false);
|
||||
_tooltipDescription.text = EMPTY_STRING;
|
||||
_tooltipHp.text = EMPTY_STRING;
|
||||
_tooltipDmg.text = EMPTY_STRING;
|
||||
_tooltipAttackSpeed.text = EMPTY_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Ally/Tooltip/TooltipText.cs.meta
Normal file
11
Assets/Scripts/Ally/Tooltip/TooltipText.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c61083f9f8ea6441afcccd38ee6428e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -2,11 +2,18 @@
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class GameObjectPlacementButton : UnitPlacementButton
|
||||
public class GameObjectPlacementButton : UnitPlacementButton, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
private TooltipManager _tooltipManager;
|
||||
[SerializeField]
|
||||
private GameObject _prefab;
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
_tooltipManager = TooltipManager.Instance;
|
||||
}
|
||||
|
||||
protected override bool CanPlace()
|
||||
{
|
||||
@ -81,4 +88,22 @@ public class GameObjectPlacementButton : UnitPlacementButton
|
||||
detection.transform.localPosition = detectionRect.position;
|
||||
detection.transform.localScale = detectionRect.size;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
Ally go = _prefab.GetComponent<Ally>();
|
||||
if (_unitCardInformation.TooltipString.Length > 0)
|
||||
{
|
||||
_tooltipManager.ShowTooltip(_unitCardInformation.TooltipString, go.Hp.ToString(), go.AttackDamage.ToString(), go.AttackInterval.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
_tooltipManager.ShowTooltip("Exemple de description d'unité pour " + _unitCardInformation.name.ToLower(), go.Hp.ToString(), go.AttackDamage.ToString(), go.AttackInterval.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
_tooltipManager.HideToolTip();
|
||||
}
|
||||
}
|
||||
@ -11,9 +11,12 @@ public class UnitCard : ScriptableObject
|
||||
protected int _food;
|
||||
[SerializeField]
|
||||
protected int _cooldownInSeconds = 3;
|
||||
[SerializeField, TextArea(10, 100)]
|
||||
protected string _tooltipString;
|
||||
|
||||
public int Wood => _wood;
|
||||
public int Rock => _rock;
|
||||
public int Food => _food;
|
||||
public int CooldownInSeconds => _cooldownInSeconds;
|
||||
public string TooltipString => _tooltipString;
|
||||
}
|
||||
@ -24,6 +24,11 @@ public abstract class UnitPlacementButton : PlacementButton
|
||||
protected Image _cooldownIndicator;
|
||||
protected bool _lockedByCooldown;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@ -77,4 +82,7 @@ public abstract class UnitPlacementButton : PlacementButton
|
||||
{
|
||||
return base.CanPlace() && !_lockedByCooldown;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
5
Assets/Scripts/Events/TooltipChangedEvent.cs
Normal file
5
Assets/Scripts/Events/TooltipChangedEvent.cs
Normal file
@ -0,0 +1,5 @@
|
||||
using GatherAndDefend.Events;
|
||||
|
||||
public class TooltipChangedEvent : EventBase
|
||||
{
|
||||
}
|
||||
11
Assets/Scripts/Events/TooltipChangedEvent.cs.meta
Normal file
11
Assets/Scripts/Events/TooltipChangedEvent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 927ca3622899c4848838a81957e849eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user