Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@needle-tools/needle-component-compiler

needle-tools8061.11.2

Compile mock unity components from typescript

readme

Typescript to Unity component

Little helper package to transpile typescript files to Unity C# components.
Please run npm install first before using.

Usage

node <path to>/component-compiler.js <output_directory> <path_to/my_script.ts>

Command decorators

  • @dont-generate-component add before class to skip generating a component
  • @generate-component to enforce generating a component (not required)
  • @serializeField field decorator, similar to [SerializeField] in Unity
  • @nonSerialized field or method decorator to skip generating c# code for a field or a method, similar to [NonSerialized] in Unity
  • @type MyNamespace.MyType decorator for fields or classes, specifiy C# type of field or class
  • @ifdef MY_IFDEF field decorator only at the moment
  • @tooltip My Text field decorator, generates a Unity [Tooltip("My Text")]
  • @contextmenu MethodName method decorator, generates a [ContextMenu("MethodName")]

changelog

Changelog

All notable changes to this package will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[1.11.2] - 2023-12-16

  • Fix: property setter emitting invalid C# code

[1.11.1] - 2023-12-02

  • Fix: Use Unity AnimatorController type
  • Fix: method inline anonymous type declaration (e.g. myMethod(arg: {x:number}))

[1.11.0] - 2023-11-18

  • Add: support to wrap fields with #if UNITY_EDITOR if their namespace contains UnityEditor
  • Add: more threejs types to generate Unity Material fields for

[1.10.3] - 2023-09-08

  • Add: Needle Engine type RGBAColor is now automatically emitted as UnityEngine.Color

[1.10.2] - 2023-09-08

  • Fix: @type was not properly applied for new expression cases (e.g. new RGBAColor should produce a new Color when decorated with @type Color)

[1.10.1] - 2023-08-02

  • Add: use @tooltip to emit a UnityEngine.Tooltip
  • Update Readme

[1.9.4] - 2023-05-24

  • Change: Object3D now emits GameObject field instead of Transform
  • Fix: ignore static methods
  • Fix: ignore abstract methods

[1.9.3] - 2022-12-30

  • Add debug logs for when no file or target directory was passed in. Also wrapping core with try catch

[1.9.2] - 2022-11-29

  • Fix codegen deleting code added manually outside of codegen sections
  • Fix codegen creating output directory if it does not exist yet

[1.9.1] - 2022-11-05

  • Fix new Vector2(1, .5) generating invalid C# where number arguments were emitted as double instead of float

[1.9.0] - 2022-10-18

  • Change: emit onEnable as OnEnable and onDisable as OnDisable so Unity creates component checkboxes
  • Change: ignore private and protected methods

[1.8.0] - 2022-09-02

  • Add @nonSerialized decorator for fields and methods
  • Fix comment gen for unknown types

[1.7.3] - 2022-09-02

  • Fix codegen for unknown array types
  • Fix codegen for abstract classes
  • Fix codegen for types imported as e.g. THREE.AnimationClip

[1.7.2] - 2022-07-27

  • fix UnityEvent codegen

[1.7.1] - 2022-07-25

[1.7.0] - 2022-07-14

  • change: skip non-serializeable variables (private without @serializable)
  • improve member type generation
  • fix bug in type generation for array types
  • add/improve initial assignment codegen for object types

[1.6.3] - 2022-07-12

  • add warning when class type is unknown

[1.6.2] - 2022-07-11

  • fix @type for class declaration

[1.6.1] - 2022-07-10

  • add using types.json json file that will be generated from Unity
  • change @type annotiation to only work without braces to be consistent

[1.5.0] - 2022-07-07

  • change @type annotation to work with and without braces (e.g. @type My.Type or @type (My.Type))

[1.4.0] - 2022-07-06

  • add CODEGEN_START and END sections to allow adding code before or after a generated componnet
  • add @ifdef to ifdef fields

[1.3.0] - 2022-06-27

  • add support for typescript namespace

[1.2.1] - 2022-06-15

  • allow adding @type(MyNamespace.MyType) to class declaration

[1.1.0] - 2022-06-13

  • add @type(MyNamespace.MyType) decorator for fields to specifiy C# type
  • add minimal docs to readme
  • dont emit comments anymore
  • make created classes partial

[1.0.1] - 2022-05-29

  • disable all warnings for generated scripts
  • add mesh and texture types

[1.0.0] - 2022-04-22

  • initial release