Jump to content

Adding new buildings/runways?


nothke

Recommended Posts


GameObject railHolder = new GameObject();
railHolder.name = "railHolder";
GameObject rail = PartReader.Read(KSPUtil.ApplicationRootPath, "model", ".mu");

rail.transform.parent = railHolder.transform;

foreach(Transform aTransform in vessel.mainBody.transform)
{
if(aTransform.name == vessel.mainBody.transform.name)
railHolder.transform.parent = aTransform;
}
PQSCity railScript = railHolder.AddComponent<PQSCity>();
railScript.debugOrientated = false;
railScript.frameDelta = 1;
railScript.lod = new PQSCity.LODRange[1];
railScript.lod[0] = new PQSCity.LODRange();
railScript.lod[0].isActive = true;
railScript.lod[0].visibleRange = 20000;
railScript.lod[0].renderers = new GameObject[1];
railScript.lod[0].renderers[0] = rail;
railScript.lod[0].objects = new GameObject[0];
railScript.modEnabled = true;
railScript.order = 100;
railScript.reorientFinalAngle = -105;
railScript.reorientInitialUp = Vector3.up;
railScript.reorientToSphere = true;
railScript.repositionRadial = (GameObject.Find("Runway").transform.position - vessel.mainBody.transform.position) + Vector3.up * 50 + Vector3.right * -350;
railScript.repositionRadiusOffset = 64.3;
railScript.repositionToSphere = true;
railScript.requirements = PQS.ModiferRequirements.Default;
railScript.sphere = vessel.mainBody.pqsController;

railScript.RebuildSphere();

That loads up a file called model.mu in the KSP root directory and puts it next to the runway (I was using a 1000m long rail to test, so a smaller object may be further down the runway). I was running it in public void OnPartUnpack(), haven't tried it in OnStart etc.

I'm not sure of the significance of all of the variables, the ones I don't understand I just copied from the KSC object, but here's a quick rundown:

railScript.lod[0].renderers

The GameObject/parent GameObject/array of GameObjects that comprise this feature.

railScript.reorientFinalAngle = -105;

railScript.reorientInitialUp = Vector3.up;

This controls the orientation of the item.

railScript.repositionRadial

The position on the planet's surface.

railScript.repositionRadiusOffset = 64.3;

The altitude.

railScript.sphere = vessel.mainBody.pqsController;

The planet it's attached to.

railScript.RebuildSphere();

This needs to be called to reflect any position changes.

Link to comment
Share on other sites

I'm not familiar with the unity version of MonoDevelop but you can't export it through unity - it needs to be compiled to a normal DLL and put in the plugin folder. If the unity version doesn't have that functionality stripped out then the basics of setting up a library/dll project in MonoDevelop are here: http://wiki.kerbalspaceprogram.com/wiki/Setting_up_MonoDevelop

Link to comment
Share on other sites

Ok, I've managed to get it working inside the PartModule and putting the name in cfg. But how do I make it part-independant? So that it shows up always without a part needed?

Link to comment
Share on other sites

Ok, this is difficult. Not really difficult but I don't know where to look.

Things I need are pretty simple, but I don't know how to script them:

1. I just need to get it to show up all the time.

2. I need to place it in on a coordinate. I see that you make an object in relation to the runway, but how to just write in the coordinates?

3. How to add multiple objects and not just one and to draw the model.mu for eg. from folders inside PluginData/Buildings?

Edited by nothke
Link to comment
Share on other sites

1. You're not editing the data files so you'll need to add it each time the flight scene is loaded. As I said I haven't experimented with it but you could try something like:

private bool done = false;

public void Update()

{

if(HighLogic.LoadedSceneIsFlight && done == false}

{

//Create buildings code here

done = true;

}

else if(!HighLogic.LoadedSceneIsFlight && done == true)

{

done = false;

}

}

2. Just write them in:

railScript.repositionRadial = new Vector3(x, y, z);

They are Cartesian & world co-ordinates so if you want to use spherical (i.e. latitude and longitude) you'll need to convert yourself.

3. Add to the path:

GameObject rail = PartReader.Read(KSPUtil.ApplicationRootPath + "Path/You/Want", "model", ".mu");

For multiple objects you either want to set them up as a hierarchy - assign them to a common parent GameObject (through transform.parent) - if they're in the same place (all of the KSC objects including the monolith have a common parent use a single PQSCity) or use multiple PQSCitys if they're widely seperated.

Edited by EndlessWaves
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...