Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 32b5d08

Browse files
authored
Merge pull request #1 from RYAN8990/Josh-T
Adds Helper and Mod Menu Classes
2 parents df10d98 + 3655d60 commit 32b5d08

5 files changed

Lines changed: 540 additions & 6 deletions

File tree

ModLoader/Helper.cs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnityEngine;
7+
using UnityEngine.SceneManagement;
8+
9+
namespace ModLoader
10+
{
11+
public class Helper : MonoBehaviour
12+
{
13+
public static Helper instance;
14+
15+
// Events
16+
/// <summary>
17+
/// Fired every frame in the Base Scene
18+
/// </summary>
19+
public static event EventHandler OnUpdateBaseScene;
20+
/// <summary>
21+
/// Fired every frame in the Home Scene
22+
/// </summary>
23+
public static event EventHandler OnUpdateHomeScene;
24+
/// <summary>
25+
/// Fired every frame in the Build Scene
26+
/// </summary>
27+
public static event EventHandler OnUpdateBuildScene;
28+
/// <summary>
29+
/// Fired every frame in the World Scene
30+
/// </summary>
31+
public static event EventHandler OnUpdateWorldScene;
32+
33+
/// <summary>
34+
/// Fired when the Base Scene (the first scene when game loads) is loaded
35+
/// </summary>
36+
public static event EventHandler OnBaseSceneLoaded;
37+
/// <summary>
38+
/// Fired when the start menu scene loaded -> After player has gone to another scene and come back
39+
/// </summary>
40+
public static event EventHandler OnHomeSceneLoaded;
41+
/// <summary>
42+
/// Fired when the Build Scene is loaded
43+
/// </summary>
44+
public static event EventHandler OnBuildSceneLoaded;
45+
/// <summary>
46+
/// Fired when the World Scene is Loaded
47+
/// </summary>
48+
public static event EventHandler OnWorldSceneLoaded;
49+
50+
51+
// Variables
52+
public static scene currentScene;
53+
54+
private void Awake()
55+
{
56+
instance = this;
57+
SceneManager.sceneLoaded += OnSceneLoaded;
58+
}
59+
60+
/// <summary>
61+
/// Fire all of the OnUpdate Events
62+
/// </summary>
63+
private void Update()
64+
{
65+
switch (currentScene)
66+
{
67+
case scene.Base:
68+
OnUpdateBaseScene?.Invoke(this, EventArgs.Empty);
69+
break;
70+
71+
case scene.Home:
72+
OnUpdateHomeScene?.Invoke(this, EventArgs.Empty);
73+
break;
74+
75+
case scene.Build:
76+
OnUpdateBuildScene?.Invoke(this, EventArgs.Empty);
77+
break;
78+
79+
case scene.World:
80+
OnUpdateWorldScene?.Invoke(this, EventArgs.Empty);
81+
break;
82+
}
83+
}
84+
85+
/// <summary>
86+
/// Fire all of the OnSceneLoaded Events
87+
/// </summary>
88+
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
89+
{
90+
switch (scene.name)
91+
{
92+
case "Base_PC":
93+
currentScene = ModLoader.scene.Base;
94+
OnBaseSceneLoaded?.Invoke(this, EventArgs.Empty);
95+
break;
96+
97+
case "Home_PC":
98+
currentScene = ModLoader.scene.Home;
99+
OnHomeSceneLoaded?.Invoke(this, EventArgs.Empty);
100+
break;
101+
102+
case "Build_PC":
103+
currentScene = ModLoader.scene.Build;
104+
OnBuildSceneLoaded?.Invoke(this, EventArgs.Empty);
105+
break;
106+
107+
case "World_PC":
108+
currentScene = ModLoader.scene.World;
109+
OnWorldSceneLoaded?.Invoke(this, EventArgs.Empty);
110+
break;
111+
}
112+
}
113+
}
114+
115+
public enum scene
116+
{
117+
Base,
118+
Home,
119+
Build,
120+
World
121+
}
122+
}

ModLoader/Loader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace ModLoader
1414
{
1515
/// <summary>
16-
/// This is the main class of ModLoader. this class is injected into the game whit Unity Doorstop injector.
16+
/// This is the main class of ModLoader. this class is injected into the game with Unity Doorstop injector.
1717
/// </summary>
1818
public class Loader : MonoBehaviour
1919
{
@@ -24,7 +24,7 @@ public class Loader : MonoBehaviour
2424

2525
private static Harmony patcher;
2626

27-
// Thiss save Loader instance
27+
// This save Loader instance
2828
public static Loader modLoader;
2929

3030
// This save the gameObject that implement Loader class

ModLoader/ModLoader.csproj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>ModLoader</RootNamespace>
1111
<AssemblyName>ModLoader</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
1516
</PropertyGroup>
1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1718
<DebugSymbols>true</DebugSymbols>
@@ -54,8 +55,21 @@
5455
<HintPath>..\Dependecies\UnityEngine.CoreModule.dll</HintPath>
5556
<Private>False</Private>
5657
</Reference>
58+
<Reference Include="UnityEngine.IMGUIModule">
59+
<HintPath>..\..\..\My Mods\References\Assemby-CSharp\UnityEngine.IMGUIModule.dll</HintPath>
60+
</Reference>
61+
<Reference Include="UnityEngine.TextRenderingModule">
62+
<HintPath>..\..\..\My Mods\References\Assemby-CSharp\UnityEngine.TextRenderingModule.dll</HintPath>
63+
</Reference>
64+
<Reference Include="UnityEngine.UI">
65+
<HintPath>..\..\..\My Mods\References\Assemby-CSharp\UnityEngine.UI.dll</HintPath>
66+
</Reference>
67+
<Reference Include="UnityEngine.UIModule">
68+
<HintPath>..\..\..\My Mods\References\Assemby-CSharp\UnityEngine.UIModule.dll</HintPath>
69+
</Reference>
5770
</ItemGroup>
5871
<ItemGroup>
72+
<Compile Include="Helper.cs" />
5973
<Compile Include="Loader.cs" />
6074
<Compile Include="ModConsole.cs" />
6175
<Compile Include="ModsMenu.cs" />

0 commit comments

Comments
 (0)