175 lines
4.5 KiB
C#
175 lines
4.5 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
|
|
public class HighscoreLetterManager : BaseInputBehavior
|
|
{
|
|
private List<string> Alphanumerics = new List<string>
|
|
{
|
|
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
|
|
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
|
|
"U", "V", "W", "X", "Y", "Z", " " //"0", "1", "2", "3",
|
|
//"4", "5", "6", "7", "8", "9", " "
|
|
};
|
|
public bool IsActive
|
|
{
|
|
get
|
|
{
|
|
return _isActive;
|
|
}
|
|
set
|
|
{
|
|
if (value == _isActive) return;
|
|
_isActive = value;
|
|
UpdateButtons();
|
|
//var image = Selector.GetComponent<Image>();
|
|
//var test = Selector.GetComponentInChildren<Image>();
|
|
}
|
|
}
|
|
|
|
public bool disabled;
|
|
|
|
private int currentIndex;
|
|
|
|
public Button UpButton;
|
|
//public Sprite UpButtonSprite;
|
|
//public Sprite PressedUpButtonSprite;
|
|
|
|
public Button DownButton;
|
|
//public Sprite DownButtonSprite;
|
|
//public Sprite PressedDownButtonSprite;
|
|
|
|
public Text LetterText;
|
|
|
|
//public GameObject Selector;
|
|
//public Color ColorSelection;
|
|
|
|
//public string XAxis;
|
|
public string YAxis { get { return !Player2 ? GameManager.Instance.YAxisP1 : GameManager.Instance.YAxisP2; } }
|
|
|
|
private Image upButtonImage;
|
|
private Image downButtonImage;
|
|
private bool letterIsChanging;
|
|
//private DateTime lastInput;
|
|
//public int InputDelay = 500;
|
|
private bool _isActive;
|
|
|
|
|
|
//bool IsSpawned
|
|
//{
|
|
// get { return lastInput == null || (DateTime.Now - lastInput).Milliseconds < InputDelay; }
|
|
//}
|
|
|
|
public string CurrentText
|
|
{ get { return Alphanumerics[CurrentIndex]; } }
|
|
|
|
private int CurrentIndex
|
|
{
|
|
get
|
|
{
|
|
return currentIndex;
|
|
}
|
|
|
|
set
|
|
{
|
|
currentIndex = value;
|
|
}
|
|
}
|
|
|
|
public bool Player2;
|
|
|
|
// Use this for initialization
|
|
void Start()
|
|
{
|
|
CurrentIndex = 0;
|
|
if (Alphanumerics.Contains(LetterText.text))
|
|
CurrentIndex = Alphanumerics.IndexOf(LetterText.text);
|
|
upButtonImage = UpButton.GetComponentInChildren<Image>();
|
|
downButtonImage = DownButton.GetComponentInChildren<Image>();
|
|
UpdateButtons();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (!IsActive || disabled) return;
|
|
|
|
UpdateLetter();
|
|
if (!IsSpawned)
|
|
{
|
|
if (!string.IsNullOrEmpty(YAxis))
|
|
{
|
|
var verticalAxis = Input.GetAxis(YAxis);
|
|
if (Math.Abs(verticalAxis) == 1)
|
|
ChangeLetter(verticalAxis == 1);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateLetter()
|
|
{
|
|
if (letterIsChanging) return;
|
|
if (LetterText.text != CurrentText)
|
|
{
|
|
LetterText.text = CurrentText;
|
|
}
|
|
////////////////UpdateButtons();
|
|
}
|
|
|
|
private void UpdateButtons()
|
|
{
|
|
//var upSprite = UpButtonSprite;
|
|
//var downSprite = DownButtonSprite;
|
|
//if (upButtonPressed && (DateTime.Now - lastInput).Milliseconds < 200)
|
|
//{
|
|
// upSprite = PressedUpButtonSprite;
|
|
//}
|
|
//else upButtonPressed = false;
|
|
//if (downButtonPressed && (DateTime.Now - lastInput).Milliseconds < 200)
|
|
//{
|
|
// downSprite = PressedDownButtonSprite;
|
|
//}
|
|
//else downButtonPressed = false;
|
|
//upButtonImage.sprite = upSprite;
|
|
//downButtonImage.sprite = downSprite;
|
|
Debug.Log(transform.gameObject.name + " is " + (_isActive ? "active" : "inactive"));
|
|
if(upButtonImage!=null)upButtonImage.gameObject.SetActive(_isActive);
|
|
if(upButtonImage!=null)downButtonImage.gameObject.SetActive(_isActive);
|
|
}
|
|
|
|
public void ChangeLetter(bool plus)
|
|
{
|
|
if (letterIsChanging) return;
|
|
lastInput = DateTime.Now;
|
|
letterIsChanging = true;
|
|
if (plus)
|
|
{
|
|
CurrentIndex++;
|
|
}
|
|
else
|
|
{
|
|
CurrentIndex--;
|
|
}
|
|
if (CurrentIndex < 0) CurrentIndex = Alphanumerics.Count - 1;
|
|
else if (CurrentIndex >= Alphanumerics.Count) CurrentIndex = 0;
|
|
letterIsChanging = false;
|
|
}
|
|
|
|
private static bool? IsPositiveMove(float axis)
|
|
{
|
|
bool? move = null;
|
|
if (axis == 1) move = true;
|
|
else if (axis == -1) move = false;
|
|
return move;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
CurrentIndex = 0;
|
|
}
|
|
}
|