ialex32x / unity-jsb

It brings Javascript runtime capability to Unity3D by integrating QuickJS.
MIT License
337 stars 41 forks source link

Module '"UnityEngine"' has no exported member 'Rect'. #40

Closed lorenalexm closed 3 years ago

lorenalexm commented 3 years ago

I am attempting to create a new clean project to use unity-jsb within. After creating he new project within Unity Hub, I copied over the following files to the new project directory.

I did go through and clear the Scripts/src directory of all its files, leaving only the contents of the fairygui and plover folders. Following that, I ran the Generate Bindings and Type Definition from within the editor and created the following script within the source directory.

// Testing.ts
import { MonoBehaviour } from "UnityEngine";
import { ScriptString, ScriptType } from "./plover/editor/editor_decorators";

@ScriptType()
class Testing extends MonoBehaviour {
    @ScriptString()
    message = "Hello World"

    Awake() {
        console.log(`The message is: ${this.message}`)
    }
}

After which I ran npm install and tsc. Running the compiler presented with the following error messages about Rect not being an exported member.

❯ tsc Scripts/src/plover/editor/auto_completion_field.ts:8:93 - error TS2305: Module '"UnityEngine"' has no exported member 'Rect'.

8 import { Event, EventType, GUI, GUILayout, GUILayoutUtility, GUIStyle, GUIUtility, KeyCode, Rect, TextAnchor, Vector2 } from "UnityEngine";


Scripts/src/plover/editor/base/editor_window_base.ts:2:56 - error TS2305: Module '"UnityEngine"' has no exported member 'Rect'.

2 import { Event, EventType, GUI, GUIContent, GUILayout, Rect, Vector2 } from "UnityEngine";

Scripts/src/plover/editor/base/splitview.ts:2:40 - error TS2305: Module '"UnityEngine"' has no exported member 'Rect'.

2 import { Color, Event, EventType, GUI, Rect } from "UnityEngine";


Scripts/src/plover/editor/base/treenode.ts:2:95 - error TS2305: Module '"UnityEngine"' has no exported member 'Rect'.

2 import { Color, Event, EventType, FocusType, GUI, GUIContent, GUILayout, GUIUtility, KeyCode, Rect, Texture, Vector2, Vector3 } from "UnityEngine";

Scripts/src/plover/editor/base/treeview.ts:2:95 - error TS2305: Module '"UnityEngine"' has no exported member 'Rect'.

2 import { Color, Event, EventType, FocusType, GUI, GUIContent, GUILayout, GUIUtility, KeyCode, Rect, Texture, Vector2, Vector3 } from "UnityEngine";


Scripts/src/plover/editor/js_console.ts:2:65 - error TS2305: Module '"UnityEngine"' has no exported member 'Rect'.

2 import { Event, EventType, GUI, GUIContent, GUILayout, KeyCode, Rect } from "UnityEngine";

Found 6 errors.

Is there a step that I have completely overlooked here? The sample project seems to have ran just fine when from the cloned repository, but I cannot seem to make it work with a new project. Is there any guidance that could be provided? Thanks!

ialex32x commented 3 years ago

The type Rect is added in Assets\Examples\Source\Editor\CustomBinding.cs in this example project. You could add your own CustomBinidng class (it will be automatically executed when generating code and d.ts)

PS: I've also moved this type into UnityBinding.cs (it's for some commonly used unity types)

lorenalexm commented 3 years ago

Thank you for the prompt reply! I am away from my computer for the day, so it will be a bit before I can dig in and see about resolving my issue using the information you provided.

I do have a question about starting from a clean slate though. What all is required from this repo in a new project? What I am meaning, is if I am just wanting the most barebones setup to start from, are the files within the plover and fairygui truly required, or are they just there solely to support the samples and console that you have created?

Thank you again for your time!

ialex32x commented 3 years ago

My pleasure 😄 Yes, I see.

The only truely required files are Assets/jsb/**. And the files in Scripts/src/plover/** are optional if you do not need the default implementation of editor scripting (you could even implement it by yourself). All other files are scripts for demonstrating. (BTW, the tsconfig.json/package.json stuff are also required, but it could not be simply copied depending on different situation of you own project.)

I'll rearrange the files in a better structure, write more doc comments in the code and write some related notes in README later.

ialex32x commented 3 years ago

I've rearranged the scripts to make it easier to use in a new project. I'll do more further works for this purpose later.

You can do some customization in js-bridge.json (or directly in Prefs.cs). For a new project, you can let editorEntryPoint = "" and assetPostProcessors = empty list. (Maybe I'd rewrite the comments in the code later for better comprehension)

lorenalexm commented 3 years ago

I really appreciate the work you have, and continue to put into this project! I look forward to really being able to delve into things and see how far I am able to take it.

At this point I have added the Rect binding to the UnityBinding.cs file as you have done, and all seems to be working smoothly for me. So that should close this issue. Thank you again for your help, and I look forward to seeing the updates you have planned!