Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

I'm currently trying to get my head around the GUI stuff provided by the KSP API, and I've set myself the task of getting a small button icon working in the bottom left portion of the screen which opens and minimises the window when pressed. Like those you see with Chatterer and ISA MapSat.

Would someone be able to describe how to go about doing this or point me in the right direction? I've been trawling over the source code for both plugins but having a bit of trouble trying to understand it.

I don't really know the first thing about it, but the GUI is what I'm interested in as well. HyperEdit is a non-part plugin that uses the UnityEngine.GUILayout class to generate its buttons and whatnot. The new official repository for HyperEdit source code is here: https://github.com/swifthawk/hyperedit (see Window.cs for GUILayout stuff)

I hope this helps. Good luck! :)

Link to comment
Share on other sites

I don't really know the first thing about it, but the GUI is what I'm interested in as well. HyperEdit is a non-part plugin that uses the UnityEngine.GUILayout class to generate its buttons and whatnot. The new official repository for HyperEdit source code is here: https://github.com/swifthawk/hyperedit (see Window.cs for GUILayout stuff)

I hope this helps. Good luck! :)

Oh I'm okay with creating some of the buttons using the following:

m_dfltButtonStyle = new GUIStyle(HighLogic.Skin.button)

Does hyper edit use a similar feature to minimise the window or is it always visible? Never used it myself.

Link to comment
Share on other sites

Oh I'm okay with creating some of the buttons using the following:

m_dfltButtonStyle = new GUIStyle(HighLogic.Skin.button)

Does hyper edit use a similar feature to minimise the window or is it always visible? Never used it myself.

No, HyperEdit is activated by pressing Alt + h on the keyboard.

As for that code, I have no idea. I'm still very new to C# and Unity, and I'm not fluent in the code yet. But it should be easy to do what you want. If nothing else, you could trigger keystrokes like Alt + TAB or even the Windows key, on a button click. Just have the button load with the view instead of waiting for the hotkey (Alt + h). Suggestion: make the button drag-able, transparent, and persistent between restarts.

Link to comment
Share on other sites

How do I get the CelestialBody component of a GameObject (a planet)?

I'm trying this right now:

GameObject reference = GameObject.Find("Tylo");

GameObject newPlanet = (GameObject)GameObject.Instantiate(reference);

Component celestialComponent = newPlanet.GetComponent("Celestial Body");

CelestialBody celBody = (CelestialBody)celestialComponent.GetComponent("CelestialBody");

Unfortunately the last two lines do not seem to work.

EDIT:

The quote is showing "Ce lestialBody" for some reason but it's properly written on the code.

Link to comment
Share on other sites

The quote is showing "Ce lestialBody" for some reason but it's properly written on the code.

That may actually not be the forum here causing that; you may have some hidden or non-standard character in your code that is translating to a whitespace here. I highly recommend you find out what is causing that, as I strongly suspect that that is why it's not working for you. I could easily be wrong, but that's my hunch. << ["His hunches ARE good..."]

Link to comment
Share on other sites

I'm currently trying to get my head around the GUI stuff provided by the KSP API, and I've set myself the task of getting a small button icon working in the bottom left portion of the screen which opens and minimises the window when pressed. Like those you see with Chatterer and ISA MapSat.

Would someone be able to describe how to go about doing this or point me in the right direction? I've been trawling over the source code for both plugins but having a bit of trouble trying to understand it.

Here is how I created an icon like that: https://github.com/taraniselsu/TacLib/blob/master/Source/Icon.cs

It is used here: https://github.com/taraniselsu/TacFuelBalancer/blob/Release2.0/Source/FuelBalanceController.cs#L37

Link to comment
Share on other sites

How do I print the list of all the components of a GameObject?

I want to see all the components (Including the PQS mods) of a planet so I can learn how are they assembled.

I know how to print CelestialBody, OrbitDriver, OrbitRenderer and UnityEngine.Transform but I'm not sure where are the other ones.

Link to comment
Share on other sites

How do I print the list of all the components of a GameObject?

I want to see all the components (Including the PQS mods) of a planet so I can learn how are they assembled.

I know how to print CelestialBody, OrbitDriver, OrbitRenderer and UnityEngine.Transform but I'm not sure where are the other ones.

I don't know if there's a built-in function to do that, but you should be able to iterate through it's children. Did you check with Unity? http://Docs.Unity3d.com/Documentation/ScriptReference/GameObject.html

Link to comment
Share on other sites

I don't know if there's a built-in function to do that, but you should be able to iterate through it's children. Did you check with Unity? http://Docs.Unity3d.com/Documentation/ScriptReference/GameObject.html

I was looking for a snippet, I know I have to iterate through the children but Unity is so confusing.

If I try to get the children of CelestialBody I get the children of the GameObject instead and same for the other 3.

EDIT:

NVM, found it.

It looks like you have to iterate the transform, not the GameObject.

Edited by aftokinito
Link to comment
Share on other sites

I have a part in a vessel. How do I get the position of the part in relation to the vessel just like vessel.LocalCom or vessel.angularMomentum but for a part. I have been looking for this for well over two hour. Looked in the source code of some mods, the KSP.API. It seems so stupidly simple, but I just can't find it.

EDIT: The answer was given in the development thread of my mod by ZRM:

I work in the vessel.transform space. Just transform positions with vessel.transform.InverseTransformPoint and directions with vessel.transform.InverseTransformDirection. If you do this with both engine positions/directions, the COM and the user input via the vessel.ReferenceTransform (the command module reference frame), everything is in the same coordinate space for solving the system. If you really want everything in a constant frame, use vessel.ReferenceTransform.
Edited by PrivateFlip
Question Answered
Link to comment
Share on other sites

Does anyone know how the Space Center buildings are spawned? I know it's using PQSCity but I don't know the specifics behind it.

I honestly have no clue, just heard of Unity, and know almost no C#, but since you're still waiting for a reply, and I'm interested, I'm going to investigate. Don't expect much. :|

Link to comment
Share on other sites

How do I get the CelestialBody component of a GameObject (a planet)?

I'm trying this right now:

Use the generics version:

CelestialBody aCBComponent = planet.GetComponent<CelestialBody>();

How do I print the list of all the components of a GameObject?

I want to see all the components (Including the PQS mods) of a planet so I can learn how are they assembled.

I know how to print CelestialBody, OrbitDriver, OrbitRenderer and UnityEngine.Transform but I'm not sure where are the other ones.

They all derive from component, so you can use something like:


foreach(Component aComponent in aTransform.gameObject.GetComponents<Component>())
{
print(aComponent.GetType());
}

Does anyone know how the Space Center buildings are spawned? I know it's using PQSCity but I don't know the specifics behind it.

http://forum.kerbalspaceprogram.com/showthread.php/26858-Adding-new-buildings-runways

(easter egg spoilers):

http://forum.kerbalspaceprogram.com/showthread.php/28857-Space-Center-Game-Objects-%28WARNING-SPOILERS%29

Link to comment
Share on other sites

k i was lurking around for hours but didn't find an answer to my problem. i want to make a plugin which doesn't need any part to function and runs as soon as the game starts or as soon as a vessel is on the launchpad.

thx to anyone helping me with this

Link to comment
Share on other sites

ok. hi everyone.

i was lurking around since hours and still haven't found a solution to my problem.

basically i want to make a "plugin" that doesn't need a part with it. also it should run as soon as a vessel is on the launchpad.

thx for help

greetings LePwnerer

Link to comment
Share on other sites

Hi guys. I was wondering if anyone can help me out here. I've got an add-on that can be used gather samples from the various celestial bodies. I'm trying to make a change to the plugin so that the sampling unit deactivates when it finishes gathering samples, but what I've got at the moment doesn't seem to be working and I'm not sure why. If anyone can help me out, that would be great. :)

Here's an example of a bit of the code that is supposed to make it deactivate on filling up. (Unit capacity is 10)

case "Moho" :

if (this.part.RequestResource("MohoSamples", -1 * TimeWarp.deltaTime) != 10)

{

UnitActive = true;

}

else

{

UnitActive = false;

UnitStatus = "Unit Inactive";

SampleRequested = "Not Sampling";

}

this.part.RequestResource("ElectricCharge", 0.025 * TimeWarp.deltaTime);

break;

Link to comment
Share on other sites

RequestResource should return by which amount the resource level has changed, so if you want to check if the resource level hasn't yet reached the maximum, you should use > 0. Not sure about this, been a while since I touched the resource system for the last time.

Link to comment
Share on other sites

RequestResource should return by which amount the resource level has changed, so if you want to check if the resource level hasn't yet reached the maximum, you should use > 0. Not sure about this, been a while since I touched the resource system for the last time.

Ok, thanks. I'll try that. :)

Link to comment
Share on other sites

basically i want to make a "plugin" that doesn't need a part with it. also it should run as soon as a vessel is on the launchpad.

Use the [KSPAddon] attribute on a monobehaviour subclass, it does have arguments as to which scene it will run in - you probably want the flight scene.

Link to comment
Share on other sites

Can anyone post some example code on how to make a right click menu?

Maybe one that displays one line of information and a toggle? (e.g. activate button)

I went through a bunch of forums and googling and the wiki and couldn't seem to find any good examples.

Are there KSP classes to build these menus or is this done with unity? I figure I could probably figure out from the unity docs, but if there is a standard way I'd rather use it so that I can match the the look and feel of other KSP menus.

Link to comment
Share on other sites

The sticky explains it in detail, but basically the lines with buttons are methods tagged with the [KSPEvent] attribute and the lines without buttons are fields tagged with the KSPField attribute with the guiActive property set to true.

Link to comment
Share on other sites

The sticky explains it in detail, but basically the lines with buttons are methods tagged with the [KSPEvent] attribute and the lines without buttons are fields tagged with the KSPField attribute with the guiActive property set to true.

Thanks! I'll try that tonight.

Which sticky? Can you link it for me?

Link to comment
Share on other sites

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...