Jump to content

Info on how to convert your Plugin to KSP 1.1


Recommended Posts

1 hour ago, Agathorn said:

If you can make it a Prefab then yes should be doable.  Really it opens up some amazing doors.

 

I"ve got an AssetBundle exported, but can't seem to get it loaded into KSP.  It just keeps erroring saying it can't be found:

AssetLoader: Cannot find bundle definition with name 'TestFlight/AssetBundles/testflight'

 

I notice in Sarbian's original post he mentions the AssetBundle should have an extension of .ksp, but the one created by PartTools has no extension.  Not sure which is correct.  The error doesn't have an extension either so I assume the no extension is correct.

I've copied over both the AssetDatabase and the xml but no joy so far.

That doesn't make any sense.  I mean after all modders in KSP are only one step removed from just a normal Unity developer unless KSP itself is mucking around with things.

Even if it is harder from a code perspective, for me it is most likely worth it to be able to design NICE looking UIs using a proper editor.

From memory you simply add the .ksp extension to the file so KSP knows to load it - I think KSP uses a simple file filter to only load files with a .ksp extension as asset bundles so it doesnt try and load any old file inside gamedata as an assetbundle

 

 

Link to comment
Share on other sites

1 hour ago, stupid_chris said:

Don't think you understood what I meant. Creating UI is easy. Importing it in the game is easy. Interacting through code with this UI is on the verge of the not really possible. From what I got it only works in simple and specific cases, and is still a hell to set up.

Well, I just pushed the new GCMonitor version and it is 100% IMGUI free. I use pure code to create the small counter with the new UI and an AssetBundle to load the big window with the graph and buttons that I designed in the Unity Editor.

Link to comment
Share on other sites

Got my AssetBundle loading after adding the .ksp extension.  Thanks @TriggerAu.  I swear I tried that before but who knows.  It loads now.

My canvas isn't showing up, but i'm at least one step forward and just need to figure out how to work with it once loaded, so thanks @sarbian for the GCMonitor code, i'm sure that will help a lot.  Is your prefab just a Canvas and its children or is there more to it than that?

Link to comment
Share on other sites

Just now, Agathorn said:

Got my AssetBundle loading after adding the .ksp extension.  Thanks @TriggerAu.  I swear I tried that before but who knows.  It loads now.

My canvas isn't showing up, but i'm at least one step forward and just need to figure out how to work with it once loaded, so thanks @sarbian for the GCMonitor code, i'm sure that will help a lot.  Is your prefab just a Canvas and its children or is there more to it than that?

No, I use the stock game Canvas so my prefab is the gameObject under it. Here is my messy Unity Project. I need to clean it up but you should find what you need in the GCMonitor scene. 

Link to comment
Share on other sites

Can anyone help me find what I need to reference to get PartCategorizer working again? I'm referencing everything the OP said I should reference, but it still doesn't exist in the current context. Is there a whole new system for this, or am I just missing something?

Link to comment
Share on other sites

1 hour ago, sarbian said:

Well, I just pushed the new GCMonitor version and it is 100% IMGUI free. I use pure code to create the small counter with the new UI and an AssetBundle to load the big window with the graph and buttons that I designed in the Unity Editor.

Honestly if you could set up an in depth tutorial/guide for that it'd be amazing, because right now I'm getting a headache looking at that code

Link to comment
Share on other sites

I've spent some time writing up some UI helper classes while waiting for pre-release, and once you get the hang of it it is actually not that hard, but to simplify your main code you need to create at least 1 more abstraction layer for UI, like your own Window, Button, Text and other primitives. Once I get home from work I can try to arrange a github repo with all that I've come up thus far so everybody can help build a proper UI library for modders.

 

 

Link to comment
Share on other sites

32 minutes ago, stupid_chris said:

Honestly if you could set up an in depth tutorial/guide for that it'd be amazing, because right now I'm getting a headache looking at that code

This was the plan but RL got busy last week. I should have the time between now and Sunday.

In the mean time here are the useful entry point in that mess of a code :). It seems some of the comment & formatting I added to that code is gone. I had a crash so I guess I lost a few minutes of work...

  • The UI is loaded in Update when the AssetLoad is ready
  • The loading is done in UILoad where I get a reference to my bundle and start the loading (which is asynchronous)
  • UIInit is called when the loading is done and set up the UI.
    • I Instantiate the UI prefab
    • Attach it to KSP stock app Canvas
    • get references to the my prefab hierarchy my searching the name I used in Unity
    • set up the initial state and events

The overlay counters are created with code only in UICreateCounters if you want to have a look. We could create the whole interface that way but a better idea would be to create a bunch of helper class to make our life easier.

 

The main limitation of using the Unity Editor to create an UI is that you can not reference any of KSP graphic components and there are a few nice useful stuff in there :(. This is because they are in the game Assembly-CSharp.dll, which you can not load in Unity since it the same name as the one the editor create internally. I tried playing with Cecil but could not get something to work.

@Ziw that would be great. And yes, we need some basic prefab for button and such. The one I use for GCMonitor are plain bad looking :)

Edited by sarbian
Link to comment
Share on other sites

@sarbian I did not yet fiddle with prefabs, all I experimented with were some UI elements created and arranged (via AutoLayout) purely from code and some .png files for backgrounds and buttons. If we can get access to KSP's prefabs for some UI controls it would make a lot of things easier, as you won't need to create them from scratch.

 

Link to comment
Share on other sites

You will notice that MJ still use the old UI ;)   GCMonitor was a good place to experiment since the UI is neither too complex or too simple. To do more complex stuff we will need helper code and prefabs.

@ZiwThat s more or less what I need for MJ. You will notice that GCMon does that for the counters but the "new" UI is a bit messy to work with code and I often found myself with strange behavior with the layouts (I find their system not intuitive at all. I had far less problem building UI by code with Java Swing...)

Edited by sarbian
Link to comment
Share on other sites

Maybe it is too early in the morning for me, but is the actual used Unity version told anywhere for 1.1? so far I was not able to find it clearly written or logged anywhere, can someone help?

Link to comment
Share on other sites

6 minutes ago, Alewx said:

Maybe it is too early in the morning for me, but is the actual used Unity version told anywhere for 1.1? so far I was not able to find it clearly written or logged anywhere, can someone help?

In the OutputLog.txt first few lines. Unity 5.2.3f1

Edited by sarbian
Link to comment
Share on other sites

4 minutes ago, Alewx said:

Maybe it is too early in the morning for me, but is the actual used Unity version told anywhere for 1.1? so far I was not able to find it clearly written or logged anywhere, can someone help?

Tis in the log file on the first line for future ref

Its 5.2.4p1 

Link to comment
Share on other sites

I'm sorry to nag, but:

1 hour ago, jandcando said:

Can anyone help me find what I need to reference to get PartCategorizer working again? I'm referencing everything the OP said I should reference, but it still doesn't exist in the current context. Is there a whole new system for this, or am I just missing something?

Link to comment
Share on other sites

1 minute ago, TriggerAu said:

Tis in the log file on the first line for future ref

Its 5.2.4p1 

5.2.4f1***

I printed it to the log directly myself.

Just now, jandcando said:

I'm sorry to nag, but:

KSP.UI.Screens. Every UI reference is there now.

Link to comment
Share on other sites

 

4 minutes ago, jandcando said:

Ok it works now! You have my thanks.

If you are using VS. Get JetBrains Resharper. Resolves these references for you. :)

Edited by JPLRepo
Link to comment
Share on other sites

3 minutes ago, stupid_chris said:

Did you include a reference to Assembly-CSharp-firstpass.dll, as mentioned in the OP?

Of course :)

Spoiler

KsqNZtu.png

It's looks like class changed totally.

Spoiler

zoDqsh3.png

 

Edited by RangeMachine
Link to comment
Share on other sites

16 minutes ago, stupid_chris said:

5.2.4f1***

I printed it to the log directly myself.

KSP.UI.Screens. Every UI reference is there now.

Your right its f in the player - the f/p tells you what Unity license is being utilised so the key here is 5.2.4 patch 1 from memory

Edited by TriggerAu
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...