Finalize Mod #8

Merged
david merged 17 commits from dev into main 2026-08-24 17:20:17 +02:00
Showing only changes of commit 7a1227d588 - Show all commits
+48 -22
View File
@@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace IngameReveries namespace IngameReveries
@@ -29,34 +30,46 @@ namespace IngameReveries
{ {
InitializeAssets(); InitializeAssets();
SceneManager.sceneLoaded += (scene, mode) => SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
// Make sure you clean up properly to support Live Reload.
Debug.Log("Good bye! " + mod.metadata.id);
harmony.UnpatchAll();
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
// Check if UI already instantiated
if (_ingameReveriesUI != null)
{ {
// Check if UI already instantiated return;
if (_ingameReveriesUI != null) }
string gameSceneDir = "Assets/Dew/Zones/";
string relativeToScene = Path.GetRelativePath(gameSceneDir, scene.path);
if (!relativeToScene.StartsWith(".."))
{
Debug.Log($"[IngameReveries] Switched to scene inside {gameSceneDir}");
GameObject menuViewGO = GameObject.Find("GameLogicPackage/UI/InGame/UI_Common_MenuView");
if (menuViewGO == null)
{ {
Debug.Log("Couldn't find menu view");
return; return;
} }
string gameSceneDir = "Assets/Dew/Zones/"; _ingameReveriesUI = Instantiate(_reveriesPrefab, menuViewGO.transform);
string relativeToScene = Path.GetRelativePath(gameSceneDir, scene.path); _ingameReveriesUI.SetActive(true);
_ingameReveriesUI.name = "IngameReveriesUI";
_ingameReveriesUI.transform.SetSiblingIndex(1);
if (!relativeToScene.StartsWith("..")) var reveries = _ingameReveriesUI.GetComponent<UI_Reveries>();
{
Debug.Log($"[IngameReveries] Switched to scene inside {gameSceneDir}");
GameObject menuViewGO = GameObject.Find("GameLogicPackage/UI/InGame/UI_Common_MenuView");
if (menuViewGO == null)
{
Debug.Log("Couldn't find menu view");
return;
}
_ingameReveriesUI = Instantiate(_reveriesPrefab, menuViewGO.transform);
_ingameReveriesUI.SetActive(true);
_ingameReveriesUI.name = "IngameReveriesUI";
_ingameReveriesUI.transform.SetAsFirstSibling();
var reveries = _ingameReveriesUI.GetComponent<UI_Reveries>();
var rect = _ingameReveriesUI.GetComponent<RectTransform>(); var rect = _ingameReveriesUI.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(0f, 1f); rect.anchorMin = new Vector2(0f, 1f);
@@ -72,6 +85,19 @@ namespace IngameReveries
// Make sure you clean up properly to support Live Reload. // Make sure you clean up properly to support Live Reload.
Debug.Log("Good bye! " + mod.metadata.id); Debug.Log("Good bye! " + mod.metadata.id);
harmony.UnpatchAll(); harmony.UnpatchAll();
// Show reveries window
var canvasGroup = _ingameReveriesUI.GetComponent<CanvasGroup>();
canvasGroup.alpha = 1f;
canvasGroup.interactable = true;
canvasGroup.blocksRaycasts = true;
// Position reveries window top left
var rect = _ingameReveriesUI.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(0f, 1f);
rect.anchorMax = new Vector2(0f, 1f);
rect.pivot = new Vector2(0f, 1f);
rect.anchoredPosition = new Vector2(+70f, -70f);
}
} }
private void InitializeAssets() private void InitializeAssets()