Jump to content

Help getting my first plugin to work.


Recommended Posts

As of right now it is only a print statement to make sure I have things working before i jump into making my plugin.

Here is what is in the output_log pertaining to my plugin.

Load(Assembly): Plugins/KSPChat

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

AssemblyLoader: Loading assembly at C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\Plugins\KSPChat.dll

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

AssemblyLoader: Loading assemblies

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

Non platform assembly: C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\Plugins\KSPChat.dll (this message is harmless)

VesselModules: Found 1 VesselModule types

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

Here is my code. (It is straight out of the wiki) Though I can't find the print statement anywhere in the log file in which the wiki says to look for.

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


using UnityEngine;


namespace KSPChat
{
public class ChatMod : PartModule
{
public override void OnStart(StartState state)
{
Debug.Log("KSPChat system test!");


}
}
}

Where am I going wrong? Do I need to create a Part cfg for a plugin that wont be using any thing other than gui?

Link to comment
Share on other sites

You probably didn't add that part module to any parts.

To add it to a stock nosecone (aerodynamic nosecone) using a module manager patch:

@PART[nosecone]
{
MODULE
{
name = ChatMod
}
}

Then, when you load into the flight scene, you'll get 1 message for each nosecone (Judging by the class name (if this is a serious plugin and not just a testing one) that behaviour may be unwanted)

Link to comment
Share on other sites

You probably didn't add that part module to any parts.

To add it to a stock nosecone (aerodynamic nosecone) using a module manager patch:

@PART[nosecone]
{
MODULE
{
name = ChatMod
}
}

Then, when you load into the flight scene, you'll get 1 message for each nosecone (Judging by the class name (if this is a serious plugin and not just a testing one) that behaviour may be unwanted)

Thanks for the help. I'll look into it tomorrow or this coming weekend. And Yes this will eventually be a serious plugin which I'll eventually have on all the screens of the game, well the ones when your actually playing. My friend, his roommate and I all play this game. Only difference is my friend didn't buy it from steam, his roommate and I did though. Be nice to have a little text chat instead of having to run skype or something else to talk to each other while playing.

Link to comment
Share on other sites

If you don't want your addon to be tied to a Part you need to use a KSPAddon. Be aware that OnStart is Start for a MonoBehaviour


using UnityEngine;

namespace KSPChat
{
[B][KSPAddon(KSPAddon.EveryScene, true)][/B]
public class ChatMod : [B]MonoBehaviour[/B]
{
public void [B]Start[/B]()
{
Debug.Log("KSPChat system test!");
}
}
}

Link to comment
Share on other sites

If you don't want your addon to be tied to a Part you need to use a KSPAddon. Be aware that OnStart is Start for a MonoBehaviour


using UnityEngine;

namespace KSPChat
{
[B][KSPAddon(KSPAddon.EveryScene, true)][/B]
public class ChatMod : [B]MonoBehaviour[/B]
{
public void [B]Start[/B]()
{
Debug.Log("KSPChat system test!");
}
}
}

Thanks for the help. Only thing I needed to change was to add Startup between KSPAddon and EveryScene. I'll be testing it here in a moment. Though after I get it all loaded up and actually printing to the debug console, will I need to change it back to PartModule one I start to implement a gui system? Or will this way allow to draw as well? Sorry for all the questions, I tried to follow the wiki and got lost.

Link to comment
Share on other sites

The KSPAddon system is used for "single instance" plugins. Part Modules have a few extra functions (the ones starting with "On". eg. OnStart) and run an instance per part module (normally one per part, but you can have multiple of the same module on a part). All plugin classes have access to the MonoBehaviour functions Awake/Start/Update/FixedUpdate/OnGUI/etc. so you will have no issues with your GUI in a KSP Addon type plugin, and you will automatically have a plugin that only runs once per scene and always does so.

Link to comment
Share on other sites

I hate to double post. Though as this still pertains to my first plugin, I'm hoping its okay.

I built the gui and everything is going good. My only issue is that I can't figure out how to capture inputting text. I've been looking that API and the wiki and haven't really found anything. Along with searching the forums. I may have over looked something. Here is what I have so far. Connects to server, able to send the current text just fine. Just need some direction on changing the current text.

/*Programmer: JR Padfield
Description: Simple multiplayer chat plugin
Version: 1
Date: 08/20/2015
*/
using Lidgren.Network;
using UnityEngine;


namespace KSPChat
{
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class ChatMod : MonoBehaviour
{


string currentText = "Press Enter to chat";
double currentValue = 10.0;


private Rect windowPostion = new Rect();
private Vector2 scrollPostion;


public void Start()
{
RenderingManager.AddToPostDrawQueue(0, OnDraw);
// Lets initiate the network.
NetworkManager.Instance.InitNetwork();
}


public void Update()
{
NetIncomingMessage im;
im = NetworkManager.Instance.client.ReadMessage();


if (im != null)
{
// lets handle the message and update the text in a text box area.
switch (im.MessageType)
{
case NetIncomingMessageType.DiscoveryResponse:
NetworkManager.Instance.client.Connect(im.SenderEndPoint); break;
case NetIncomingMessageType.Data:
HandleTCP.Instance.HandleData(im);
break;
case NetIncomingMessageType.StatusChanged:
if ((NetConnectionStatus)NetworkManager.Instance.client.ConnectionStatus == NetConnectionStatus.Disconnected)
{
// TODO: Figure out what to do here.
}
break;
default:
break;
}
}
}


private void OnDraw()
{
windowPostion = GUILayout.Window(10, windowPostion, OnWindow, "KSP Chat Program: Made by The Crzy Doctor");
}


private void OnWindow(int windowId)
{
scrollPostion = GUILayout.BeginScrollView(scrollPostion, GUILayout.Width(400f), GUILayout.Height(200f));
GUILayout.BeginHorizontal(GUILayout.Width(400f));
HandleTCP.Instance.chatText = GUILayout.TextArea(HandleTCP.Instance.chatText);
GUILayout.EndHorizontal();
GUILayout.EndScrollView();
GUILayout.BeginVertical(GUILayout.Height(2f));
GUILayout.EndVertical();
GUILayout.BeginHorizontal(GUILayout.Width(400f));
this.currentText = GUILayout.TextField(currentText);
if(GUILayout.Button("Send Text"))
{
NetworkManager.Instance.sendChat(currentText);
}
GUILayout.EndHorizontal();


GUI.DragWindow();
}



}
}

Link to comment
Share on other sites

  • 1 month later...

I assume you mean changing the content of your text field for "currentText"? The way most changeable GUILayouts work is you pass in the current value and it returns the revised values (which may be the same as the current value). The current value you pass in can be changed by anything.

Example if you want to clear the text after sending:


this.currentText = GUILayout.TextField(currentText);
if(GUILayout.Button("Send Text"))
{
NetworkManager.Instance.sendChat(currentText);
[COLOR=#ff0000]this.currentText = "";[/COLOR]
}

If on the other hand you want to know if the contents have changed. The easiest way is to compare to the previous value.


string tempText = GUILayout.TextField(currentText);
if (tempText != currentText)
{
currentText = tempText;
doSomethingWithChangedText(tempText);
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...