-
Notifications
You must be signed in to change notification settings - Fork 35
1. Hello World
Wen Taichi edited this page Feb 5, 2025
·
2 revisions
Let create a graph which only log "Hello World!!"
- Create an AbilityGraph and named
HelloWorld:Create -> Flexi -> AbilityAsset - Double-click this asset to open the editor.
- Click "New Group" button at topleft, to create the first group.
- Search and create a built-in
StartNode. - Search and create a built-in
LogNode. - Create a link from StartNode to LogNode.
- Write "Hello World!!" into the text field of LogNode.
- Press "Save" button on top. (Ctrl+S also works if editor is focused.)
- Create a C# script named
FlexiExtend.csand 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>
{
}- Create another script named "Test.cs"
- Create
FlexiCorewithFlexiCoreBuilderonAwake(). - On
Update(), start an ability when we press Space. We need to enqueue all abilities we want to run, then callFlexiCore.Run().
- Create
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();
}
}
}- Almost done! Create an empty scene and add the
Testbehaviour into scene. - Set the "HelloWorld" ability asset to the field.
- Play and press Space key to see some "Hello World!!"
- When you press Space key at first time, you might see a warning log about performance. Let's handle it.
- Back to the
Testclass. Uncomment the line of_core.LoadAbilityAll(_asset.Data); - Play again. Since we have preloaded, the warning log should disappear.