-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
52 lines (46 loc) · 1.7 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using BepInEx;
using KSP.Game;
using System;
using UnityEngine;
namespace KSP2_TestPlugin
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
Logger.LogInfo($"We are in...");
}
private GameInstance gameInstance = null;
public void Update()
{
if (gameInstance == null)
// It is slow to use FindObjectOfType<>() as it has to traverse the entire scene, so we cache what we can
gameInstance = FindObjectOfType<GameInstance>();
// Not everything you want to access is actually available or instantiated at any given point in time.
// Need to always be programming defensively
if (gameInstance != null && Input.GetKeyDown(KeyCode.F2))
{
NotificationData notificationData = new NotificationData
{
Tier = NotificationTier.Alert,
Importance = NotificationImportance.Medium,
AlertTitle =
{
LocKey = "Success!"
},
FirstLine =
{
LocKey = "You have a game instance!"
},
IsTimerActive = true,
TimerDuration = 3f,
TimeStamp = DateTime.Now
};
gameInstance.Notifications.ProcessNotification(notificationData);
}
}
}
}