Last active
April 22, 2016 13:49
-
-
Save grofit/ec959540061ea65b3309 to your computer and use it in GitHub Desktop.
Example of interacting with uFrame from NodeCanvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using NodeCanvas; | |
using NodeCanvas.Variables; | |
using UnityEngine; | |
/* | |
Let us assume you have a uFrame Entity which can attack | |
and when it does it needs to play an animation in the view layer | |
and also needs to tell the controller to trigger an attack | |
in the back end. An attack may not hit anything but we would | |
delegate that call to the Controller to deal with | |
We can assume that the View has a ViewComponent for dealing | |
with animations and another for dealing with effects, | |
and has a controller for dealing with the actual hit logic. | |
*/ | |
[Name("Attack")] | |
[Category("<YourGameName>/Entities")] | |
[RequireComponent(typeof(EntityView))] | |
public class AttackAction : ActionTask | |
{ | |
[GetFromAgent] | |
private EntityView _view; | |
protected override void OnExecute() | |
{ | |
// Tell the controller to trigger an attack | |
var attackResult = _view.EntityController.DoAttack(); | |
// Check if the attack was a success and handle the view concerns | |
switch(attackResult.Status) | |
{ | |
case AttackStatus.OutOfAmmo: | |
{ _view.Animator.PlayOutOfAmmoAnimation(); } | |
break; | |
case AttackStatus.InCooldown: | |
{ _view.Effects.FlashRed(); } | |
break; | |
case AttackStatus.Hit: | |
{ _view.Animator.PlayFireAnimation(); } | |
break; | |
} | |
// Everything went well | |
EndAction(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment