85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Timers;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class IoTestPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] List<AudioClip> wowSounds;
|
|
float timer = 0;
|
|
|
|
[SerializeField] RectTransform pipeline;
|
|
[SerializeField] List<ButtonTester> buttonTesters;
|
|
int currentTesterIndex = 0;
|
|
|
|
float exitTime = 3f;
|
|
[SerializeField] Image ExitImage;
|
|
|
|
private Vector2 velocity = Vector2.zero;
|
|
private void OnEnable()
|
|
{
|
|
foreach (var tester in buttonTesters) { tester.active = false; }
|
|
|
|
pipeline.anchoredPosition = Vector2.zero;
|
|
currentTesterIndex = 0;
|
|
buttonTesters[currentTesterIndex].active = true;
|
|
}
|
|
void Update()
|
|
{
|
|
ExitProcessing();
|
|
|
|
ButtonPinMapping buttonToPress = buttonTesters[currentTesterIndex].button;
|
|
if (In.GetButton(buttonToPress))
|
|
{
|
|
buttonTesters[currentTesterIndex].EmulatePress();
|
|
SoundManager.instance.playClip(wowSounds[Random.Range(0, wowSounds.Count)]);
|
|
buttonTesters[currentTesterIndex].active = false;
|
|
|
|
currentTesterIndex = (currentTesterIndex + 1 + buttonTesters.Count) % buttonTesters.Count;
|
|
buttonTesters[currentTesterIndex].active = true;
|
|
}
|
|
|
|
Vector2 target = new Vector2(200 * currentTesterIndex, 0);
|
|
pipeline.anchoredPosition = Vector2.SmoothDamp(
|
|
pipeline.anchoredPosition,
|
|
target,
|
|
ref velocity,
|
|
0.3f
|
|
);
|
|
}
|
|
|
|
private void ExitProcessing()
|
|
{
|
|
bool pressedExit = In.GetButton(ButtonPinMapping.startOnePlayer) && In.GetButton(ButtonPinMapping.startTwoPlayers);
|
|
timer += pressedExit ? Time.deltaTime : -3 * Time.deltaTime;
|
|
timer = Mathf.Clamp(timer, 0, exitTime);
|
|
|
|
float fillAmount = timer / exitTime;
|
|
ExitImage.fillAmount = fillAmount;
|
|
|
|
|
|
|
|
if (timer >= 3)
|
|
{
|
|
GameManager.instance.stateMachine.ChangeState(new SettingsState());
|
|
}
|
|
}
|
|
|
|
IEnumerator UpdatePosition()
|
|
{
|
|
Vector2 velocity = Vector2.zero;
|
|
|
|
while (true)
|
|
{
|
|
yield return null;
|
|
pipeline.anchoredPosition = Vector2.SmoothDamp(current: pipeline.anchoredPosition,
|
|
target: new Vector2(-200 * currentTesterIndex, 0),
|
|
currentVelocity: ref velocity,
|
|
smoothTime: 0.5f);
|
|
}
|
|
|
|
}
|
|
|
|
}
|