11 Scriptable Object Blackboard
This example shows you how to use a scriptable object Blackboard.
These files can be found in the /Examples/[example] and /Blackboards/Examples folders.
ScriptableObjectBlackboard.cs
using System;
using CrashKonijn.Blackboard.Contracts;
using UnityEngine;
namespace CrashKonijn.BlackboardPro.Blackboards.Examples
{
[CreateAssetMenu(menuName = "Blackboard Pro/Examples/ScriptableObjectBlackboard")]
public partial class ScriptableObjectBlackboard : BlackboardScriptable
{
private int startPlayerHealth = 100;
private static int lowHealth(Signals.StartPlayerHealth startPlayerHealth) => (int) (startPlayerHealth.Value * 0.4f);
}
}
ScriptableBehaviour.cs
using System;
using CrashKonijn.BlackboardPro.Blackboards.Examples;
using UnityEngine;
namespace CrashKonijn.BlackboardPro.Examples._11_scriptable_object
{
public class ScriptableBehaviour : MonoBehaviour
{
[Header("Make sure to view the ScriptableBlackboard\nin the example folder!\n\nThis behaviour binds events on play")]
[SerializeField]
private ScriptableObjectBlackboard blackboard;
// You can still register events to the signals!
private void OnEnable()
{
blackboard.LowHealthSignal.OnValueChanged.AddListener(OnLowHealthChanged);
blackboard.StartPlayerHealthSignal.OnValueChanged.AddListener(OnStartPlayerHealthChanged);
}
private void OnDisable()
{
blackboard.LowHealthSignal.OnValueChanged.RemoveListener(OnLowHealthChanged);
blackboard.StartPlayerHealthSignal.OnValueChanged.RemoveListener(OnStartPlayerHealthChanged);
}
private void OnLowHealthChanged(int value)
{
Debug.Log($"Low health changed to {value}");
}
private void OnStartPlayerHealthChanged(int value)
{
Debug.Log($"Start player health changed to {value}");
}
}
}
Last updated