add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class simpleAIAction : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool actionEnabled = true;
|
||||
|
||||
public bool actionUsedByPlayer;
|
||||
|
||||
public float actionDuration;
|
||||
|
||||
public bool useUpdateSystemCoroutine;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool actionActive;
|
||||
|
||||
public Transform currentTarget;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnStartAction;
|
||||
public UnityEvent eventOnStartAction;
|
||||
|
||||
public bool useEventOnEndAction;
|
||||
public UnityEvent eventOnEndAction;
|
||||
|
||||
[HideInInspector] public Coroutine actionCoroutine;
|
||||
|
||||
|
||||
public virtual void startAIAction ()
|
||||
{
|
||||
if (actionEnabled) {
|
||||
activateCoroutine ();
|
||||
|
||||
actionActive = true;
|
||||
|
||||
if (useEventOnStartAction) {
|
||||
eventOnStartAction.Invoke ();
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("startAIAction");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void endAIAction ()
|
||||
{
|
||||
if (actionEnabled) {
|
||||
if (actionActive) {
|
||||
if (useEventOnEndAction) {
|
||||
eventOnEndAction.Invoke ();
|
||||
}
|
||||
|
||||
actionActive = false;
|
||||
|
||||
stopActionCoroutine ();
|
||||
|
||||
resetStatesOnActionEnd ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("endAIAction");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void stopActionCoroutine ()
|
||||
{
|
||||
if (actionCoroutine != null) {
|
||||
StopCoroutine (actionCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void activateCoroutine ()
|
||||
{
|
||||
if (useUpdateSystemCoroutine) {
|
||||
actionCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
} else {
|
||||
actionCoroutine = StartCoroutine (updateActionCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateActionCoroutine ()
|
||||
{
|
||||
WaitForSeconds delay = new WaitForSeconds (actionDuration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
endAIAction ();
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void updateSystem ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void resetStatesOnActionEnd ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setCustomTarget (Transform newTarget)
|
||||
{
|
||||
currentTarget = newTarget;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user