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

4402393--400618--debug.png

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

2 Likes

Why don’t use use Unity in such case?
Or already existing c# parsers to Unity game, available on the asset store?

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.

1 Like

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.

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.

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#?

In lua, methods need to be bound with something like RegisterMethod or AddClass.
(lua-users wiki: Binding With Members And Methods)
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:

I’m already using Input, transform, Destroy, Resources.Load without any binding stuffs.

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

1 Like

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 :wink:

That’s correct! Thanks!

I spent vacations last week, dev progress was slowed down.
I’ve implemented LINQ, Lambda(partial) and Optimizers.

The most important part is I made two below tests pass (Merge and Quick sort snippets):

I think it is usable now, even there’re many undiscovered bugs and limitations.

I made a WebPlayground for a demo.

They don’t have much things to do for now, I’ll add some contents.

WASD to move, Right drag to rotate the camera.
Right click to inspect object.

Playground:
https://pjc0247.github.io/UniScript/uniplayground/

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.

2 Likes

Hi [pjccccc]( [WIP] UniScript - Yet Another C# Scripting for Unity members/pjccccc.953776/)! Are you still working on this?

1 Like

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