Custom

Custom Error Configuration

A custom Error is defined by implementing the CustomErrorTypeDefinition class and attaching it to the UI. For example, the HeightLimitError triggers if the Target prefab exceeds the specified MaxHeight.

public class HeightLimitError : CustomErrorTypeDefinition
{
    public float MaxHeight { get; set; } = 2f;
    public GameObject Target { get; set; } = null;

    private GameObject spawnedPrefab = null;

    protected override void OnCreate()
    {
        Target = Resources.Load<GameObject>("TargetCube");
    }

    protected override void OnActionInitialize(BaseActionData baseActionData)
    {
        if (baseActionData.ActionName == ActionName)
        {
                spawnedPrefab = AnalyticsUtilities.Spawn(Target);

                spawnedPrefab.AttachCallback(AnalyticsUtilities.Hook.OnTranslation, () =>
                {
                if (spawnedPrefab.transform.position.y > MaxHeight)
                {
                    TriggerError();
                }
                });
        }
    }

    protected override void OnActionPerform(BaseActionData baseActionData, bool skipped)
    {
        if (baseActionData.ActionName == ActionName)
        {
                AnalyticsUtilities.Destroy(spawnedPrefab);
        }
    }

    protected override void OnActionUndo(BaseActionData baseActionData)
    {
        if (baseActionData.ActionName == ActionName)
        {
                AnalyticsUtilities.Destroy(spawnedPrefab);
        }
    }
}

Custom Objective Configuration

A custom Objective can be created by implementing the CustomObjectiveTypeDefinition class and attaching it to the UI. For example, the OperationTimeObjective class succeeds if GetRealTimeSinceStartUp() is less than the timeLimit value.

public class OperationTimeObjective : CustomObjectiveTypeDefinition
{
    float timeLimit = 20f;

    protected override void OnActionInitialize(BaseActionData baseActionData)
    {
        if (Hub.Instance.Get<SceneGraphModule>().GetActionCategory(baseActionData)
        == SceneGraphModule.ActionCategory.End)
        {
            bool success = Hub.Instance.
            Get<MAGESAnalytics>().GetRealTimeSinceStartUp() < timeLimit;

            TriggerObjective(success);
        }
    }
}