59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class MonumentController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private float _energyToUnlock;
|
|
[SerializeField]
|
|
private MonumentInfo _info;
|
|
|
|
private EnergyController _energyController;
|
|
private float _currentEnergy;
|
|
private ScoreController _scoreController;
|
|
private CockpitUIModule _cockpitUI;
|
|
private MonumentPreviewSound _previewSound;
|
|
|
|
public UnityEvent OnUnlock;
|
|
|
|
private void Awake()
|
|
{
|
|
_previewSound = FindObjectOfType<MonumentPreviewSound>();
|
|
_scoreController = FindObjectOfType<ScoreController>();
|
|
_cockpitUI = FindObjectOfType<CockpitUIModule>();
|
|
_energyController = FindObjectOfType<EnergyController>();
|
|
_currentEnergy = _energyToUnlock;
|
|
}
|
|
|
|
[ContextMenu("Debug Unlock")]
|
|
public void UnlockMonument()
|
|
{
|
|
OnUnlock?.Invoke();
|
|
var totalEnergy = _energyController.Energy;
|
|
|
|
LeanTween.value(totalEnergy, 0, 1).setEase(LeanTweenType.easeInOutSine).setOnUpdate((float x)=>
|
|
{
|
|
_energyController.Energy = x;
|
|
_currentEnergy = Mathf.Clamp(_energyToUnlock - (totalEnergy - x), 0, int.MaxValue);
|
|
Debug.Log($"Clamped energy value: {_currentEnergy / _energyToUnlock}");
|
|
});
|
|
|
|
|
|
_scoreController.AddScoreInTime(_info.Score, 1, false);
|
|
//TODO: ÐÀÇÁËÎÊÈÐÎÂÀÒÜ ÌÎÍÓÌÅÍÒ ÒÎËÜÊÎ ÅÑËÈ ÕÂÀÒÈËÎ ÝÍÅÐÃÈÈ
|
|
PlayerSetup.Instance.UnlockMonument(_info);
|
|
}
|
|
|
|
public void PlaySound()
|
|
{
|
|
_previewSound.PlaySound(_info.LongClip);
|
|
}
|
|
|
|
public void ShowPreview()
|
|
{
|
|
_cockpitUI.ShowInfo(_info.Image, _info.Description);
|
|
}
|
|
}
|