Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED]Scripting with actual JavaScript!

Discussion in 'Scripting' started by answerwinner, Jan 8, 2015.

  1. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Description
    • JSBinding is a tool enabling you to run actual javascript in Unity3D. It contains Mozilla SpiderMonkey JavaScript engine version 33 library.
    • JSBinding's target users are people who would like to develop Unity applications with existing or writing javascripts or to use javascript to do anything else.
    • It's very easy for javascript and c# to interact with each other. Unity's script serialization, GameObject->Components relationship are specially supported.
    • Memory management is a tough stuff because javascript and c# both have garbage collection. JSBinding has overcame it. Users don't need to do any work.
    • The package contains full source code! Feel free to customize you own needs!
    • Does JSBinding need Unity Pro? Unity 4 documents say using native dll is pro/mobile-only feature, but Unity 5 documents don't.
    >> See Online Documents for more information!
    >> Asset store link https://www.assetstore.unity3d.com/#!/content/25497
    >> Download sample executable

    Try to modify some javascript! Add this line somewhere you like:
    Code (CSharp):
    1. print("hello, jsb!");
    • for Windows, javascript files are located at
    • for Mac OS, javascript files are located at
    Features
    • Simply config c# types you need and with a single click, c# classes are available in javascript!
    • Full calling stack will be printed out whenever error occurs in JavaScript or C#.
    • Support Unity serialization: int(i), string(s), double(f), UnityEngine.Object(o), JavaScript MonoBehaviour(k)
    • Almost all c# methods are available in javascript:
    >> struct/class
    >> instance variables/methods
    >> static variables/methods
    >> properties
    >> generic methods/parameters
    >> ref/out
    >> delegate
    >> array
    >> overloaded methods
    >> indexers
    >> operators
    >> even COROUTINE

    Supported Platforms
    • Windows Editor (32 and 64)
    • Windows Executable (32 and 64)
    • Mac OS X Editor (32 and 64)
    • Mac OS X Executable (32 and 64)
    • Android (armv7a)
    • iOS (32 and 64, works great with IL2CPP)

    Email: answerwinner@gmail.com
    >> Online Documents

    Screen Shots
    -----------------------------------------------

    -----------------------------------------------

    -----------------------------------------------



    -----------------------------------------------

    -----------------------------------------------

     
    Last edited: Jul 16, 2016
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,264
    This is pretty cool. If you're making an interactive website, and want to put Unity apps in it, you don't have to have two different code bases.
     
  3. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Yeah, you are right. by exporting all classes you need in c#, all you have to deal with is actual JavaScript and Unity Editor. Let's say bye-bye to c# :D.
     
  4. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Is it too cheap so people don't believe it can provide good functions?
    OR
    no one is interested...
    OR
    should I make it free?
     
    twobob likes this.
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,264
    You're aiming at a very narrow group - someone who wants to make games with Unity, and would prefer vanilla Javascript to C# or boo. Which is probably not a lot of people.

    I'm not sure how to break this to you, but here goes: Javascript is a horrible, horrible language. It's very widespread because it works in the browser, but it's still crazy bad at doing stuff that's not strictly browser stuff. The tool is really, really cool, but it's based on the assumption that developers would want to write Javascript - the ECMAscript version - over C#. That's probably not that many people.
     
    lordofduct, BenZed, kdub and 3 others like this.
  6. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    645
    I agree with what Baste has said. Maybe years ago this would be more sought after, but most have already shifted away from the JavaScript paradigm in exchange for C#.
     
  7. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    ok, i got it.
    for now, may be it can be used to make tools, modify something during run-time, etc.
     
    twobob likes this.
  8. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    This plugin has been updated to version 1.2.0. (Feb 18,2015)
     
  9. Jacksendary

    Jacksendary

    Joined:
    Jan 31, 2012
    Posts:
    407
    Not bad, not a huge fan of javascript nor have I ever really used it much. Still believe C#, C++ or Java is superior, but if it works I guess some out there will find it use full... One thing that would impress me is if it actually works with other javascript libraries (node.js for instance?) and if it do how do you exactly communicate with the MONO.NET unity API? Having a hard time seeing how that would work?
     
  10. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    @jackie0100

    If you are familiar with LUA Binding (cocos2d-x) or other JS Binding, this plugin does the same thing. Only one difference: This plugin works with C#, most of the 'bindings' works with C/C++.

    1. This plugin uses Mozilla SpiderMonkey JavaScript engine. It supports standard ECMAScript. (So it doesn't support node.js because node.js is based on Google V8?)
    2.
    Most of classes and functions are supported, some syntax are not supported, for example:
    (JS->CS) Generic Functions, (e.g. gameObject.AddComponent<CharacterController>();), but most of them have overloaded functions to use.(e.g. gameObject.AddComponent("CharacterController");)
    (JS->CS) Functions with complex parameters, such as Dictionary<int, string>. Users almost don't need it, and it is not high-efficient.

    For parameters of basic types, (string, int, float, double), they are correctly converted.

    It's easy to use.
    When you call C# functions from js, you write js code as if it the functions were implemented in js.
    Code (csharp):
    1.  
    2. var go = new GameObject("i love you"); // js code, exactly the same with c#
    3. Physics.Raycast(Input.mousePosition);
    4.  
    Some syntax are supported in js, but a little inconvenient:
    Code (csharp):
    1.  
    2. // C#
    3. Vector3 v = v1 + v2;
    4. // JS
    5. var v = Vector3.op_Addition(v1, v2);
    6.  
    Generally, you don't have to care about the generator code, only take care of the generated code.

    ----------------------------------------------------
    Edit (2016 July 13)
    Text above is old comments.
     
    Last edited: Jul 13, 2016
  11. Jacksendary

    Jacksendary

    Joined:
    Jan 31, 2012
    Posts:
    407
    I see, I'm not much into language design and such but sound pretty interesting, probably not the plugin for me tho, as I do think C# give better flexibility , would love to be able to use C++ with Unity3D (as natively supported language - not as a plugin or with DLLImport), but Good luck with it there sure must be some javascripts fans that can use this! :)
     
  12. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    back here again, some news. :).

    I am still working on this plugin. It changes a lot now.
    In next new version, it will enable you develop your game with C# as usual.
    After you've finished your game, It can automatically convert C# to actual JavaScript with the help of SharpKit.net.

    Why do we do this? Because it's not possible to update Unity C# scripts when releasing new version. But it's OK to update JavaScript files. Update them just like you update models, textures.

    Will you be interested?

    -----------------------------------------------------------------
    Edit (2016 July 13)
    This package no longer uses SharpKit to compile c# to javascript. It just let you write javascript.
     
    Last edited: Jul 13, 2016
  13. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    13,353
    Wouldn't that make your game exceptionally hackable? And stealable?

    The question here is, what problems are you trying to solve?
     
  14. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    @angrypenguin

    You can encrypt you js files.

    On iOS, each time you have new contents(scritps), users are required to re-download the whole game because it's not possible to update scripts. But if scripts are translated to JS, they become normal assets and can be delta updated.
     
    LykenTech likes this.
  15. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    13,353
    Ok, but what problem does that solve? Why is not being able to delta update a bad thing?

    Furthermore, is that in line with Apple's TOS and the App Store rules?
     
    twobob likes this.
  16. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,779
    What, you expect actual market research before sinking time into developing an asset? I have no time for this. :)
     
  17. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    @angrypenguin

    It's not a bad thing, but if you have to update your game frequently, waiting for Apple to approve is a waste of time.

    Apple does not clearly say that SpiderMonkey js engine is allowed (as far as I know), but the js-version of cocos2d-x (http://cocos2d-x.org/) already did this. If .. i said if, this is plugin is declined by Apple, you are still able to use C# version.


    -----------------------------------------------------------------
    Edit (2016 July 13)
    This package no longer uses SharpKit to compile c# to javascript. It just let you write javascript.
     
    Last edited: Jul 13, 2016
  18. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    13,353
    I do know there are cases where this has been treated with... extreme lenience. However, none of those cases were people doing it specifically to avoid the app review guidelines for updates.

    Edit: My point isn't to shoot it down, in any case. I can imagine at least one case where this would come in handy, which is porting something that's already written in JavaScript. Another could be making apps where the whole point is that the user can program things.
     
  19. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Most users of cocos2d-x would choose LUA or JS as main developing language. If Apple reject these engines, they have to totally rewrite the code.

    This plugin is just an option. :)
     
  20. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Version 1.5.0 has been released.
    It is expected to work with SharpKit (sharpkit.net)


    -----------------------------------------------------------------
    Edit (2016 July 13)
    This package no longer uses SharpKit to compile c# to javascript. It just let you write javascript.
     
    Last edited: Jul 13, 2016
  21. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Out of curiosity, what is the performance impact of using your plugin?

    I'm imagining runtime javascript interpretation for all of the games logic is going to be quite a bit slower than IL.
     
  22. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    @BenZed
    It's certainly slower than IL, but I can't tell how much.
    Generally it's not recommended to use this plugin for MMORPG, or other games with massive calculation.
    It's OK for casual games.

    And lots of optimizations has be used for reducing interaction between C# and JavaScript. For example, 90% methods of Vector3 is implemented by hand in JavaScript.
     
  23. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Back here again, some news. :).
    Version 2.0 is coming. I've edited first post.

    You can ask me any questions here...even if you are not interested at all.
     
  24. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,779
    Been a year since release. Any games actually using it in production?
     
  25. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    @BoredMormon
    Good question!
    As far as I know, at least 5 companies are using this package in their product. They use SharpKit to compile c# to javascript. They are all still developing. One of them will publish their product soon.

    I've found that most people would't choose to use SharpKit compiler, so this package doesn't ship SharpKit compiler anymore.
     
  26. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    The package has been accepted and is shown on asset store.
     
  27. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    One product has been published to App Store!
     
  28. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    it's FREE now.
     
    twobob likes this.
  29. mhuyle

    mhuyle

    Joined:
    Jul 26, 2016
    Posts:
    4
    Any problems with app submission as of late? I know Apple has been getting stricter. Are you still considering making this free?
     
  30. sat12341234

    sat12341234

    Joined:
    Jan 7, 2013
    Posts:
    1
    Hi,

    I just bought this package and wondering if there is a very simple javascript applications? I have a simple html page that loads a D3.js diagram.

    Thanks
    sam
     
  31. freesun

    freesun

    Joined:
    Jan 3, 2017
    Posts:
    2
    hi, @answerwang, It's a very interesting plugin. About the performance, the React Native allowed call native code using js too, but with high performance. Maybe you can have some research about it, it's open source.
     
  32. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    JSBinding is different, it's desinged to call c# from javascript.
     
  33. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    Yes it's free now.
     
    twobob likes this.
  34. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    There is a 2048 game inside the package.
    But JSBinding doesn't analyze(parse) any html marks. It only supports javascript syntax.
     
  35. horeaper

    horeaper

    Joined:
    Oct 30, 2013
    Posts:
    28
    请问会不会有Linux支持?我们现在在做一个游戏,准备支持SteamOS,如果能支持Linux就太好啦!
     
  36. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    改起来不难就是了,但是没有这个计划。用的人太少了。
     
  37. Ninh

    Ninh

    Joined:
    Aug 6, 2013
    Posts:
    5
    I'm trying to load a textures from asset bundle as a var but still not find how to do it. could u help me. thanks
     
  38. answerwinner

    answerwinner

    Joined:
    Jan 8, 2015
    Posts:
    47
    @Ninh
    Did you follow steps documents said?
     
  39. Ninh

    Ninh

    Joined:
    Aug 6, 2013
    Posts:
    5
    I still not find Documents about AssetBundle and in example dont use assetbundle, can you share me the link of it.
    Thanks
     
unityunity