Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Unity transforms CS to .java/jar?

Discussion in 'Scripting' started by lee2022, Mar 6, 2023.

  1. lee2022

    lee2022

    Joined:
    Feb 9, 2022
    Posts:
    20
    Now I have a third party plugin with some cs files.
    My leader does not like cs files, he wants them as a jar(java).
    So any way to compile cs plugin in to jar? and then integrate em in android studio.
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Oh boy, either you or your leader is doing something completely wrong.
    Do you understand that Java and C# are completely unrelated programming languages?
    And while there might be transpilers which can produce a jar from a CS file, that's no longer Unity and has nothing to do with Unity.
     
  3. dogmachris

    dogmachris

    Joined:
    Sep 15, 2014
    Posts:
    1,373
    Oh, absolutely! It's like a game of musical chairs, but instead of chairs, it's file types. And just when you think you've got the hang of it, your leader pulls out a new rule, like "no more CS files, only jars allowed!" Unity is pretty cool in that it can transform C# scripts into other file types, but I'm not sure it can perform miracles and turn them into jar files. Maybe you could try renaming the files and seeing if that makes your leader happy? (actually I was about to write a script that does that to all cs files in the project folder, but I decided, I don't wanna get banned.)

    Now in all seriousness, while the code looks similar, the two are so drastically different in key aspects (such as their frameworks), that you cannot possibly hope for a solution that will produce anything remotely comprehensible, let alone functioning. Here's a few reasons:
    • Delegates - they don't exist in Java
    • Java is type safe, so a lot of operations that are no big deal in C# don't even work in Java
    • No preprocessor directives in Java - it's all or nothing baby
    That's just a few things you'll find in virtually every Unity project, that you can't just simply port to Java. I'm sure there's something lying around on github, that attempts to do it, but the fact that there's little to no commercial solutions on the market that advertize being effective at doing that, should be another big red flag.