Skip to content

1. Hello World

Wen Taichi edited this page Feb 5, 2025 · 2 revisions

Let create a graph which only log "Hello World!!"

Create the HelloWorld asset

  1. Create an AbilityGraph and named HelloWorld: Create -> Flexi -> AbilityAsset
  2. Double-click this asset to open the editor.
  3. Click "New Group" button at topleft, to create the first group.
  4. Search and create a built-in StartNode.
  5. Search and create a built-in LogNode.
  6. Create a link from StartNode to LogNode.
  7. Write "Hello World!!" into the text field of LogNode.
  8. Press "Save" button on top. (Ctrl+S also works if editor is focused.)

Start writing code

  1. Create a C# script named FlexiExtend.cs and paste below code. This is a template.
using Physalia.Flexi;

public class DefaultAbilityContainer : AbilityContainer
{
    public DefaultAbilityContainer(AbilityData abilityData, int groupIndex)
        : base(abilityData, groupIndex)
    {

    }
}

public abstract class DefaultEntryNode<TEventContext>
    : EntryNode<DefaultAbilityContainer, TEventContext> where TEventContext : IEventContext
{

}

public abstract class DefaultEntryNode<TEventContext, TResumeContext>
    : EntryNode<DefaultAbilityContainer, TEventContext, TResumeContext>
    where TEventContext : IEventContext where TResumeContext : IResumeContext
{

}

public abstract class DefaultProcessNode : ProcessNode<DefaultAbilityContainer>
{

}

public abstract class DefaultProcessNode<TResumeContext>
    : ProcessNode<DefaultAbilityContainer, TResumeContext> where TResumeContext : IResumeContext
{

}

public abstract class DefaultModifierNode : ModifierNode<DefaultAbilityContainer>
{

}

public abstract class DefaultValueNode : ValueNode<DefaultAbilityContainer>
{

}
  1. Create another script named "Test.cs"
    • Create FlexiCore with FlexiCoreBuilder on Awake().
    • On Update(), start an ability when we press Space. We need to enqueue all abilities we want to run, then call FlexiCore.Run().
using Physalia.Flexi;
using UnityEngine;

public class Test : MonoBehaviour
{
    [SerializeField]
    private AbilityAsset _asset;

    private FlexiCore _core;
    private DefaultAbilityContainer _container;

    private void Awake()
    {
        var builder = new FlexiCoreBuilder();
        _core = builder.Build();

        // Pre-load abilities
        //_core.LoadAbilityAll(_asset.Data);

        _container = new DefaultAbilityContainer(_asset.Data, 0);
    }

    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            _ = _core.TryEnqueueAbility(_container, EmptyEventContext.Instance);
            _core.Run();
        }
    }
}

Setup scene

  1. Almost done! Create an empty scene and add the Test behaviour into scene.
  2. Set the "HelloWorld" ability asset to the field.
  3. Play and press Space key to see some "Hello World!!"

Extra - Preloading ability

  1. When you press Space key at first time, you might see a warning log about performance. Let's handle it.
  2. Back to the Test class. Uncomment the line of _core.LoadAbilityAll(_asset.Data);
  3. Play again. Since we have preloaded, the warning log should disappear.

Clone this wiki locally