Giter Club home page Giter Club logo

unity-rumor's Introduction

Rumor

Rumor is a free, open source narrative content framework meant to be integrated into any Unity3D game that needs a dialog system. This library is a good fit for teams that want a scripting language for writers to use and need an easy-to-use API for running the dialog. This library does not and will not contain any rendering capabilities.

You can download official releases at the releases page.

To learn more about Rumor, check the official wiki.

Change Log

Please see the file named CHANGELOG.md.

Licensing

Please see the file named LICENSE.md.

Usage

Example.txt

label start:
    say "Hi!"
    say "Is this working?"

    choice "Yes!":
        say "Great!"
    choice "No.":
        say "Darn..."
        pause 0.5
        add "Maybe next time."
        jump end
    choose

$ apples = get_apples()
$ pears = get_pears()

if apples == pears:
    $ pears += 1

say "I have " + apples + " apples."
say "You have { pears } pears."
say "Who has more fruits?"

choice "I do.":
    if apples < pears:
        jump correct
    jump incorrect
choice "You do.":
    if apples > pears:
        jump correct
    jump incorrect
choose

label correct:
    say "That's right!"
    jump end

label incorrect:
    say "That's wrong!"
    jump end

label end:
    say "Well, thanks for stopping by!"
    say "See you next time!"

Example.cs

using Exodrifter.Rumor.Engine;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class RumorScriptExample : MonoBehaviour
{
    private Rumor rumor;
    public Text text;

    void Awake()
    {
        rumor = new Rumor(File.ReadAllText("Example.txt"));
        rumor.Scope.DefaultSpeaker = "Narrator";

        rumor.Bindings.Bind("get_apples", () => { return Random.Range(2, 6); });
        rumor.Bindings.Bind("get_pears", () => { return Random.Range(2, 6); });

        StartCoroutine(rumor.Start());
    }

    void Update()
    {
        if (rumor == null) {
            text.text = "";
            return;
        }

        if (rumor.Choosing) {
            int num = 1;
            text.text = "";

            foreach (var choice in rumor.State.Choices) {
                text.text += num + ") " + choice + "\n";
                num++;
            }
        }
        else {
            text.text = rumor.State.Dialog["Narrator"];
        }

        rumor.Update(Time.deltaTime);

        if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)) {
            rumor.Advance();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1)) {
            rumor.Choose(0);
        }

        if (Input.GetKeyDown(KeyCode.Alpha2)) {
            rumor.Choose(1);
        }
    }
}

See Editor/Examples/RumorScriptExample.cs to run this example in Unity.

unity-rumor's People

Contributors

exodrifter avatar gableroux avatar

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.