TouhouLS/Assets/RealCode/Menu/Rematch.cs

77 lines
1.9 KiB
C#
Raw Permalink Normal View History

2020-08-22 07:34:54 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
2020-08-22 07:34:54 +00:00
using TMPro;
public class Rematch : MonoBehaviour {
public static Rematch Instance { get; private set; }
public GameObject[] spButtons;
public GameObject[] mpButtons;
2020-08-22 07:34:54 +00:00
public TextMeshProUGUI continueTextMesh;
public string continueKey, waitKey;
public Image continueBar;
public float continueDuration = 10f;
private float continueTime;
private void Awake() {
Instance = this;
}
private void Update() {
if (GameTransition.Instance.state == GameState.Continue){
var delta = Mathf.Clamp01(1f - (Time.time - continueTime) / continueDuration);
continueBar.fillAmount = delta;
if (delta <= 0f && PlayerProperties.playerResponse.GetLocal() == -1){
PlayerProperties.playerResponse.SetLocal(0);
2020-08-22 07:34:54 +00:00
}
}
}
public void Setup(){
if (NetworkManager.inRoom){
foreach(var b in mpButtons){
b.SetActive(true);
}
foreach(var b in spButtons){
b.SetActive(false);
}
EventSystem.current.SetSelectedGameObject(mpButtons[0].transform.GetChild(0).gameObject);
} else {
foreach(var b in mpButtons){
b.SetActive(false);
}
foreach(var b in spButtons){
b.SetActive(true);
}
EventSystem.current.SetSelectedGameObject(spButtons[0].transform.GetChild(0).gameObject);
2020-08-22 07:34:54 +00:00
}
continueTextMesh.text = Localization.GetString(continueKey);
continueBar.fillAmount = 1f;
continueTime = Time.time;
}
public void SelectOption(int i){
EventSystem.current.SetSelectedGameObject(null);
2020-08-22 07:34:54 +00:00
PlayerProperties.playerResponse.SetLocal(i);
foreach(var b in mpButtons){
b.SetActive(false);
}
foreach(var b in spButtons){
2020-08-22 07:34:54 +00:00
b.SetActive(false);
}
continueTextMesh.text = Localization.GetString(waitKey);
}
}