Jump to content

How to trigger a non-part addon


Recommended Posts

Hi guys

I'm trying to make a hello world mod. I just want to display a window during flight with some text. However, I dont know how to get KSP to actually kick off my DLL.

I looked at some of nifty255's vids but they all use partplugin to get triggered.

My plan was to just place the .dll in the gamedata\myplugin\Plugins folder but it didn't work.

Here's my very simple code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;


namespace eatxttest
{
[KSPAddon(KSPAddon.Startup.Flight, false)]
class ExampleLoader : MonoBehaviour
{
string stringToLoad = "TestTXT";

void Awake()
{

}

void OnGui()
{
GUI.Window(GetInstanceID(), new Rect(5f,40f,500f,400f), DrawGui, "Window");
}

void DrawGui(int windowID)
{
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("stringToLoad");
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
}

Link to comment
Share on other sites

I *think* it could just be your capitalisation of OnGUI (all of GUI is capitalised). You do have Debug.Log() and print() for sticking things in the log as well so you can see that OnGui() is never entered but Awake() did run (massive red flag for OnGui).

PS

You dont need the GUILayout.Begin/End for just putting stuff in a window. By default, GUILayout places each object sequentially in a single column, Begin Horizontal is used to start a row, and then Begin Vertical makes a column inside a cell of that row.

Edited by Crzyrndm
Link to comment
Share on other sites

Anything inheriting from Monobehaviour also gets print() which is the same thing as Debug.Log (Also, try typing it out manually with capitilisation and all. Sometimes VS autocomplete is silly about it)

[COLOR=#333333][FONT=Consolas]Debug.Log([/FONT][/COLOR][COLOR=#333333][FONT=Consolas]o);

Link to comment
Share on other sites

Hmm... I don't know what I did before, but it sure is working now. Thanks a lot. It was the uppercase.

Here's my code and a screenshot of the result in case anyone will benefit:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;


namespace eatxttest
{
[KSPAddon(KSPAddon.Startup.Flight, false)]
class ExampleLoader : MonoBehaviour
{

void Awake()
{

}

void OnGUI()
{
GUI.Window(GetInstanceID(), new Rect(200f,40f,500f,400f), DrawGui, "Window");
Debug.Log("Loaded");
}

void DrawGui(int windowID)
{
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("Hello World");
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
}

e98wX3K.png

Edited by ceauke
pic link
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...