Sign in to follow this  
Stainless

Unity C# and Java interop

Recommended Posts

This is a bit of a long post, but I want you to understand why I am doing what I am doing. The why affects the what... if you see what I mean.

 

A few years ago I needed some meshes for a technology demo. It was for internal use only, so I wasn't really bothered about copyright issues.

 

I found this website http://www.sas1946.com/main/index.php

 

It had exactly what I needed. The meshes were in a strange format, but I quickly reverse engineered the format and wrote an importer and knocked the demo out.

 

Even though the public never saw the demo, I still  felt  I owed the guys something, so I used the knowledge I had gained in the demo to write them a tool that displayed meshes without having to jump through hoops and actually get it in the game.

 

It was well received and over time has suffered from feature creep. You can now use it to test weapon loadouts, particle emitters, animation, and a thousand other things.

 

The last main job I want to do is extend the tool to create the basic files needed to actually get a mod into the game.

 

The way the game works is you have a core engine written in C++, hidden away inside the game. It calls out to Java class files for aircraft specific data.

 

For example it will call moveElevator(float f)  on the Java class for an aircraft every time the elevator position changes. It is the Java classes responsibility to reflect this in the visual mesh.

 

This means that the modding community is polarised into two groups. Those who can code Java, and those that can't.

 

It must be incredibly frustrating for the 3D artists to spend months researching and creating a mesh for an aircraft and then have to wait for some kind person to write the java code you need to actually fly it in the game.

 

I want to remove that frustration.

 

On the face of it, it should be an easy task. I create a wizard that walks them through the process, a gui to display what they have done, and a bit of code to output it as Java.

 

However that's not enough for me. I want to make it really easy to use.

 

Has anyone come across a way of invoking Java classes from C#?

 

What I want to do is build a jar file with all the current aircraft compiled and ready in it. Then query this jar file from C#.

 

This will allow me to give the end user a list of existing aircraft. They can then start by basing their new mod on an existing aircraft.

 

In java it would be

class SPITFIRE2b extends SPITFIRE

In a lot of cases this would be enough to get the aircraft into the game and test it. Later the files could be edited by someone who knows what they are doing to really make this aircraft more than just visually different from the existing one.

 

I also want to allow the end user to be able to select an aircraft type from a list extracted from the jar files.

 

Once again in Java this would be

class SPITFIRE2b extends SPITFIRE implements TypeFighter

Then I want to be able to allow the end user to tweak values and test.

 

This means that I will need to be able to call methods on the Java class and have the java class call methods in a C# class.

 

Has any one tried this before?

 

Any good examples I can study?

 

Cheers guys, and sorry for the long post

 

Share this post


Link to post
Share on other sites

Perhaps something like: http://www.prodigyproductionsllc.com/articles/programming/decompile-java-using-c/

 

or https://msdn.microsoft.com/en-us/library/y9teabc2%28VS.80%29.aspx

 

Maybe one of those potential ideas will help you.

 

Also if I remember correctly jar files are really just zip files. You can "extract" the jar file and look at the class files inside of it... I don't know if you will be able to do much with the class files but if you extract the jar file to a temp directory and then iterate through the files you should be able to determine the names of things potentially.

Edited by shadowisadog

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this