public static void AddNotification(NkhMsg msg) { Scene globalScene = SceneManager.GetSceneByName("Global"); if (!globalScene.IsValid()) { return; } Transform game = globalScene.GetRootGameObjects()[0].transform.Find("Game"); if (game is null) { return; } //if (InGame.instance == null || notifications.Count >= maxMessagesAtOnce) if (notifications.Count >= maxMessagesAtOnce) { notificationQueue.Enqueue(msg); return; } lock (notifications) { int slot = 0; for (int i = 0; i < maxMessagesAtOnce; i++) //this terrible looking code gets first availible slot for message. prevents overlapping msgs { bool skip = false; foreach (Notification item in notifications) { if (item.slot == i) { skip = true; break; } } if (skip) { continue; } slot = i; break; } Notification notification = new Notification(slot, msg); notifications.Add(notification); } }
public Notification(int slot, NkhMsg msg) { if (assetBundle == null) { assetBundle = AssetBundle.LoadFromMemory(Properties.Resources.ingame_popup); } if (canvas == null) { canvas = assetBundle.LoadAsset("Canvas").Cast <GameObject>(); } this.slot = slot; //====== // Initialize game object stuff //====== Scene popups = SceneManager.GetSceneByName("Popups"); Scene mainMenuWorld = SceneManager.GetSceneByName("MainMenuWorld"); Scene globalScene = SceneManager.GetSceneByName("Global"); Scene commonForeground = SceneManager.GetSceneByName("CommonForegroundUI"); Scene mainMenuUI = SceneManager.GetSceneByName("MainMenuUi"); /*img = canvas.transform.Find("Image").GetComponent<Image>(); * title = canvas.transform.Find("Image/Title").GetComponent<Text>(); * body = canvas.transform.Find("Image/Body").GetComponent<Text>(); * * gameObject = GameObject.Instantiate(img.gameObject, mainMenuUI.GetRootGameObjects()[0].transform);*/ gameObject = GameObject.Instantiate(canvas, globalScene.GetRootGameObjects()[0].transform); //tried this to get popup showing on main menu. Didnt work /*var canvasPos = gameObject.transform.position; * gameObject.transform.position = new Vector3(canvasPos.x, canvasPos.y, -46); //48*/ img = gameObject.transform.Find("Image").GetComponent <Image>(); title = gameObject.transform.Find("Image/Title").GetComponent <Text>(); body = gameObject.transform.Find("Image/Body").GetComponent <Text>(); //====== //set ui elements //====== currentMsg = msg; title.text = currentMsg.NkhText.Title; title.color = currentMsg.NkhText.TitleColor; body.text = currentMsg.NkhText.Body; body.color = currentMsg.NkhText.BodyColor; //set pos so elements are positioned correctly int windowHeight = Screen.height; //MelonLogger.Log(windowHeight.ToString()); float test1 = (windowHeight / 8) * 1.155f; //var spaceBetweenSlots = 110 * slot; //var spaceBetweenSlots = 135* slot; float spaceBetweenSlots = test1 * slot; Vector3 pos = img.transform.position; pos.x = -defaultWidth; pos.y -= spaceBetweenSlots + 55; pos.z = 955; //might get rid of this later. Setting ui to be very high up so it won't get put under other stuff. Game camera is at about 995 nextX = -defaultWidth; img.transform.position = pos; if (currentMsg.MsgShowTime == 0) { currentMsg.MsgShowTime = 1.5; } //prepping final variables for smooth transitions msgIsAlive = true; doShowMsg = true; doStallMsg = false; doHideMsg = false; UpdateEvent += Notification_UpdateEvent; }