using System.Collections; 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 { [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 { get => _state; set { if (_state == value) return; _state = value; EventSystem.current.SetSelectedGameObject(null); var select = rDisplays.FirstOrDefault(d => d.states.Contains(value) && d.firstSelectedGameObject != null); if (select != null) EventSystem.current.SetSelectedGameObject(select.firstSelectedGameObject); } } public bool inMultiplayer; public float lerpSpeed = 10f; [System.Serializable] private class RectTransformDisplay{ public RectTransform target = null; public GameState[] states = new GameState[] { GameState.Menu }; [System.NonSerialized] public Vector2 basePosition = Vector2.zero; public Vector2 selectedPosition = Vector2.zero; public GameObject firstSelectedGameObject = null; } [System.Serializable] private class TransformDisplay : TransformDefault{ public GameState[] states = new GameState[] { GameState.Menu }; public int playerLoadedCount = 0; public TransformDisplay(Transform t, Vector3 p, Vector3 r, Vector3 s) : base(t, p, r, s) { } } private class TransformDefault{ public Transform target = null; public Vector3 position = Vector3.zero; public Vector3 rotation = Vector3.zero; public Vector3 scale = Vector3.one; public TransformDefault(Transform t, Vector3 p, Vector3 r, Vector3 s){ target = t; position = p; rotation = r; scale = s; } public void Set(float lerp){ target.localPosition = Vector3.Lerp(target.localPosition, position, lerp); target.localRotation = Quaternion.Slerp(target.localRotation, Quaternion.Euler(rotation), lerp); target.localScale = Vector3.Lerp(target.localScale, scale, lerp); } } private TransformDefault[] tDefault; [SerializeField] private RectTransformDisplay[] rDisplays = new RectTransformDisplay[0]; [SerializeField] private TransformDisplay[] tDisplays = new TransformDisplay[0]; public GameState[] selectedOrthoStates; public float selectedCameraOrthoSize = 3f; private float baseCameraOrthoSize; private Camera baseCamera; private void Awake() { Instance = this; } private void Start() { escapeButton.GetComponent