-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolbar.cs
156 lines (123 loc) · 3.51 KB
/
Toolbar.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using UnityEngine;
using KSP.UI.Screens;
using System.IO;
using RUI.Icons.Selectable;
namespace SciencePlus
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class AppButton : MonoBehaviour
{
const ApplicationLauncher.AppScenes buttonScenes = ApplicationLauncher.AppScenes.SPACECENTER | ApplicationLauncher.AppScenes.FLIGHT;
private static ApplicationLauncherButton button = null;
public static Callback Toggle = delegate { };
public void Start()
{
GameObject.DontDestroyOnLoad(this);
GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
}
void OnDestroy()
{
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
}
void OnGUIAppLauncherReady()
{
if (ApplicationLauncher.Ready && button == null)
{
Texture tex = GameDatabase.Instance.GetTexture("SciencePlus/Assets/icon", false);
button = ApplicationLauncher.Instance.AddModApplication(OnToggle, OnToggle, null, null, null, null, buttonScenes, tex);
UpdateVisibility();
}
}
static bool buttonVisible
{
get
{
return true;
}
}
public static void UpdateVisibility()
{
if (button != null)
{
button.VisibleInScenes = buttonVisible ? buttonScenes : 0;
}
}
private void OnToggle()
{
Toggle();
}
}
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class Toolbar_Flight : MonoBehaviour
{
public void Awake()
{
AppButton.Toggle += WindowFlight.ToggleGUI;
}
void OnDestroy()
{
AppButton.Toggle -= WindowFlight.ToggleGUI;
}
}
[KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
public class Toolbar_SpaceCenter : MonoBehaviour
{
public void Awake()
{
AppButton.Toggle += WindowSpaceCenter.ToggleGUI;
}
void OnDestroy()
{
AppButton.Toggle -= WindowSpaceCenter.ToggleGUI;
}
}
}
/*
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace TestAddon
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class CoolUILoader : MonoBehaviour
{
private static GameObject panelPrefab;
public static GameObject PanelPrefab
{
get { return panelPrefab; }
}
private void Awake()
{
AssetBundle prefabs = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mycoolui.dat"));
panelPrefab = prefabs.LoadAsset("MyCoolUIPanel") as GameObject;
}
}
[KSPAddon(KSPAddon.Startup.AllGameScenes, true)]
public class CoolUI : MonoBehaviour
{
public static GameObject CoolUICanvas = null;
public static GameObject CoolUIText = null;
public static void Destroy()
{
CoolUICanvas.DestroyGameObject();
CoolUICanvas = null;
}
public static void ShowGUI()
{
CoolUICanvas = (GameObject)Instantiate(CoolUILoader.PanelPrefab);
Debug.Log("[--------SCIENCE+--------]: 1");
CoolUICanvas.transform.SetParent(MainCanvasUtil.MainCanvas.transform);
Debug.Log("[--------SCIENCE+--------]: 2");
CoolUICanvas.AddComponent<CoolUI>();
Debug.Log("[--------SCIENCE+--------]: 3");
CoolUIText = (GameObject)GameObject.Find("ImportantText");
Debug.Log("[--------SCIENCE+--------]: 4");
GameObject checkToggle = (GameObject)GameObject.Find("CheckThisOUt");
Debug.Log("[--------SCIENCE+--------]: 5");
}
}
}
*/