Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
KSP toolbar setup not working as expected
using System;
using UnityEngine;
using KSP.UI.Screens;
namespace ToolBarTest
[KSPAddon(KSPAddon.Startup.MainMenu, false)]
public class ToolBarTest : MonoBehaviour
public static ApplicationLauncherButton button_1;
public static ApplicationLauncherButton button_2;
Texture2D test_texture_1 = new Texture2D(1, 1, TextureFormat.RGBA32, false);
Texture2D test_texture_2 = new Texture2D(1, 1, TextureFormat.RGBA32, false);
private void Awake(){
test_texture_1.SetPixel(0, 0,;
test_texture_2.SetPixel(0, 0,;
Debug.Log ("Adding App launcher event callbacks");
GameEvents.onGUIApplicationLauncherReady.Add (this.app_launcher_ready);
GameEvents.onGUIApplicationLauncherDestroyed.Add (this.app_launcher_destroyed);
public void app_launcher_ready(){
GameEvents.onGUIApplicationLauncherReady.Remove (this.app_launcher_ready);
Debug.Log ("app launcher is ready");
add_to_toolbar ();
public void app_launcher_destroyed(){
Debug.Log ("app launcher destroyed");
public void add_to_toolbar(){
Debug.Log ("Adding buttons to toolbar");
ToolBarTest.button_1 = ApplicationLauncher.Instance.AddModApplication (
button_1_action, button_1_action,
null, null,
null, null,
ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH,
ToolBarTest.button_2 = ApplicationLauncher.Instance.AddModApplication (
button_2_action, button_2_action,
null, null,
null, null,
public void remove_from_toolbar(){
Debug.Log ("removing button from toolbar");
ApplicationLauncher.Instance.RemoveModApplication (button_1);
ApplicationLauncher.Instance.RemoveModApplication (button_2);
public void button_1_action(){
Debug.Log ("button 1: Oi! someone clicked me.");
public void button_2_action(){
Debug.Log ("button 2: quit poking me.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment