proper esc
This commit is contained in:
parent
0e365b3d23
commit
d7deb5d8c4
|
@ -10,6 +10,7 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
public static GameBoardInstance instance { get; private set; }
|
||||
|
||||
public GameBoard player1, player2;
|
||||
public bool gameActive;
|
||||
|
||||
[Header("Text")]
|
||||
public TextMeshProUGUI headerTextMesh;
|
||||
|
@ -33,7 +34,7 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
if (GameTransition.Instance == null) return;
|
||||
|
||||
var state = GameTransition.Instance.state;
|
||||
if (state == GameState.InGame && !endGameCoroutine){
|
||||
if (state == GameState.InGame && gameActive){
|
||||
var over = player1.delayState == GameBoard.DelayState.Loss || player2.delayState == GameBoard.DelayState.Loss;
|
||||
|
||||
if (over){
|
||||
|
@ -57,14 +58,7 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
switch(response){
|
||||
// leave room
|
||||
case 0:
|
||||
if (NetworkManager.inRoom){
|
||||
NetworkManager.net.OpLeaveRoom();
|
||||
GameTransition.Instance.state = GameState.Multiplayer;
|
||||
} else {
|
||||
GameTransition.Instance.state = GameState.Menu;
|
||||
}
|
||||
player1.Clear();
|
||||
player2.Clear();
|
||||
ExitGame(true);
|
||||
break;
|
||||
// return to lobby or not enough players
|
||||
case 1:
|
||||
|
@ -124,15 +118,15 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
|
||||
PlayerProperties.CreatePlayerHashtable();
|
||||
callback();
|
||||
gameActive = true;
|
||||
|
||||
yield return new WaitForSeconds(2f);
|
||||
headerTextMesh.text = "";
|
||||
}
|
||||
|
||||
private bool endGameCoroutine;
|
||||
|
||||
private IEnumerator EndGameTimer(float timer){
|
||||
endGameCoroutine = true;
|
||||
gameActive = false;
|
||||
|
||||
headerTextMesh.text = Localization.GetString(gameSetKey);
|
||||
yield return new WaitForSeconds(timer);
|
||||
|
@ -140,8 +134,6 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
|
||||
GameTransition.Instance.state = GameState.Continue;
|
||||
Rematch.Instance.Setup();
|
||||
|
||||
endGameCoroutine = false;
|
||||
}
|
||||
|
||||
private void StartSinglePlayer(){
|
||||
|
@ -155,4 +147,23 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
player2.Setup();
|
||||
}
|
||||
|
||||
public void ExitGame(bool force = false){
|
||||
if (gameActive || force){
|
||||
gameActive = false;
|
||||
|
||||
player1.Stop();
|
||||
player2.Stop();
|
||||
|
||||
player1.Clear();
|
||||
player2.Clear();
|
||||
|
||||
if (NetworkManager.inRoom){
|
||||
NetworkManager.net.OpLeaveRoom();
|
||||
GameTransition.Instance.state = GameState.Multiplayer;
|
||||
} else {
|
||||
GameTransition.Instance.state = GameState.Menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,48 +2,21 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using System.Linq;
|
||||
|
||||
public enum GameState { Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits, Help }
|
||||
|
||||
public class GameTransition : MonoBehaviour {
|
||||
|
||||
#region Escape
|
||||
public static void Escape() {
|
||||
// Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits
|
||||
switch (Instance.state){
|
||||
case GameState.SinglePlayer:
|
||||
case GameState.Multiplayer:
|
||||
case GameState.SelectingRegion:
|
||||
case GameState.Continue:
|
||||
case GameState.InGame:
|
||||
case GameState.Help:
|
||||
// Hard reset states
|
||||
// Blah blah deprecated still works
|
||||
Application.LoadLevel(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
Instance.state = GameState.Menu;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ShowEscape() {
|
||||
switch(Instance.state) {
|
||||
case GameState.Menu:
|
||||
case GameState.Lobby:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public UnityEngine.UI.Button EscapeButton;
|
||||
#endregion
|
||||
[Header("Escape")]
|
||||
public RectTransform escapeButton;
|
||||
public Vector2 selectedEscapePosition = Vector2.zero;
|
||||
private Vector2 baseEscapePosition;
|
||||
|
||||
public static GameTransition Instance { get; private set; }
|
||||
|
||||
[Header("Main")]
|
||||
[SerializeField]
|
||||
private GameState _state;
|
||||
public GameState state {
|
||||
|
@ -121,7 +94,8 @@ public class GameTransition : MonoBehaviour {
|
|||
}
|
||||
|
||||
private void Start() {
|
||||
if (EscapeButton) EscapeButton.onClick.AddListener(Escape);
|
||||
escapeButton.GetComponent<Button>().onClick.AddListener(Escape);
|
||||
baseEscapePosition = escapeButton.anchoredPosition;
|
||||
|
||||
baseCamera = Camera.main;
|
||||
baseCameraOrthoSize = baseCamera.orthographicSize;
|
||||
|
@ -133,17 +107,28 @@ public class GameTransition : MonoBehaviour {
|
|||
tDefault = tDisplays.Select(t => t.target).Distinct().Select(t => new TransformDefault(t, t.localPosition, t.localEulerAngles, t.localScale)).ToArray();
|
||||
}
|
||||
|
||||
private bool prevState;
|
||||
private bool curState;
|
||||
|
||||
private void Update() {
|
||||
|
||||
// obscure fix to input field + esc
|
||||
prevState = curState;
|
||||
var sinputfield = EventSystem.current.currentSelectedGameObject;
|
||||
if (sinputfield){
|
||||
var comp = sinputfield.GetComponent<TMPro.TMP_InputField>();
|
||||
curState = comp ? comp.isFocused : false;
|
||||
} else {
|
||||
curState = false;
|
||||
}
|
||||
|
||||
// Escape handling
|
||||
if (state != GameState.Menu) {
|
||||
if (Input.GetKey(KeyCode.Escape)) {
|
||||
Escape();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Escape)) {
|
||||
if (prevState && !curState) return;
|
||||
Escape();
|
||||
}
|
||||
|
||||
if (EscapeButton)
|
||||
EscapeButton.gameObject.SetActive(ShowEscape());
|
||||
|
||||
// in case the player disconnects during any weird times
|
||||
if (inMultiplayer){
|
||||
switch(NetworkManager.net.State){
|
||||
case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected:
|
||||
|
@ -198,5 +183,43 @@ public class GameTransition : MonoBehaviour {
|
|||
|
||||
baseCamera.orthographicSize = Mathf.Lerp(baseCamera.orthographicSize, selectedOrthoStates.Contains(state) ? selectedCameraOrthoSize : baseCameraOrthoSize, dist);
|
||||
|
||||
escapeButton.anchoredPosition = Vector2.Lerp(escapeButton.anchoredPosition, ShowEscapeButton() ? selectedEscapePosition : baseEscapePosition, dist);
|
||||
|
||||
}
|
||||
|
||||
bool ShowEscapeButton(){
|
||||
return state != GameState.Menu;
|
||||
}
|
||||
|
||||
void Escape(){
|
||||
if (!ShowEscapeButton()) return;
|
||||
|
||||
switch (state){
|
||||
case GameState.Help:
|
||||
case GameState.Credits:
|
||||
state = GameState.Menu;
|
||||
break;
|
||||
// must disconnect
|
||||
case GameState.Multiplayer:
|
||||
case GameState.SelectingRegion:
|
||||
state = GameState.ConnectionInProgress;
|
||||
NetworkManager.net.Service();
|
||||
NetworkManager.net.Disconnect();
|
||||
break;
|
||||
|
||||
// special case, leave room
|
||||
case GameState.Lobby:
|
||||
state = GameState.ConnectionInProgress;
|
||||
NetworkManager.net.OpLeaveRoom();
|
||||
break;
|
||||
|
||||
// close game
|
||||
case GameState.InGame:
|
||||
GameBoardInstance.instance.ExitGame();
|
||||
break;
|
||||
case GameState.Continue:
|
||||
GameBoardInstance.instance.ExitGame(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -20
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
@ -170,24 +170,6 @@ MonoBehaviour:
|
|||
speed: 0.25
|
||||
one: {fileID: 456349643}
|
||||
two: {fileID: 1386837618}
|
||||
--- !u!1 &130187149 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 1736330633655152094, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 1736330635466942931}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &130187155
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 130187149}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 62d2a91b62e06c04cb0f877e535b187e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &456349642
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1421,6 +1403,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
player1: {fileID: 647195263}
|
||||
player2: {fileID: 2143326256}
|
||||
gameActive: 0
|
||||
headerTextMesh: {fileID: 2013137395}
|
||||
startKey: GAME_START
|
||||
gameSetKey: GAME_GAMESET
|
||||
|
@ -1559,17 +1542,9 @@ PrefabInstance:
|
|||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 380521610, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 380521610, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 380521610, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
|
||||
- target: {fileID: 482421870, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
value: 49.99994
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 610498694, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
|
@ -1651,185 +1626,10 @@ PrefabInstance:
|
|||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633638169071, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633638169071, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633638169071, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
- target: {fileID: 1736330633687387551, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633760980512, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633760980512, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633760980512, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633775482130, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633775482130, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633775482130, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633916843623, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633916843623, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330633916843623, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634003904156, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634003904156, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634003904156, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634159991433, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634159991433, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634159991433, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634177679782, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634177679782, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634177679782, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634248025819, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634248025819, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634248025819, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634454597124, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634454597124, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634454597124, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634653605562, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634653605562, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634653605562, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634900042864, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634900042864, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330634900042864, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635014798853, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635014798853, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635014798853, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
value: 49.99994
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635070797285, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
|
@ -1941,21 +1741,6 @@ PrefabInstance:
|
|||
propertyPath: m_Pivot.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635428427867, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635428427867, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635428427867, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1736330635485585598, guid: adba91609cb1e5448b76682be198fc9b,
|
||||
type: 3}
|
||||
propertyPath: tDisplays.Array.data[0].target
|
||||
|
|
Loading…
Reference in New Issue