A progress bar can be displayed in the header of NodeComponent.
How to write a script
- Implement
LogicToolkit.IProgressComponent
as a type that inherits various NodeComponents.
- Implement
public LogicToolkit.ProgressPlayer ProgressPlayer{ get; }
.
- Switch the display of the progress bar with the
IsActive
property of LogicToolkit.ProgressPlayer
.
- Switch the progress bar progress (0 to 1) with the
CurrentProgress
property of LogicToolkit.ProgressPlayer
.
Code example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LogicToolkit;
[System.Serializable]
public class ProgressExample : TaskComponent, IProgressComponent
{
private ProgressPlayer progressPlayer = new ProgressPlayer();
public ProgressPlayer ProgressPlayer => progressPlayer;
private float startTime;
// OnActivated is called when activated.
protected override void OnActivated()
{
progressPlayer.IsActive = true;
progressPlayer.CurrentProgress = 0f;
startTime = Time.time;
}
// OnExecute is called when it is executed.
protected override TaskStatus OnExecute()
{
float progress = Time.time - startTime / 1f;
progressPlayer.CurrentProgress = progress;
// Return Running, Success, or Failure depending on the task execution status.
return progress >= 1f? TaskStatus.Success : TaskStatus.Running;
}
// OnDeactivated is called when it is deactivated.
protected override void OnDeactivated()
{
progressPlayer.IsActive = false;
}
}
|
In this example, the progress of the TaskComponent while it is waiting for 1 second is displayed as a progress bar in the NodeComponent header.
In addition, a script called Wait For Seconds is included in advance as a similar function.