Convert Figma logo to code with AI

Tencent logopuerts

PUER(普洱) Typescript. Let's write your game in UE or Unity with TypeScript.

5,133
717
5,133
245

Top Related Projects

A framework for building native Windows apps with React.

A framework for building native applications using React

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.

90,206

Godot Engine – Multi-platform 2D and 3D game engine

Kotlin/Native infrastructure

Quick Overview

Puerts is a cross-platform JavaScript/TypeScript integration solution that allows developers to use JavaScript/TypeScript in C++ and C# projects. It provides a seamless way to bridge the gap between native and scripting languages, enabling developers to leverage the strengths of both.

Pros

  • Cross-platform Compatibility: Puerts supports multiple platforms, including Windows, macOS, and Linux, making it a versatile choice for developers working on diverse projects.
  • TypeScript Support: Puerts fully supports TypeScript, allowing developers to leverage the benefits of static typing and improved tooling.
  • Performance Optimization: Puerts is designed for performance, with features like asynchronous function calls and efficient memory management.
  • Extensive Documentation: The project has comprehensive documentation, including tutorials, API references, and examples, making it easier for developers to get started and integrate Puerts into their projects.

Cons

  • Learning Curve: Integrating Puerts into an existing project may require a significant learning curve, especially for developers unfamiliar with the concept of bridging native and scripting languages.
  • Dependency on Specific Frameworks: Puerts is primarily designed to work with Unity and Unreal Engine, which may limit its applicability for developers working with other game engines or native applications.
  • Limited Community: Compared to more established JavaScript/TypeScript frameworks, the Puerts community is relatively small, which could make it harder to find support and resources.
  • Potential Performance Overhead: While Puerts is designed for performance, there may be some overhead associated with the language bridging, which could be a concern for highly performance-critical applications.

Code Examples

Example 1: Calling a C++ Function from TypeScript

import * as csharp from 'csharp';

// Call a C++ function
const result = csharp.Puerts.TestClass.Add(1, 2);
console.log(result); // Output: 3

This example demonstrates how to call a C++ function from TypeScript using the csharp module provided by Puerts.

Example 2: Exposing a TypeScript Class to C++

import * as csharp from 'csharp';

class MyClass extends csharp.Puerts.TestClass {
  public Add(a: number, b: number): number {
    return a + b;
  }
}

// Register the TypeScript class with C++
csharp.Puerts.TestClass.Register(MyClass);

This example shows how to expose a TypeScript class to C++ by extending a C++ class and registering the TypeScript class with Puerts.

Example 3: Asynchronous Function Calls

import * as csharp from 'csharp';

async function callAsyncCppFunction() {
  const result = await csharp.Puerts.TestClass.DoSomethingAsync();
  console.log(result);
}

callAsyncCppFunction();

This example demonstrates how to call an asynchronous C++ function from TypeScript using the await keyword.

Getting Started

To get started with Puerts, follow these steps:

  1. Install the Puerts package in your project:

    • For Unity, you can install the package from the Unity Package Manager.
    • For Unreal Engine, you can download the Puerts plugin from the Puerts GitHub repository.
  2. Create a new TypeScript file in your project and import the necessary Puerts modules:

    import * as csharp from 'csharp';
    
  3. Expose your C++ or C# functions and classes to TypeScript by using the Puerts API:

    // Expose a C++ function
    csharp.Puerts.TestClass.Register(
      'Add',
      (a: number, b: number) => csharp.Puerts.TestClass.Add(a, b)
    );
    
    // Expose a C# class
    csharp.Puerts.TestClass.Register(MyClass);
    
  4. Call the exposed functions and use the exposed classes from your TypeScript code:

    const result = csharp.Puerts.TestClass.Ad
    

Competitor Comparisons

A framework for building native Windows apps with React.

Pros of react-native-windows

  • Specifically designed for Windows platform, offering native UI components and APIs
  • Backed by Microsoft, ensuring long-term support and integration with Windows ecosystem
  • Large community and extensive documentation for Windows-specific development

Cons of react-native-windows

  • Limited to Windows platform, lacking cross-platform versatility
  • Steeper learning curve for developers not familiar with Windows development
  • May have performance overhead compared to native C++ development

Code Comparison

react-native-windows:

import { Text, View } from 'react-native';
import { Button } from 'react-native-windows';

const App = () => (
  <View>
    <Text>Hello, Windows!</Text>
    <Button content="Click me" />
  </View>
);

puerts:

import * as UE from 'ue'

class MyActor extends UE.Actor {
    ReceiveBeginPlay(): void {
        console.log("Hello, Unreal Engine!");
    }
}

puerts.register(MyActor);

Key Differences

  • react-native-windows focuses on building Windows applications using React Native
  • puerts enables TypeScript/JavaScript development in Unreal Engine
  • react-native-windows uses JSX for UI components, while puerts interacts with Unreal Engine's C++ API
  • puerts offers broader game engine integration, while react-native-windows is tailored for Windows app development

A framework for building native applications using React

Pros of React Native

  • Larger community and ecosystem, with more resources and third-party libraries
  • Cross-platform development for iOS and Android with a single codebase
  • Hot reloading for faster development and testing

Cons of React Native

  • Steeper learning curve for developers new to React or mobile development
  • Performance can be slower compared to native development, especially for complex apps
  • Requires frequent updates to keep up with changes in iOS and Android platforms

Code Comparison

React Native:

import React from 'react';
import { View, Text } from 'react-native';

const App = () => (
  <View>
    <Text>Hello, React Native!</Text>
  </View>
);

PuerTS:

import * as UE from 'ue'

class MyActor extends UE.Actor {
    ReceiveBeginPlay(): void {
        console.log("Hello, PuerTS!");
    }
}

PuerTS focuses on integrating TypeScript with Unreal Engine, while React Native is a framework for building mobile applications using React. The code examples showcase their different use cases and syntax, with React Native using JSX for UI components and PuerTS utilizing TypeScript for game development in Unreal Engine.

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.

Pros of cocos-engine

  • Comprehensive game development framework with a rich set of tools and features
  • Large and active community, providing extensive resources and support
  • Cross-platform compatibility, allowing developers to target multiple platforms easily

Cons of cocos-engine

  • Steeper learning curve due to its extensive feature set
  • Potentially heavier resource usage compared to lightweight solutions
  • May be overkill for simple projects or those not requiring a full game engine

Code Comparison

cocos-engine:

import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('HelloWorld')
export class HelloWorld extends Component {
    start() {
        console.log('Hello, Cocos Creator!');
    }
}

puerts:

import { FString, Actor } from 'ue'

class HelloWorld extends Actor {
    Constructor() {
        this.PrimaryActorTick.bCanEverTick = true;
    }

    ReceiveBeginPlay() {
        console.log('Hello, Puerts!');
    }
}

The code snippets demonstrate basic setup and logging in both frameworks. cocos-engine uses decorators and a component-based approach, while puerts integrates more closely with Unreal Engine's actor system.

90,206

Godot Engine – Multi-platform 2D and 3D game engine

Pros of Godot

  • Complete game engine with built-in editor, rendering, physics, and more
  • Large, active community with extensive documentation and tutorials
  • Cross-platform support for multiple desktop and mobile platforms

Cons of Godot

  • Steeper learning curve for developers new to game development
  • Less flexible for integrating with existing C++ codebases
  • Performance may be lower compared to native C++ engines for complex games

Code Comparison

Godot (GDScript):

extends Node2D

func _ready():
    print("Hello, Godot!")

func _process(delta):
    position += Vector2(1, 0) * delta

PuerTS (TypeScript):

import * as UE from 'ue'

class MyActor extends UE.Actor {
    BeginPlay(): void {
        console.log("Hello, PuerTS!");
    }

    Tick(DeltaSeconds: number): void {
        this.AddActorWorldOffset(new UE.Vector(100, 0, 0).Multiply(DeltaSeconds));
    }
}

Summary

Godot is a full-featured game engine suitable for various game types, while PuerTS focuses on integrating TypeScript into existing Unreal Engine projects. Godot offers a more comprehensive solution for game development but may have a steeper learning curve. PuerTS provides better performance and integration with C++ codebases but requires existing knowledge of Unreal Engine.

Kotlin/Native infrastructure

Pros of kotlin-native

  • Supports multiple target platforms, including iOS, macOS, Windows, and Linux
  • Seamless interoperability with existing native libraries and frameworks
  • Strong static typing and null safety features inherited from Kotlin

Cons of kotlin-native

  • Steeper learning curve for developers not familiar with Kotlin
  • Limited JavaScript ecosystem integration compared to puerts
  • Potentially larger binary sizes due to inclusion of Kotlin runtime

Code Comparison

kotlin-native:

fun main() {
    println("Hello, Kotlin/Native!")
}

puerts:

console.log("Hello, PuerTS!");

Key Differences

  • puerts focuses on TypeScript/JavaScript integration with game engines, while kotlin-native is a general-purpose native compilation solution for Kotlin
  • kotlin-native provides direct compilation to native binaries, whereas puerts acts as a bridge between TypeScript/JavaScript and native environments
  • puerts is specifically designed for game development scenarios, while kotlin-native has broader applications across various domains

Use Cases

  • Choose kotlin-native for developing cross-platform native applications with Kotlin
  • Opt for puerts when integrating TypeScript/JavaScript into game engines like Unreal Engine or Unity

Community and Support

  • kotlin-native benefits from JetBrains' extensive support and the broader Kotlin community
  • puerts has a growing community, particularly in the game development sector, with strong backing from Tencent

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Logo

license PRs Welcome

unreal

unity Unity_Test

跳转中文

WHAT is PuerTS (PUER Typescript)?

PuerTS is a TypeScript programming solution in Unity/Unreal/DotNet.

  • provides a JavaScript Runtime.
  • allows TypeScript to access the host engine with the help of TypeScript declarations generation.

WHY should I use PuerTS?

  • Facilitates game-building processes by combining JavaScript/Node.js ecosystem and professional game engines
  • In contrast to Lua script, TypeScript supports static type checking, which significantly improves code robustness and maintainability.
  • High efficiency: supports reflection call throughout the host - no extra steps needed for interop with C++/C#.
  • High performance: supports static wrapper generation - handles complex scenes with high-performance demands.
  • Talented WebGL Support: massive advantage in performance and dev efficiency compared to Lua, even faster than pure C# in some cases.

HOW can I start to use PuerTS

Documentation


FAQ

How to Install

Changelog

Known issues


Select Script Engine

Currently puerts supports three script engines: v8, quickjs, nodejs, choose the one that suits you.

  • V8 (default): Generally excellent performance, moderate code size, only includes the implementation of the ECMAScript specification, does not include Node.js API or browser API.

  • QuickJS: Performance is not as good as V8, does not support debugging, but has a small code size, suitable for scenarios where code size is critical.

  • Node.js: Supports Node.js API (OpenSSL-related APIs are not supported on Unreal Engine's mobile platform), but has a larger code size.

Script EngineNode apiPerformanceCode SizeDebuggingNotes
V8❌********✔️
QuickJS❌***❌
Node.js✔️**********✔️OpenSSL may be disabled

Avaliable on these Engine

  • unreal engine 4.22 ~ latest

  • unity 5 ~ latest

  • Any .net project

Available on these Platform

  • iOS
  • Android
  • OpenHarmony
  • Windows
  • Macos

Ask for help

Github Discussion


WHAT - 普洱TS是什么?

PuerTS是 Unity/Unreal/Dotnet 下的TypeScript编程解决方案

  • 提供了一个JavaScript运行时
  • 提供TypeScript声明文件生成能力,易于通过TypeScript访问宿主引擎,

WHY - 为什么我该用普洱TS?

  • JavaScript生态有众多的库和工具链,结合专业商业引擎的渲染能力,快速打造游戏
  • 相比游戏领域常用的lua脚本,TypeScript的静态类型检查有助于编写更健壮,可维护性更好的程序
  • 高效:全引擎,全平台支持反射调用,无需额外步骤即可与宿主C++/C#通信。
  • 高性能:全引擎,全平台支持生成静态调用桥梁,兼顾了高性能的场景。
  • WebGL平台下的天生优势:相比Lua脚本在WebGL版本的表现,PuerTS在性能和效率上都有极大提升,目前极限情况甚至比C#更快。

HOW - 我该怎么开始


常见问题

最新版本安装

改动日志

已知问题与解决办法


脚本引擎选择

目前puerts支持三种脚本引擎:v8、quickjs、nodejs,选择合适你的那个。

  • v8(默认):综合比较优秀,高性能,代码体积适中,仅包含ecmascript规范的实现,不包含nodejs api、浏览器 api

  • quickjs: 性能不如v8,不支持调试,但代码体积小,适用于代码段大小敏感型业务

  • nodejs:支持nodejs api(unreal engine的移动平台下不支持openssl相关api),代码体积较大

脚本引擎Node api性能代码体积调试补充
V8❌********✔️
QuickJS❌***❌
Node.js✔️**********✔️OpenSSL 可能被禁用

可用引擎

  • unreal engine 4.22 ~ latest

  • unity 5 ~ latest

  • 任意.net环境

可用平台

  • iOS
  • Android
  • 鸿蒙(OpenHarmony)
  • Windows
  • Macos

技术支持

Github Discussion

QQ群:942696334

UE4专属群:689643903

开发博客

知乎专栏

NPM DownloadsLast 30 Days