Giter Club home page Giter Club logo

dimension-gate's Introduction

Instructions

  1. Run Unity, open scene in Assets/Scenes
  2. Start the Unity server click the Play button, it's running at the following address: ws://localhost:1234.
  3. Run stack repl in dimension-gate/scripting-api
  4. Run runDGTest in the repl (Only works after you click Play because runDG connects to the Unity websocket engine on address ws://localhost:1234)

DimensionGate Websockets Server starts from the DimensionGateClient script which is placed on the Core object in the Scene hierarchy.

If you want to send something to the Haskell websocket client then use DimensionGateServer.inst.send("A string that will go to the Haskell client");

For example, in the DimensionGateClient there is the code bellow:

void Update () {
    if (Input.GetKeyDown(KeyCode.F)) {
        DimensionGateServer.inst.send("F");
    }
}

It means when we press Play, focus on the game window in the Unity editor and press the F button, then the "F" message is sent to the Haskell websockets client.

If you want to handle a message that Haskell websocket client sends, go to the DimensionGateServer class and and respond in the OnMessage function. BE CAREFUL, you can't just run Unity functions in the OnMessage callback because it's running not in the Unity thread, so to run something that uses MonoBehaviour or some another Unity API, use the next function:

UnityMainThreadDispatcher.Instance().Enqueue(() => {
    // Write some Unity code
})

For example, in the OnMessage function we have the following code:

if (e.Data == "Set camera to 0, 0") {
    UnityMainThreadDispatcher.Instance().Enqueue(() => {
        PlayerCamera.inst.setPosition(new Vector2(0, 0));
    });
}

It means that when Haskell websockets client sends to the Unity websockets server the message Set camera to 0, 0 the function PlayerCamera.inst.setPosition(new Vector2(0, 0)); is ran with the help of the UnityMainThreadDispatcher.Instance().Enqueue(() => { ... }) function.

Scripting API

Read the scripting-api/README.md file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.