130 lines
4.5 KiB
C#
130 lines
4.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace PrizeSystem
|
|
{
|
|
public class TakeOrRiskPanel : MonoBehaviour
|
|
{
|
|
[Header("Ссылки на панели")]
|
|
[SerializeField] private Image CurrentPrizeFrame;
|
|
[SerializeField] private Image NextPrizeFrame;
|
|
[SerializeField] private PrizeView CurrentPrizeView;
|
|
[SerializeField] private PrizeView NextPrizeView;
|
|
|
|
[Header("Цветовая анимация")]
|
|
[SerializeField] private Color DisabledColor;
|
|
[SerializeField] float HsvSpeed = 0.3f;
|
|
|
|
[Header("Анимация размера панелей")]
|
|
[SerializeField] private float ScalingSpeed = 1;
|
|
[SerializeField] private float SelectedScale = 1.05f;
|
|
[SerializeField] private float IdleScale = 0.95f;
|
|
|
|
[SerializeField] private AudioClip StartAcceptingClip;
|
|
|
|
private TakeOrRiskOption SelectedOption;
|
|
public event Action<TakeOrRiskOption> OnComplete;
|
|
|
|
private Image activeFrame;
|
|
private Image inactiveFrame;
|
|
private float acceptTimer = 0;
|
|
|
|
private void OnEnable()
|
|
{
|
|
SelectedOption = TakeOrRiskOption.Take;
|
|
|
|
activeFrame = CurrentPrizeFrame;
|
|
inactiveFrame = NextPrizeFrame;
|
|
|
|
acceptTimer = 0;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
ClearPrizes();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
//var inputs = ProcessInput();
|
|
//UpdateState(inputs.selectedOption, inputs.timerDelta);
|
|
|
|
if(In.GetButtonDown(ButtonPinMapping.startOnePlayer))
|
|
{
|
|
SelectedOption = TakeOrRiskOption.Take;
|
|
Accept();
|
|
}
|
|
if (In.GetButtonDown(ButtonPinMapping.startTwoPlayers))
|
|
{
|
|
SelectedOption = TakeOrRiskOption.Risk;
|
|
Accept();
|
|
}
|
|
DisplayGraphics();
|
|
}
|
|
|
|
public void SetPrizes(Prize CurrentPrize, Prize NextPrize)
|
|
{
|
|
CurrentPrizeView.SetPrize(CurrentPrize);
|
|
NextPrizeView.SetPrize(NextPrize);
|
|
}
|
|
|
|
private void ClearPrizes()
|
|
{
|
|
CurrentPrizeView.Clear();
|
|
NextPrizeView.Clear();
|
|
}
|
|
|
|
//private (TakeOrRiskOption selectedOption, float timerDelta) ProcessInput()
|
|
//{
|
|
// //if (In.GetButtonAnyPlayer(PlayerAction.left) && SelectedOption != TakeOrRiskOption.Take)
|
|
// //{
|
|
// // //SoundManager.instance.playSwitch();
|
|
// // //SelectedOption = TakeOrRiskOption.Take;
|
|
// //}
|
|
// //if (In.GetButtonAnyPlayer(PlayerAction.right) && SelectedOption != TakeOrRiskOption.Risk)
|
|
// //{
|
|
// // //SoundManager.instance.playSwitch();
|
|
// // //SelectedOption = TakeOrRiskOption.Risk;
|
|
// //}
|
|
|
|
// //if(In.GetButtonDownAnyPlayer(PlayerAction.down)) SoundManager.instance.playClip(StartAcceptingClip);
|
|
// //float timerDelta = Time.deltaTime * (In.GetButtonAnyPlayer(PlayerAction.down) ? 1 : -1);
|
|
|
|
// //return (SelectedOption, timerDelta);
|
|
//}
|
|
|
|
//private void UpdateState(TakeOrRiskOption selectedOption, float timerDelta)
|
|
//{
|
|
// activeFrame = selectedOption == TakeOrRiskOption.Take ? CurrentPrizeFrame : NextPrizeFrame;
|
|
// inactiveFrame = selectedOption == TakeOrRiskOption.Take ? NextPrizeFrame : CurrentPrizeFrame;
|
|
|
|
// acceptTimer = Mathf.Clamp(acceptTimer + timerDelta, 0, TimeToAccept);
|
|
// if (acceptTimer >= TimeToAccept) Accept();
|
|
//}
|
|
|
|
private void DisplayGraphics()
|
|
{
|
|
// Скалирование
|
|
//activeFrame.transform.localScale = Vector3.MoveTowards(activeFrame.transform.localScale, Vector3.one * SelectedScale, Time.deltaTime * ScalingSpeed);
|
|
//inactiveFrame.transform.localScale = Vector3.MoveTowards(inactiveFrame.transform.localScale, Vector3.one * IdleScale, Time.deltaTime * ScalingSpeed);
|
|
|
|
//Цвет рамки
|
|
float hue = (Time.time * HsvSpeed) % 1f;
|
|
Color animatedColor = Color.HSVToRGB(hue, 1, 1);
|
|
activeFrame.color = animatedColor;
|
|
inactiveFrame.color = animatedColor;
|
|
|
|
//Круговой таймер
|
|
//float timerPercent = acceptTimer / TimeToAccept;
|
|
//TimerRing.fillAmount = TimerFillCurve.Evaluate(timerPercent);
|
|
}
|
|
|
|
private void Accept()
|
|
{
|
|
OnComplete?.Invoke(SelectedOption);
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|