Jump to content

KSPedia Creation Tutorial


DMagic

Recommended Posts

4 minutes ago, DMagic said:

@micha Creating sprites at runtime is definitely expensive, but if done in Unity it's already taken care of by the time it's displayed in KSP.

I've done some more testing and while the filesize is definitely smaller with textures, the display of the images is less sharp than if you import the image as either "Editor GUI and Legacy GUI" or as "Sprite". Adding them as "Image" or "Raw Image" doesn't seem to make a difference here (although obviously if you use "Image" then you have to import as "Sprite").

But nothing I do seems to make the images properly sharp like in your KSPedia entries.
 

4 minutes ago, DMagic said:

For lines like these:

<snip>

I just do them in Photoshop with the the line tool. You can hold ctrl, or alt, or something to make them snap to 45o increments. They don't always come out perfect, if you look closely you can see the gaps between some of the segments, and it's also a pain because any time you need to move the text you have to move the lines around, too, but it works well enough for me.

Yes exactly :)

Hmm, ok, but how do you line them up with the text? I've had a look at your GitHub repo for the images and yeah, you just have the lines as part of your images, but that must have been a royal PITA to line up...?  I guess it is what it is..!

Link to comment
Share on other sites

On 06/09/2017 at 7:06 PM, DMagic said:

Keep in mind that this does not update any actual text changes in the final KSPedia entry. I think this is mentioned briefly in the tutorial.The Part Tools reads the actual text from an XML file in your Unity project folder (I'm not sure about the exact name or location of the file). The only way to update the XML file without going through the whole process with setting up the KSPedia pages is to manually update the text in the XML file.

<...>

It's possible that this is fixed in the 5.4 Part Tools.

I haven't worked out when it works and when it doesn't, but sometimes text changes are applied and other times not. It's very frustrating. And no, it's not fixed in the latest PartTools.

EDIT: Ok, so it looks like the following happens:

When you first create an entry in the KSPedia using the KSPedia tool, it sets up the information in the XML file, and copies any text into the XML.  But if you change text in an existing item, it does not get updated!

However; if you delete all the <text>...</text> tags out of the XML, it will now take the text directly from the prefab when re-generating the AssetBundle. Of course, this only applies for existing items; any new items have the same issue as above.

TL;DR: After adding any new entries using the KSPedia tool, open the kspedia XML file and delete all <text> tags out of it to ensure the text is taken directly from the prefabs.

 

On 18/11/2017 at 5:49 PM, micha said:

<...>
But nothing I do seems to make the images properly sharp like in your KSPedia entries.
<...>

Looks like my main issue has been not capturing sharp-enough images from the game itself. They looked fine in-game, but were horrible in the KSPedia.  I've since been paying more attention to the quality, and there's a particular zoom-level in-game where the textures suddenly "snap" into focus. My new captures have been at that zoom-level and they look much better in KSPedia.

So to re-cap, in my experimenting I've found that for the smallest KSPedia filesize and best image quality, you will want to import your images as "Editor GUI and Legacy UI", then add them to your prefab as "Raw Image". This can more than halve the final size compared to importing the images as Sprites, regardless of whether you then use the Sprite texture as a "Raw Image" or an "Image" in your prefab.  I've also got up to half-a-dozen or more separate images on a page instead of using DMagic's method of combining them all onto one big image. The benefit, apart from being able to freely re-arrange them in Unity, is that you can re-use them on other pages without them taking up more resources.

There may be benefits to doing it DMagic's way though; I haven't actually profiled the game while it's running.

Edited by micha
Link to comment
Share on other sites

  • 6 months later...

I recently discovered a simple way to modify KSPedia entries to add custom effects. Since these are all standard Unity components you can simply add any script to a KSPedia component and have it do whatever you want. It requires coding, but not necessarily anything complicated.

The example I have is of making a kind of simple GIF (I don't think actual GIFs are supported by Unity's image formats).

I make a KSPedia page in the standard way, add an image, then add a custom script to it that cycles through multiple images in a given time frame.

This is the total code required for this effect:


using System.Collections;
using UnityEngine;
using UnityEngine.UI;

namespace UniversalStorage.Unity
{
    [RequireComponent(typeof(Image))]
    public class KSPediaImageCycler : MonoBehaviour
    {
        [SerializeField]
        private Sprite[] m_Images = null;
        [SerializeField]
        private float m_Delay = 3;

        private Image _image;
        private Coroutine _cycler;
        private int _counter;

        private void Awake()
        {
            _image = GetComponent<Image>();
        }

        private void OnEnable()
        {
            if (_cycler != null)
                StopCoroutine(_cycler);

            _cycler = StartCoroutine(CycleImages());
        }

        private void OnDisable()
        {
            if (_cycler != null)
                StopCoroutine(_cycler);

            _cycler = null;
        }

        private IEnumerator CycleImages()
        {
            WaitForSeconds wait = new WaitForSeconds(m_Delay);

            while (gameObject.activeInHierarchy)
            {
                yield return wait;

                _counter++;

                if (_counter >= m_Images.Length)
                    _counter = 0;

                _image.sprite = m_Images[_counter];
            }

            _cycler = null;
        }
    }
}

This script has to be compiled and the plugin added to your Unity Assets/Plugins folder. This means that anything you want to add to KSPedia has to be done in a separate .dll assembly than what you might already be using for KSP, since anything referencing the KSP plugins can't be imported into Unity.

What you do is select the Image component that you want to use in your KSPedia page, then add this script to it, then add all of the files that you want to cycle through to the m_Images array. You can set the time between changes by setting a value for the m_Delay field:

Qj91O5k.png?1

 

Then make sure to add the plugin to your mod folder in KSP's GameData folder (if you don't the KSPedia page will still work, it just wont use any custom scripts you've added and the log file will complain). The result is this:

BM0Qfp2.gif

 

This could be expanded to do basically whatever you want within the limits of Unity. You could add things like buttons to make the page interactive, or even add a working copy of a UI if you really wanted to.

 

On 11/19/2017 at 2:04 PM, micha said:

So to re-cap, in my experimenting I've found that for the smallest KSPedia filesize and best image quality, you will want to import your images as "Editor GUI and Legacy UI", then add them to your prefab as "Raw Image". This can more than halve the final size compared to importing the images as Sprites, regardless of whether you then use the Sprite texture as a "Raw Image" or an "Image" in your prefab.  I've also got up to half-a-dozen or more separate images on a page instead of using DMagic's method of combining them all onto one big image. The benefit, apart from being able to freely re-arrange them in Unity, is that you can re-use them on other pages without them taking up more resources.

I haven't done any testing. But I think this may be due to texture compression, or the lack of compression, and textures with dimensions in powers of 2. When you add a sprite to Unity with a size that does not conform to a power of 2, a full size page of 2048*1536, for instance, it won't get compressed, or at least not to the same degree as a 2048*2048 texture. So maybe the best way is use separate textures for each image element and just make sure they are all powers of 2, probably 512*512 or 256*256 in most cases, and set compression to Normal or Low.

For this single test page I had four sprites of about 400*500 and I was getting a ~800kb .ksp file, when I changed them all to 512*512 the file size was reduced to ~200kb.

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...
6 hours ago, DMagic said:

@SnailsAttack You are using Unity 2018, you must use the version of Unity that matches the Part Tools, 2017.1 for KSP 1.4.

I downgraded my Unity version and it worked fine. Unfortunately, I suspect that making entries for my two dozen kopernicus planets is going to be a rather long process. Oh well. Thanks for your help!

Link to comment
Share on other sites

  • 8 months later...

Hello guys,

Not sure if I am doing something wrong, but i cannot build anything.
If followed the first steps in the tutorial and when i try to build use the asset compiler i get the following message:

TypeLoadException: Could not load type 'KSPFontAsset' from assembly 'KSPAssetCompiler, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'.
UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (BuildCallbacks findFlags) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:109)
UnityEditor.BuildPipeline:BuildAssetBundles(String, AssetBundleBuild[], BuildAssetBundleOptions, BuildTarget)
KSPAssets.Editor.AssetCompiler:BuildAssetBundles(Boolean, Boolean, String, String[])
KSPAssets.Editor.<BuildBundle>d__6:MoveNext()
KSPAssets.Editor.EditorUtil:UpdateCoroutine()
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Am I missing something or does more people get the problem?? I am using Unity 2017.1.3f1 as instructed with the PartTools.
I have tried everything with and without TMP added to the project, they give the same problem.

Also if I try to build the KSPFontAsset manually via Assets > KSP Fonts > Generate KSPFontAsset i get the following error:
FileNotFoundException: Could not load file or assembly 'TextMeshPro-2017.1-1.0.56-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Link to comment
Share on other sites

  • 5 months later...

@Nils277 Thanks for that. I was running into the same problem but decided to push it off until I sorted my other mods.

It would be nice if they could try to push all of the TMP stuff into a separate plugin so that we wouldn't have to deal with this nonsense.

Link to comment
Share on other sites

  • 1 year later...

Is this tutorial no longer accurate, and if so, where is a new one? I was linked to here, but I got stuck while trying to follow it - when I'm supposed to open the KSPedia Database, all I get is a completely blank gray rectangle with a label and close button.

Link to comment
Share on other sites

  • 4 months later...

Thank you very much for this! Using @Nils277 post and this one, it works in 1.11.x using Unity version 2019.2.2f1. Note to anyone reading this, make sure to constantly update and save both the KSPedia Database as well as the Asset Compiler to prevent any "Prefab not found" errors.

Link to comment
Share on other sites

  • 1 year later...
On 1/27/2021 at 1:18 AM, WarriorSabe said:

Is this tutorial no longer accurate, and if so, where is a new one? I was linked to here, but I got stuck while trying to follow it - when I'm supposed to open the KSPedia Database, all I get is a completely blank gray rectangle with a label and close button.

same issue for me. also @DMagicwasn't online for over 2 months now, so i don't think we get help soon!

Link to comment
Share on other sites

  • 6 months later...

A few corrections as of Unity 2019.4.18f1 (64-bit):

1.)

On 4/21/2016 at 11:11 AM, DMagic said:
  • In the Panel’s Rect Transform Component Window set the Width to 2048 and the Height to 1536 (you can change the sizes if you want to have a taller or wider page that can be scrolled through - Thanks @jandcando)
  • Click the Anchor Preset (the box with the grey squares and red cross, or blue arrows) and select Top-Left

Reverse these steps - Width and Height do not appear until the Anchor Preset has been changed to Top-Left.
 

2.)

On 4/21/2016 at 11:11 AM, DMagic said:

In the lower-right, below the Inspector Window is the Preview Window, at the bottom of this is a selection box labeled AssetBundle

In Unity 2019.4.18f1 (64-bit) this is untrue, see the post below for details on how to set the AssetBundle.

3.)
Final Gotcha for me...

Each text and image added to the page you are making requires an extra step to actually SHOW UP in KSP.

  • Right click the object you added and click Added GameObject->Apply to Prefab '...' to make the small + disappear. NOW it's actually added to the page!

S3pGYul.png

Edited by tg626
Link to comment
Share on other sites

  • 3 weeks later...

How to make two or more nesting levels?
The tool allows you to create only one level of nesting category - subcategory. It is not possible to add another level of nesting to the subcategory.
I need to get at least two levels of nesting. Something like this:

root: Main Title    
  1 lvl: Title1  
    2 lvl: Subtitle1
    2 lvl: Subtitle2
    2 lvl: Subtitle3
  1 lvl: Title2  
    2 lvl: Subtitle4
    2 lvl: Subtitle5
    2 lvl: Subtitle6

 

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