Search Unity

  1. Unity 2020.1 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

Assets [WIP] UniScript - Yet Another C# Scripting for Unity

Discussion in 'Works In Progress' started by pjccccc, Apr 7, 2019.

  1. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43


    debug.png

    https://github.com/pjc0247/UniScript

    I'm working on script engine for my new game project.

    The game allows user to create their own stage just like rolobox.
    I don't have enough time to make a game creation tool, So planning to let users use Unity Editor.

    However, there're some limitation with previous script engines,
    * C# script cannot be run on iOS
    * other scripts can be run on iOS, but I have huge stuffs to do (binding & writing API doc for users)

    So my goal is
    * Running on iOS
    * Can execute all Unity's API except blocked by policy (API blacklist is supported by UniScript)
    * Some sandbox-like features such as timeout.

    This project is very early stage of dev, So may not be enough to use.
    Currently, I'm working on implementing more syntaxs and writing more and more tests.

    Thanks!!
     
    wahid_rachmawan and Aldo-V like this.
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,289
    Why don't use use Unity in such case?
    Or already existing c# parsers to Unity game, available on the asset store?
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,917
    IOS app store policy prevents dynamic dll's. And there is currently no way to correctly sandbox C#, it's too easy to get around.

    The only sane approach is an embedded dynamic language of some type, with access to well sanitized C# methods.
     
    Antypodish likes this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,289
    Right. But I know there was at least one C# embeded asset project, where code could be typed in a game within simple script editor and compiled real time like. That didn't requires any DLLs. Most likely players could save scripts in txt format. Or similar. Game could read them and compile at startup for example.
     
  5. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
    Actually, runtime compilation is prohibited by iOS, even not possible with IL2CPP. because they all rely on Reflection.Emit.
    So, the problem is not generating DLL or not.
    Every scripts MUST be interpreted.

    * There's only one C# script engine(maybe interpreter) named PaxScript which is not updated anymore. the last article was written in 2013.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,289
    What about lua? That would be more accessible to younger audience, and should work around such limitations. At least I think should ...
    Does it have to be C#?
     
  7. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
    In lua, methods need to be bound with something like `RegisterMethod` or `AddClass`.
    (http://lua-users.org/wiki/BindingWithMembersAndMethods)
    I have to provide hundreds of API for user modding and also documentations for each methods.

    With my script engine, you can call native Unity APIs directly, because it's already C# for both!

    Please see my messy test code from the repository:
    https://github.com/pjc0247/UniScript/blob/master/Assets/UniScript/Scripts/TestScript.cs

    I'm already using `Input`, `transform`, `Destroy`, `Resources.Load` without any binding stuffs.
     
  8. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
    I'm not sure C# is friendly for non-developers, but one clear thing is there're so many documentations, tutorials and StackOverflow questions for Unity/C#.

    I don't think Unity's documentations are good, but I can't do better than that as a personal developer
     
    Antypodish likes this.
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,289
    If your approach takes care for cross platform and works directly with most Unity APIs, that is good news.
    So far I can just wish you persistence and all best ;)
     
  10. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
    That's correct! Thanks!
     
  11. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
  12. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
  13. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    43
    Added an experimental feature(and the most interesting part, maybe)

    Migrate scene into an UniScript scene.
    Find all scripts from scene and converts each MonoBehaviours to UniFileScriptBehaviour.

    So, your scene can be exported as AssetBundle with scripts which is not possible in pure Unity.

    https://github.com/pjc0247/UniScrip...ript/Scripts/Migration/Editor/UniMigration.cs


    * Sorry, I can't explain it well. But it solves this problem:
    https://forum.unity.com/threads/including-scripts-in-assetbundles.459849/
     
    forestrf and wahid_rachmawan like this.
  14. paulbettner

    paulbettner

    Joined:
    Jan 13, 2014
    Posts:
    9
    Hi pjccccc! Are you still working on this?
     
    slimshader likes this.
  15. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    96
    Wow. This is crazy!
    The hot reloading feature is so good that makes me wonder, how's performance? Because if it's only somewhat slower, this is a game changer
     
unityunity