Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Interop;
- using TMPro;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- namespace Horizon
- {
- public class HorizonUI : MonoBehaviour
- {
- static readonly String prefix = "(HorizonUi)";
- static readonly String officialMenuScene = "simulation";
- static readonly String officialMenuUi = "MainMenuUI";
- static readonly String officialMenuUiChild = "MainMenu";
- static readonly String officialInGameUi = "InGameUI";
- static readonly String officialMenuTopLevel = "TopLevel";
- private static UnityModManagerNet.UnityModManager.ModEntry mod;
- private static int waitDuration = 100;
- private static bool searchingForGameState;
- private static bool searchingForMainMenu;
- private static bool searchingForMenuNode;
- private static bool searchingForTopLevel;
- static Scene scene;
- // Extern
- public static void Init( UnityModManagerNet.UnityModManager.ModEntry modEntry )
- {
- mod = modEntry;
- searchingForMainMenu = true;
- searchingForGameState = true;
- searchingForMenuNode = true;
- searchingForTopLevel = true;
- HorizonUI horizonUiManager = new HorizonUI();
- HorizonMessages.writeMessage(prefix,
- "Creating new Thread.",
- mod);
- Thread uiThread = new Thread( delegate() {
- horizonUiManager.CreateMenu();
- });
- uiThread.Start();
- }
- public void CreateMenu()
- {
- //While of death
- while (searchingForMainMenu)
- {
- scene = SceneManager.GetActiveScene();
- if (scene.name == officialMenuScene )
- {
- HorizonMessages.writeMessage(prefix,
- "Found main menu scene: " + scene.name + ".",
- mod);
- searchingForMainMenu = false;
- while (searchingForGameState)
- {
- if (GameState.inst != null)
- {
- HorizonMessages.Debug("gamestate is not null anymore", mod);
- searchingForGameState = false;
- while (searchingForMenuNode)
- {
- if (GameState.inst.mainMenuMode != null)
- {
- HorizonMessages.Debug("gamemode is not null anymore", mod);
- searchingForMenuNode = false;
- while (searchingForTopLevel)
- {
- if (GameState.inst.mainMenuMode.topLevelUI != null)
- {
- HorizonMessages.Debug("toplevel is not null anymore", mod);
- searchingForTopLevel = false;
- }
- else
- {
- HorizonMessages.Debug("toplevel is null", mod);
- Thread.Sleep(waitDuration);
- }
- }
- }
- else
- {
- HorizonMessages.Debug("gamemode is null", mod);
- Thread.Sleep(waitDuration);
- }
- }
- }
- else
- {
- HorizonMessages.Debug("gamestate is null", mod);
- Thread.Sleep(waitDuration);
- }
- }
- }
- else
- {
- Thread.Sleep(waitDuration);
- }
- }
- HorizonMessages.writeMessage(prefix, "Left while loop.", mod);
- GameObject topLevel = GameState.inst.mainMenuMode.topLevelUI;
- GameObject horizonBanner = new GameObject();
- DontDestroyOnLoad(horizonBanner);
- Text text = horizonBanner.AddComponent<Text>();
- RectTransform t = text.transform as RectTransform;
- horizonBanner.transform.parent = topLevel.transform;
- text.text = "Lingadium levi displaynow!";
- text.color = Color.red;
- text.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
- text.fontSize = 20;
- t.anchorMin = new Vector2(0f, 1f);
- t.anchorMax = new Vector2(0f, 1f);
- t.pivot = new Vector2(0f, 1f);
- t.sizeDelta = new Vector2(200, 50);
- t.anchoredPosition = new Vector2(0, 0);
- /*
- t.anchorMin = new Vector2(0f, 1f);
- t.anchorMax = new Vector2(0f, 1f);
- t.pivot = new Vector2(0f, 1f);
- t.sizeDelta = new Vector2(200, 50);
- t.anchoredPosition = new Vector2(50f, -50f);
- */
- //t.transform.position = new Vector2(-200, 40);
- /*
- TextMeshProUGUI tmpU = topLevel.GetComponent<TextMeshProUGUI>();
- tmpU.text = "lol";
- */
- /*
- Text text = (new GameObject()).AddComponent<Text>();
- text.transform.SetParent(horizonCanvas.transform);
- text.text = "Lingardium levi displaynow!";
- RectTransform t = text.transform as RectTransform;
- //Rect rect = t.rect;
- t.anchorMin = new Vector2(0f, 1f);
- t.anchorMax = new Vector2(0f, 1f);
- t.pivot = new Vector2(0f, 1f);
- t.sizeDelta = new Vector2(200, 50);
- t.anchoredPosition = new Vector2(50f, -50f);
- */
- //trans.anchoredPosition = new Vector2(20, 20);
- HorizonMessages.writeMessage(prefix, "HorizonUi loaded.", mod);
- }
- public static Scene getCurrentScene()
- {
- return SceneManager.GetActiveScene();
- }
- public static String getSceneName(Scene scene)
- {
- return scene.name;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement