Tencent / puerts

PUER(普洱) Typescript. Let's write your game in UE or Unity with TypeScript.
Other
5.04k stars 702 forks source link

[Unity] General Questions #1644

Open raad-genies opened 9 months ago

raad-genies commented 9 months ago

detail | 详细描述

Before diving into Puerts I'd like to see if someone can answer some questions I had:

Thank you for an awesome framework!

chexiongsheng commented 9 months ago

It partially supports C# generics, here is an example of a generic container: https://github.com/chexiongsheng/puerts_unity_demo/blob/master/projects/0_Basic_Demo/TsProj/QuickStart.mts#L57, and here is the logic for determining the scope of generic support: https://github.com/Tencent/puerts/blob/master/unity/Assets/core/upm/Runtime/Src/Default/Utils.cs#L183. Delegates are of course supported, you can still refer to https://github.com/chexiongsheng/puerts_unity_demo/blob/master/projects/0_Basic_Demo/TsProj/QuickStart.mts#L24 Due to some limitations under il2cpp, generics are not fully supported, and UniTask may not be fully usable. I suggest writing asynchronous logic in js, using async/await can also express asynchronous logic well.

raad-genies commented 9 months ago

@chexiongsheng thanks for answering! regarding the following:

chexiongsheng commented 9 months ago

From your questions, I think you need to systematically learn TS/JS first.

raad-genies commented 9 months ago

@chexiongsheng Thank you for answering my questions! definitely there's a lot to learn specially in the context of binding.

I'll rephrase my questions to convey my intent better. For context, my need is to expose my current APIs to a scripting language and I've been evaluating Puerts for that. The scripting side's job is to interact with my/unity's APIs to build using TS/JS. I do want to use a static wrapper as opposed to reflection as performance is important for us.

Again, thanks for taking the time to answer my questions, this gave me a better understanding of some limitations, and again, these questions are aimed to understand how C# is exposed on JS side and how Puerts worked through the limitations of JS regarding the features I asked about.

chexiongsheng commented 8 months ago

Instantiated generic classes that have been statically wrapped are usable, including il2cpp. If UniTask provides methods with the same name, same signature, and same semantics, it doesn't need to inherit from Task. Even if it doesn't provide such methods, any asynchronous operation with a completion callback and an optional error callback can be wrapped as a promise by similar way.