Jump to content

First KSP Mod. Issues creating a GUI Window


Recommended Posts

I'm trying my hand at creating my first KSP part mod, but I'm hitting a stumbling block right out of the gate. I found a tutorial here and have tried to complete the first step: create a GUI window for a part module. So here's my newb question.

I'm following this video here:

...which is essentially taking the stock RCS block and rewriting its functionality to bring up a basic GUI window.

The problem is that when I start KSP, I see that the module loads successfully in the log, and I can add the part to a craft in the VAB. When I go to launch it, however, I get no GUI whatsoever. In fact, I don't even see the print statement that I put into OnStart() that I should be seeing in the log. My concern is that this video tutorial set is for a vastly older version of KSP, but KSP's own wiki tutorials follow the same general syntax.

I'm kind of beating my head against the wall because I can't figure what I'm doing wrong. Does anybody have any suggestions or see something wrong with my helloworld code snippet below?


using System;
using UnityEngine;

namespace PluginTutorial{
public class PluginTutorial : PartModule {
private Rect _windowPosition = new Rect();

public override void OnStart(StartState state){
if (state != StartState.Editor){
print("[PluginTutorial] start: live");
RenderingManager.AddToPostDrawQueue(0, OnDraw);
}
}

private void OnDraw(){
if (this.vessel == FlightGlobals.ActiveVessel)
_windowPosition = GUILayout.Window(10, _windowPosition, OnWindow, "Title!");
}

private void OnWindow(int windowId){
GUILayout.BeginHorizontal(GUILayout.Width(250f));
GUILayout.Label("This is a label");
GUILayout.EndHorizontal();

GUI.DragWindow();
}
}
}

I should also point out that I am new to C#. Thanks for any advice or support. :)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...