Demo Scene Examples

v1.0

In this demo scene we work with some custom actions and slightly more advanced methods to accomplish some juicy behaviors.

circle-info

Note that I am using the Customize Component Names arrow-up-rightpackage from Magic Pig Games, available on the Asset Store. It allows for custom names in the Inspector for components. I will use them to better highlight what various components like ActionRunner components will do, especially when there are multiple on a single object.

Custom Predicates

The JuicyActor class, which is custom for this demo, also implements IAmRPGDemo which has various methods that can be used with the Custom Predicate Conditional option.

// IAmRPGActor.cs
public interface IAmRPGActor
{
    public bool IsReady();
    public bool IsActive();
}

The Main Sprite under each of the Player prefabs in the scene has an Action Runner which handles scaling their sprite up and down when they're active. To ensure it only runs when the player is actually active, and when they're in a "isReady" state, we can use the Custom Predicate Conditional.

Now the action will only run when the IsReady and IsActive both return true. The script automatically finds methods using the IAmRPGActor interface.

Set Override Values at Runtime

The Damage Number prefab is instantiated, but then positioned and set up by the JuicyActor who has been hit, as each of them has their own offset value based on Sprite size.

If the attack "Missed", meaning the damage was <= 0, then we want the text to be white, not red. So we set the target color values directly in the code:

Since the ActionExecutor has two TMPTextColorAction actions, we need to specify which one to target using the UID assigned to each, which I've copied from the Inspector into my code. One targets the color to full alpha, the other targets the color with alpha at 0.

Utilizing CanExecute()

The three buttons, Next Player, Player Attack, and Enemy Attack, disable when they are not able to do anything. For the two attack buttons, this utilizes properties on RGPGameManager.cs and ToggleButtonForEnemy.cs / ToggleButtonForPlayer.cs.

In this code, the EnemyCanAttack just checks to make sure the attackActions can execute.

For the PlayerCanAttack, we check the attackActions as well as the onSelectedActions and onDeselectedActions, which move the players forward and back when they are activated.

Action Executor Setup

It is important to remember that the value of CanExecute() is determined by the cooldown and restart settings of the ActionExecutor itself, and does not have to relate to the actual actions being executed.

Here we have Can Restart set true, and the cooldown is Determined by Duration. This means that CanExecute() will return true only when the duration (0.5) has elapsed. This matches the actual ActionExecutor logic, and is a helpful way to know if Execute() will even result in a successful execution.

Last updated