Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Windows.Interop;
  6. using TMPro;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. using UnityEngine.UI;
  10.  
  11. namespace Horizon
  12. {
  13.     public class HorizonUI : MonoBehaviour
  14.     {
  15.         static readonly String prefix = "(HorizonUi)";
  16.         static readonly String officialMenuScene = "simulation";
  17.         static readonly String officialMenuUi = "MainMenuUI";
  18.         static readonly String officialMenuUiChild = "MainMenu";
  19.         static readonly String officialInGameUi = "InGameUI";
  20.         static readonly String officialMenuTopLevel = "TopLevel";
  21.  
  22.         private static UnityModManagerNet.UnityModManager.ModEntry mod;
  23.         private static int waitDuration = 100;
  24.  
  25.         private static bool searchingForGameState;
  26.         private static bool searchingForMainMenu;
  27.         private static bool searchingForMenuNode;
  28.         private static bool searchingForTopLevel;
  29.  
  30.         static Scene scene;
  31.  
  32.         // Extern
  33.      
  34.         public static void Init( UnityModManagerNet.UnityModManager.ModEntry modEntry )
  35.         {
  36.             mod = modEntry;
  37.             searchingForMainMenu  = true;
  38.             searchingForGameState = true;
  39.             searchingForMenuNode  = true;
  40.             searchingForTopLevel  = true;
  41.             HorizonUI horizonUiManager = new HorizonUI();
  42.             HorizonMessages.writeMessage(prefix,
  43.                                                  "Creating new Thread.",
  44.                                                  mod);
  45.             Thread uiThread = new Thread( delegate() {
  46.                 horizonUiManager.CreateMenu();
  47.             });
  48.             uiThread.Start();
  49.            
  50.  
  51.         }
  52.  
  53.         public void CreateMenu()
  54.         {
  55.             //While of death
  56.             while (searchingForMainMenu)
  57.             {
  58.                 scene = SceneManager.GetActiveScene();
  59.                 if (scene.name == officialMenuScene )
  60.                 {
  61.                     HorizonMessages.writeMessage(prefix,
  62.                                                  "Found main menu scene: " + scene.name + ".",
  63.                                                  mod);
  64.                     searchingForMainMenu = false;
  65.                     while (searchingForGameState)
  66.                     {
  67.                         if (GameState.inst != null)
  68.                         {
  69.                             HorizonMessages.Debug("gamestate is not null anymore", mod);
  70.                             searchingForGameState = false;
  71.                             while (searchingForMenuNode)
  72.                             {
  73.                                 if (GameState.inst.mainMenuMode != null)
  74.                                 {
  75.                                     HorizonMessages.Debug("gamemode is not null anymore", mod);
  76.                                     searchingForMenuNode = false;
  77.                                     while (searchingForTopLevel)
  78.                                     {
  79.                                         if (GameState.inst.mainMenuMode.topLevelUI != null)
  80.                                         {
  81.                                             HorizonMessages.Debug("toplevel is not null anymore", mod);
  82.                                             searchingForTopLevel = false;
  83.  
  84.                                         }
  85.                                         else
  86.                                         {
  87.                                             HorizonMessages.Debug("toplevel is null", mod);
  88.                                             Thread.Sleep(waitDuration);
  89.                                         }
  90.  
  91.                                     }
  92.  
  93.                                 }
  94.                                 else
  95.                                 {
  96.                                     HorizonMessages.Debug("gamemode is null", mod);
  97.                                     Thread.Sleep(waitDuration);
  98.                                 }
  99.  
  100.                             }
  101.                         }
  102.                         else
  103.                         {
  104.                             HorizonMessages.Debug("gamestate is null", mod);
  105.                             Thread.Sleep(waitDuration);
  106.                         }
  107.                     }
  108.                 }
  109.                 else
  110.                 {
  111.                     Thread.Sleep(waitDuration);
  112.                 }
  113.             }
  114.            
  115.  
  116.             HorizonMessages.writeMessage(prefix, "Left while loop.", mod);
  117.  
  118.  
  119.             GameObject topLevel = GameState.inst.mainMenuMode.topLevelUI;
  120.             GameObject horizonBanner = new GameObject();
  121.             DontDestroyOnLoad(horizonBanner);
  122.            
  123.             Text text = horizonBanner.AddComponent<Text>();
  124.             RectTransform t = text.transform as RectTransform;
  125.             horizonBanner.transform.parent = topLevel.transform;
  126.  
  127.             text.text = "Lingadium levi displaynow!";
  128.             text.color = Color.red;
  129.             text.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
  130.             text.fontSize = 20;
  131.  
  132.             t.anchorMin = new Vector2(0f, 1f);
  133.             t.anchorMax = new Vector2(0f, 1f);
  134.             t.pivot = new Vector2(0f, 1f);
  135.             t.sizeDelta = new Vector2(200, 50);
  136.             t.anchoredPosition = new Vector2(0, 0);
  137.  
  138.             /*
  139.             t.anchorMin = new Vector2(0f, 1f);
  140.             t.anchorMax = new Vector2(0f, 1f);
  141.             t.pivot = new Vector2(0f, 1f);
  142.             t.sizeDelta = new Vector2(200, 50);
  143.             t.anchoredPosition = new Vector2(50f, -50f);
  144.             */
  145.  
  146.             //t.transform.position = new Vector2(-200, 40);
  147.             /*
  148.             TextMeshProUGUI tmpU = topLevel.GetComponent<TextMeshProUGUI>();
  149.             tmpU.text = "lol";
  150.             */
  151.  
  152.             /*
  153.             Text text = (new GameObject()).AddComponent<Text>();
  154.            
  155.             text.transform.SetParent(horizonCanvas.transform);
  156.             text.text = "Lingardium levi displaynow!";
  157.             RectTransform t = text.transform as RectTransform;
  158.            
  159.  
  160.             //Rect rect = t.rect;
  161.             t.anchorMin = new Vector2(0f, 1f);
  162.             t.anchorMax = new Vector2(0f, 1f);
  163.             t.pivot = new Vector2(0f, 1f);
  164.             t.sizeDelta = new Vector2(200, 50);
  165.             t.anchoredPosition = new Vector2(50f, -50f);
  166.             */
  167.  
  168.  
  169.             //trans.anchoredPosition = new Vector2(20, 20);
  170.  
  171.  
  172.             HorizonMessages.writeMessage(prefix, "HorizonUi loaded.", mod);
  173.         }
  174.  
  175.        
  176.  
  177.  
  178.         public  static Scene getCurrentScene()
  179.         {
  180.             return SceneManager.GetActiveScene();
  181.         }
  182.  
  183.         public static String getSceneName(Scene scene)
  184.         {
  185.             return scene.name;
  186.         }
  187.  
  188.      
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement