123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using NodeCanvas.Framework;
- using ParadoxNotion.Design;
- using KairoEngine.Core;
- namespace KairoEngine.CharacterSystem
- {
- [Category("KairoEngine")]
- public class CharacterMoveToPositionTaskAction : ActionTask
- {
- [BlackboardOnly, RequiredField] public BBParameter<CharacterController> character;
- [BlackboardOnly, RequiredField] public BBParameter<Vector3> position;
- [RequiredField] public BBParameter<float> stoppingDistance = 1f;
- public MoveSpeed moveSpeed = MoveSpeed.walk;
- protected override string info {
- get { return "Move character to position"; }
- }
- protected override void OnExecute()
- {
- float translationSpeed = 1.25f;
- float animationSpeed = 1f;
- if(moveSpeed == MoveSpeed.run)
- {
- translationSpeed = 3.5f;
- animationSpeed = 2f;
- }
- GenericEvents.StartListening(character.value.unique_name + "-ArrivedInPositionAction", End);
- ICommand movecommand = new CharacterMoveToPositionCommand(character.value, position.value, translationSpeed, animationSpeed, stoppingDistance.value);
- CommandInvoker.AddCommand(movecommand);
- }
- protected override void OnUpdate()
- {
- float distance = Vector3.Distance(character.value.transform.position, position.value);
- if(distance < stoppingDistance.value) End();
- }
- protected override void OnStop()
- {
- End();
- }
- private void End()
- {
- GenericEvents.StopListening(character.value.unique_name + "-ArrivedInPositionAction", End);
- ICommand stopCommand = new CharacterStopMoveCommand(character.value);
- CommandInvoker.AddCommand(stopCommand);
- EndAction(true);
- }
- }
- }
|