Jump to content

Writing Plugins in UnityScript


Recommended Posts

Hey guys,

someone on the KerbalKon livestream was asking how to write a Plugin in UnityScript. And while not really relevant for most of us, this question is all but crazy. After all, KSP just needs a valid .net assembly that provides for example a class that implements PartModule. And all Unity does with UnityScript source is to compile it into a good old .NET dll called Assembly-UnityScript.dll, just like & next to Assembly-CSharp.dll.

So why should it be possible to write a plugin in VB.NET and C#, but not UnityScript? All we have to do is to find a way that transforms our UnityScript source files into a .net assembly without having an a real unity project associated. I haven't found a proper "unityscript dll" project type, but there is a "console project" that compiles without starting up unity. Yes, we don't want an executable assembly file, but they are basically identical to a library assembly file except also having an entry point. All we have to do is to rename the file!

Create plugin for KSP written in UnityScript in a nutshell:

- Install Unity

- Open MonoDevelop

- Create a new UnityScript Console Application

- Add dependencies just like you do when writing KSP plugins in other languages (UnityEngine.dll, Assembly-CSharp.dll)

- Ignore Main and start writing your code, for example:


class awesomeKspModule extends PartModule {
public function Update(){
for (var entry : ModuleEngines in this.part.FindModulesImplementing.<ModuleEngines>()) {
entry.throttleLocked = true;
entry.currentThrottle = 1;
entry.requestedThrottle = 1;
}
}
}

- compile it

- rename the .exe file into a .dll file and place it in your mods directory

- start up KSP and enjoy your mod!

There are a few drawbacks, though. Its not just that i am a C# guy and thus do not really benefit from UnityScript. But the language also seems kind of limited... for example i was not able to add an Attribute to a class. As a result, it might not be possible to create a part-less plugin using KSPAddon. Also MonoDevelop did not give me any autocompletion/intelisense for KSP/Unity stuff, just like the assemblies would not have been referenced. But someone more familiar with MonoDevelop might figure it out.

Link to comment
Share on other sites

I would not! I am fine with C#. But others might prefer UnityScript or any other language that is capable of compiling into a .net assembly, maybe in case they worked with it in various previous projects. Maybe a personal preference, and those guys don't have to be told it is impossible. I did use Monodevelop to write that UnityScript, btw.

Actually, UnityScript appears to offer some kind of dynamics that i think are not available to us in C#, since we have to target .net 3.5. So that's at least one other example, and i rly don't know lot about UnityScript.

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