Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MoonBit-Unity

A very handy framework that lets you write MoonBit in Unity. (MoonBit -> JS backend -> PuerTS -> Unity)

"Handy" means few magic in gluing things together. Since MoonBit is rapidly growing in both language features and toolchains, I want to keep things bare and easy to evolve together.

Though still primitive, you can now begin exploring MoonBit in Unity.

Get started

Tested with Unity 6 (6000.0.38f1) and Moon's version as below.

moon 0.1.20250402 (5cc5674 2025-04-02) ~/.moon/bin/moon
moonc v0.1.20250402+bf7b62354 ~/.moon/bin/moonc
moonrun 0.1.20250402 (5cc5674 2025-04-02) ~/.moon/bin/moonrun

Open Assets/MoonBit/Samples/RotateCube.unity and enter Play mode.

TEMP Run python3 build.py to compile code, see todos in it.

Behaviour Code Example

typealias MoonBehaviour = @bind.MoonBehaviour

struct Rotate {
  mut bindTo : MoonBehaviour?
  speed : Int
  string_value : String
} derive(Default)

fn start(self : Rotate) -> Unit {
  println("start")
}

fn update(self : Rotate) -> Unit {
  println("current speed is \{self.speed}")
}

fn ondestroy(self : Rotate) -> Unit {
  println("onDestroy...")
}

fn new() -> Rotate {
  Rotate::default()
}

pub fn bind(bindTo : MoonBehaviour) -> Unit {
  let self = new()
  self.bindTo = Some(bindTo)
  bindTo.set_start(fn() { self.start() })
  bindTo.set_update(fn() { self.update() })
  bindTo.set_ondestroy(fn() { self.ondestroy() })
}

Features

  • Bind .mbt asset and variables in via spector

About

Write MoonBit in Unity

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages