From 7f493f682503f5186308de7b8f74b5b49233cfe4 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 2 Nov 2023 11:51:31 +0800 Subject: +init --- GameCode/LevelSelectManager.cs | 114 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 GameCode/LevelSelectManager.cs (limited to 'GameCode/LevelSelectManager.cs') diff --git a/GameCode/LevelSelectManager.cs b/GameCode/LevelSelectManager.cs new file mode 100644 index 0000000..5650ffd --- /dev/null +++ b/GameCode/LevelSelectManager.cs @@ -0,0 +1,114 @@ +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +public class LevelSelectManager : MonoBehaviour +{ + public static LevelSelectManager instance; + + private LevelInteractor[] levelInteractors; + + public Vector3 spawnOnLevelOffsetPositon; + + public PlayerMovement playerMovement; + + public TMP_Text levelTitle; + + public TMP_Text levelHighscore; + + public TMP_Text beatenState; + + public string notBeatenYet = "Not beaten yet."; + + public string successfullyBeaten = "Successfully beaten."; + + public string scorePrefix = "Your Best: "; + + public GameObject tooltipObject; + + public Image tooltipImage; + + public TMP_Text tooltipTitle; + + public TMP_Text tooltipDescription; + + private Equippable showingTooltipFor; + + public Canvas levelSelectedCanvas; + + public Camera camMain; + + private LevelInteractor openedLevel; + + private int iFrames; + + private bool fixedLoadout; + + public Equippable ShowingTooltipFor => showingTooltipFor; + + public bool PreLevelMenuIsOpen => openedLevel != null; + + public void ShowTooltip(Equippable _eq) + { + showingTooltipFor = _eq; + tooltipObject.SetActive(_eq != null); + if (!(_eq == null)) + { + tooltipImage.sprite = _eq.icon; + tooltipTitle.text = _eq.displayName; + tooltipDescription.text = _eq.description; + float num = camMain.pixelRect.height / levelSelectedCanvas.pixelRect.height; + tooltipObject.transform.position = Input.mousePosition * num; + } + } + + private void Awake() + { + instance = this; + } + + private void Start() + { + levelInteractors = GetComponentsInChildren(); + ShowTooltip(null); + } + + private void MovePlayerToTheLevelYouCameFrom() + { + SceneTransitionManager sceneTransitionManager = SceneTransitionManager.instance; + if (!sceneTransitionManager || sceneTransitionManager.ComingFromGameplayScene == "") + { + return; + } + for (int i = 0; i < levelInteractors.Length; i++) + { + if (levelInteractors[i].sceneName == sceneTransitionManager.ComingFromGameplayScene) + { + playerMovement.TeleportTo(levelInteractors[i].transform.position + spawnOnLevelOffsetPositon); + break; + } + } + } + + private void Update() + { + if (iFrames <= 1) + { + MovePlayerToTheLevelYouCameFrom(); + } + iFrames++; + } + + public void PlayButtonPressed() + { + if (PreLevelMenuIsOpen) + { + if (openedLevel.fixedLoadout.Count > 0) + { + PerkManager.instance.CurrentlyEquipped.Clear(); + PerkManager.instance.CurrentlyEquipped.AddRange(openedLevel.fixedLoadout); + } + SceneTransitionManager.instance.TransitionFromLevelSelectToLevel(openedLevel.sceneName); + } + } +} -- cgit v1.1-26-g67d0