some old local changes

This commit is contained in:
i.korystin
2019-08-04 00:45:18 +03:00
parent 70a767cf09
commit 1c1dd5cab6
48 changed files with 1017 additions and 0 deletions

View File

@@ -0,0 +1,200 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
/// <summary>
/// Basic action class for subclassing. To inherit interval actions, consider using the ActionInterval as the base class.
/// </summary>
public class ActionInstant
{
/// <summary>
/// Axis locks - the action will try to preserve tha values of these axises when moving or rotating the target.
/// </summary>
public Axises locks = Axises.none;
/// <summary>
/// Sets if the action should stop when the actor's StopAllActions method is called.
/// </summary>
public bool unstopable = false;
protected Actor target;
protected Transform transform;
protected Renderer renderer;
private float durationValue = 0;
private float dtrValue = 0;
private bool isRunning = false;
public ActionInstant()
{
}
/// <summary>
/// Returns a copy of the action.
/// </summary>
public virtual ActionInstant Clone()
{
return new ActionInstant();
}
/// <summary>
/// Returns the reversed version of the action, if it is possible.
/// </summary>
public virtual ActionInstant Reverse()
{
throw new Exception("Can reverse only the reversable interval actions");
}
/// <summary>
/// This method is called at the action start. Usable for instant and interval actions.
/// </summary>
public virtual void Start()
{
if (target == null)
throw new Exception("Can start the action only after it's atached to the actor");
transform = target.transformCached;
renderer = target.rendererCached;
}
/// <summary>
/// This method is called at every frame update. Not usable for instant actions.
/// </summary>
public virtual void StepTimer(float dt)
{
if (target == null)
throw new Exception("Can update the action only after it's atached to the actor");
}
/// <summary>
/// This method is called after the interval action is stopped. Not usable for instant actions.
/// </summary>
public virtual void Stop()
{
if (target == null)
throw new Exception("Can stop the action only after it's atached to the actor");
}
/// <summary>
/// This method sets the actor for the action.
/// </summary>
public void SetActor(Actor actor)
{
target = actor;
}
/// <summary>
/// This method modifies the given vector to keep the locked axises untouched.
/// </summary>
protected void LockAxises(ref Vector3 point)
{
{
if (target == null)
throw new Exception("Can calculate axises only after the action is atached to the actor");
}
switch (locks)
{
case Axises.x:
point.x = transform.position.x;
break;
case Axises.y:
point.y = transform.position.y;
break;
case Axises.z:
point.z = transform.position.z;
break;
case Axises.xy:
point.x = transform.position.x;
point.y = transform.position.y;
break;
case Axises.xz:
point.x = transform.position.x;
point.z = transform.position.z;
break;
case Axises.yz:
point.y = transform.position.y;
point.z = transform.position.z;
break;
case Axises.xyz:
point.x = transform.position.x;
point.y = transform.position.y;
point.z = transform.position.z;
break;
case Axises.rx:
point.x = transform.rotation.eulerAngles.x;
break;
case Axises.ry:
point.y = transform.rotation.eulerAngles.y;
break;
case Axises.rz:
point.z = transform.rotation.eulerAngles.z;
break;
case Axises.rxy:
point.x = transform.rotation.eulerAngles.x;
point.y = transform.rotation.eulerAngles.y;
break;
case Axises.rxz:
point.x = transform.rotation.eulerAngles.x;
point.z = transform.rotation.eulerAngles.z;
break;
case Axises.ryz:
point.y = transform.rotation.eulerAngles.y;
point.z = transform.rotation.eulerAngles.z;
break;
case Axises.rxyz:
point.x = transform.rotation.eulerAngles.x;
point.y = transform.rotation.eulerAngles.y;
point.z = transform.rotation.eulerAngles.z;
break;
}
}
/// <summary>
/// Readonly property. Shows the remaining time of the action.
/// </summary>
public float duration
{
get
{
return durationValue;
}
protected set
{
durationValue = value;
}
}
/// <summary>
/// Readonly property. Shows if the action is running or not.
/// </summary>
public bool running
{
get
{
return isRunning;
}
protected set
{
isRunning = value;
}
}
/// <summary>
/// Readonly property. Contains the remaining tick time after action finished.
/// </summary>
public float dtr
{
get
{
return dtrValue;
}
protected set
{
dtrValue = value;
}
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using coa4u;
namespace coa4u
{
/// <summary>
/// Moves the target to the random point inside the given zone.
/// </summary>
class ActionSelectRoamingPoint : ActionInstant
{
protected Vector3 radius;
protected Vector3 pointRef;
protected float speed;
protected Vector3 delta;
public ActionSelectRoamingPoint(Vector3 targetRadius, ref Vector3 point)
: base()
{
radius = targetRadius;
pointRef = point;
}
public override ActionInstant Clone()
{
return new ActionSelectRoamingPoint(radius, ref pointRef);
}
public override void Start()
{
base.Start();
pointRef.x = UnityEngine.Random.Range(-radius.x, radius.x);
pointRef.y = UnityEngine.Random.Range(-radius.y, radius.y);
pointRef.z = UnityEngine.Random.Range(-radius.z, radius.z);
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
/// <summary>
/// Moves in the given direction for the given amount of seconds.
/// </summary>
class ActionMoveForward : ActionInterval
{
protected float speed;
protected Vector3 delta;
public ActionMoveForward(float targetSpeed, float targetDuration)
: base(targetDuration)
{
speed = targetSpeed;
}
public override ActionInstant Clone()
{
return new ActionMoveForward(speed, duration);
}
public override ActionInstant Reverse()
{
return new ActionMoveForward(speed * -1F, duration);
}
public override void Start()
{
base.Start();
delta = speed * transform.forward;
}
public override void Step(float dt)
{
float d = dt / duration;
transform.Translate(delta * d, Space.World);
}
}
}

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 47f23d1678e988842ba4d66cdde3c4f8
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
/// <summary>
/// Creates the and starts the given action instance at Start. If you're using calcers for parameters, they will be also calculated at start.
/// </summary>
class ActionHolder<T> : ActionInstant
where T : ActionInstant
{
protected T action;
protected object[] args;
public ActionHolder(params object[] args) : base()
{
this.args = args;
}
public override void Start()
{
if (target == null)
throw new Exception("Can start the action only after it's atached to the actor");
object[] nargs = new object[args.Length];
for (int i = 0; i < args.Length; i++)
{
if (args[i] is CalcerFloat)
{
nargs[i] = ((CalcerFloat)args[i]).value;
}
else if (args[i] is CalcerVector)
{
nargs[i] = ((CalcerVector)args[i]).value;
}
else
{
nargs[i] = args[i];
}
}
action = (T)Activator.CreateInstance(typeof(T), nargs);
action.SetActor(target);
action.locks = locks;
action.Start();
duration = action.duration;
if (action.running)
running = true;
}
public override void StepTimer(float dt)
{
if (target == null)
throw new Exception("Can update the action only after it's atached to the actor");
action.StepTimer(dt);
if (!action.running)
{
dtr = action.dtr;
Stop();
}
}
public override void Stop()
{
if (target == null)
throw new Exception("Can stop the action only after it's atached to the actor");
if (action.running)
action.Stop();
running = false;
}
public override ActionInstant Clone()
{
return new ActionHolder<T>(args);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bbefa1d122cfc4c4e99bd1a82f65569d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
class ActionIf : ActionInterval
{
protected ActionInstant action;
protected Predicate predicate;
protected bool started;
public ActionIf(Predicate targetPredicate, ActionInstant targetAction)
: base(0)
{
action = targetAction;
predicate = targetPredicate;
}
public override ActionInstant Clone()
{
return new ActionIf(predicate, action);
}
public override ActionInstant Reverse()
{
return new ActionIf(predicate, action.Reverse());
}
public override void Start()
{
base.Start();
if (predicate.check())
{
started = true;
action.SetActor(target);
action.Start();
duration = action.duration;
}
else
{
running = false;
}
}
public override void StepTimer(float dt)
{
if (!started)
return;
dt *= timeScale;
if (action.running)
action.StepTimer(dt);
if (!action.running)
{
Stop();
dtr = action.dtr;
}
}
public override void Stop()
{
base.Stop();
action.Stop();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a45c0e16e46018a40813f228d30baa43
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
/// <summary>
/// Plays the action on another actor;
/// </summary>
class ActionPlayer : ActionInterval
{
protected ActionInstant action;
protected Actor actor;
public ActionPlayer(ActionInstant targetAction, Actor targetActor)
: base(0)
{
action = targetAction;
actor = targetActor;
}
public override ActionInstant Clone()
{
return new ActionPlayer(action, actor);
}
public override void Start()
{
base.Start();
actor.AttachAction(action);
if (!action.running)
running = false;
}
public override void StepTimer(float dt)
{
if (target == null)
throw new Exception("Can update the action only after it's atached to the actor");
action.StepTimer(dt);
if (!action.running)
{
dtr = action.dtr;
Stop();
}
}
public override void Step(float dt)
{
if (!action.running)
running = false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2d0fe551d8f6b114cb3bfc83d880377a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
class ActionSwitchState : ActionInstant
{
string stateName;
int stateIndex;
public ActionSwitchState(int targetIndex)
: base()
{
stateIndex = targetIndex;
}
public ActionSwitchState(string targetName)
: base()
{
stateName = targetName;
}
public override void Start()
{
base.Start();
if (!(target is SeqActor))
{
throw new Exception("Target is not capable of switching states.");
}
if (stateIndex != null)
{
((SeqActor)target).SetState(stateIndex);
}
else
{
((SeqActor)target).SetState(stateName);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 70a08a1fe8836f0419bd1b03f05a906a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 5a9b2c3311eddf04c861c0f8a385a3a0
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public abstract class Calcer
{
}
public abstract class Calcer<T> : Calcer
{
public abstract T value {get;}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1c50d149e0d2dab4bb3a6114abdeb7e8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerDirection : CalcerVector
{
Actor selfActor;
Actor targetActor;
Transform selfTransform;
Transform targetTransform;
public CalcerDirection(Actor self, Actor target)
: base()
{
selfActor = self;
targetActor = target;
}
public CalcerDirection(Transform self, Transform target)
: base()
{
selfTransform = self;
targetTransform = target;
}
public override Vector3 value
{
get
{
if (targetTransform != null)
{
return Quaternion.LookRotation(targetTransform.position - selfTransform.position).eulerAngles;
}
else
{
return Quaternion.LookRotation(targetActor.transformCached.position - selfActor.transformCached.position).eulerAngles;
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0a0a80ede5ea3dc42a372d76d2004cd0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerFloat : Calcer<float>
{
private float internalValue;
public CalcerFloat()
{
}
public CalcerFloat(float value)
{
internalValue = value;
}
public CalcerFloat(int value)
{
internalValue = (float)value;
}
public CalcerFloat(double value)
{
internalValue = (float)value;
}
public override float value
{
get
{
return internalValue;
}
}
public static implicit operator CalcerFloat(float val)
{
return new CalcerFloat(val);
}
public static implicit operator float(CalcerFloat calc)
{
return calc.value;
}
public static CalcerFloat operator +(CalcerFloat first, CalcerFloat second)
{
return new CalcerFloatCalc(first, second, CalcerFloatCalc.Operation.Add);
}
public static CalcerFloat operator -(CalcerFloat first, CalcerFloat second)
{
return new CalcerFloatCalc(first, second, CalcerFloatCalc.Operation.Sub);
}
public static CalcerFloat operator *(CalcerFloat first, CalcerFloat second)
{
return new CalcerFloatCalc(first, second, CalcerFloatCalc.Operation.Mul);
}
public static CalcerFloat operator /(CalcerFloat first, CalcerFloat second)
{
return new CalcerFloatCalc(first, second, CalcerFloatCalc.Operation.Div);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7e93dc2f49487544fa3a9b1468d66779
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerFloatCalc : CalcerFloat
{
public enum Operation
{
Add,
Sub,
Mul,
Div
}
private Operation operation;
private CalcerFloat first;
private CalcerFloat second;
public CalcerFloatCalc(CalcerFloat first, CalcerFloat second, Operation operation = Operation.Add)
{
this.first = first;
this.second = second;
this.operation = operation;
}
public float value
{
get
{
switch (operation)
{
case Operation.Add:
return first.value + second.value;
case Operation.Sub:
return first.value - second.value;
case Operation.Mul:
return first.value * second.value;
case Operation.Div:
return first.value / second.value;
default:
throw new Exception("Operation not found.");
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 45cbf8512a210f942a10b844f2000826
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerPosition : CalcerVector
{
Actor targetActor;
Transform targetTransform;
public CalcerPosition(Actor target)
: base()
{
this.targetActor = target;
}
public CalcerPosition(Transform target)
: base()
{
this.targetTransform = target;
}
public override Vector3 value
{
get
{
if (targetTransform != null)
return (Vector3)targetTransform.position;
else
return (Vector3)targetActor.transformCached.position;
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6f377903d22e64e409c946c5ec777bb9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerRandomDirection : CalcerVector
{
Axises axises;
public CalcerRandomDirection(Axises axises)
{
this.axises = axises;
}
public override Vector3 value
{
get
{
float x = UnityEngine.Random.Range(-360.0F, 360.0F);
float y = UnityEngine.Random.Range(-360.0F, 360.0F);
float z = UnityEngine.Random.Range(-360.0F, 360.0F);
switch (axises)
{
case Axises.x:
return new Vector3(x, 0, 0);
case Axises.y:
return new Vector3(0, y, 0);
case Axises.z:
return new Vector3(0, 0, z);
case Axises.xy:
return new Vector3(x, y, 0);
case Axises.xz:
return new Vector3(x, 0, z);
case Axises.yz:
return new Vector3(0, y, z);
case Axises.xyz:
return new Vector3(x, y, z);
default:
return Vector3.zero;
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5ad17ef81ba6b9944bf5aa283e4be908
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerVector : Calcer<Vector3>
{
private Vector3 internalValue;
private int dimensions;
public CalcerVector()
{
}
public CalcerVector(Vector3 value)
{
internalValue = value;
dimensions = 3;
}
public CalcerVector(Vector2 value)
{
internalValue = value;
dimensions = 2;
}
public override Vector3 value
{
get
{
switch (dimensions)
{
case 3:
return (Vector3)internalValue;
case 2:
return (Vector2)internalValue;
default:
return internalValue;
}
}
}
public static implicit operator CalcerVector(Vector3 val)
{
return new CalcerVector(val);
}
public static implicit operator CalcerVector(Vector2 val)
{
return new CalcerVector(val);
}
public static implicit operator Vector3(CalcerVector calc)
{
return calc.value;
}
public static CalcerVector operator +(CalcerVector first, CalcerVector second)
{
return new CalcerVectorCalc(first, second, CalcerVectorCalc.Operation.Add);
}
public static CalcerVector operator -(CalcerVector first, CalcerVector second)
{
return new CalcerVectorCalc(first, second, CalcerVectorCalc.Operation.Sub);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c04bfd357341874e8be24608bfd976e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
public class CalcerVectorCalc : CalcerVector
{
public enum Operation
{
Add,
Sub
}
private Operation operation;
private CalcerVector first;
private CalcerVector second;
public CalcerVectorCalc(CalcerVector first, CalcerVector second, Operation operation = Operation.Add)
{
this.first = first;
this.second = second;
this.operation = operation;
}
public override Vector3 value
{
get
{
switch (operation)
{
case Operation.Add:
return first.value + second.value;
case Operation.Sub:
return first.value - second.value;
default:
throw new Exception("Operation not found.");
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 78a730b682beb8d4180d80db8bdc6537
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 38016d14a3449b7478e2c667c72063f6
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
namespace coa4u
{
public class State
{
public readonly ActionInstant action;
public readonly Predicate trigger;
public readonly string name;
public State(ActionInstant targetAction, string targetName = "")
{
action = targetAction;
name = targetName;
}
public State(Predicate targetTrigger, ActionInstant targetAction, string targetName = "")
{
trigger = targetTrigger;
action = targetAction;
name = targetName;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ebc37cf537501dd4f9290a911cb5b757
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 470c1cdb0ca2c1a4895bc641646f9474
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
namespace coa4u
{
public abstract class Predicate
{
public abstract bool check();
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 97583e10785bec74c939caf211b248b8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
namespace coa4u
{
public class PredicateDistanceGreater : Predicate
{
protected CalcerVector first;
protected CalcerVector second;
protected float distance;
public PredicateDistanceGreater(CalcerVector one, CalcerVector other, float dist)
: base()
{
first = one;
second = other;
distance = dist;
}
public override bool check()
{
if (Vector3.Distance(first.value, second.value) > distance)
return true;
else
return false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17a24fb6b2830f24fb10e079734a432f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
namespace coa4u
{
public class PredicateDistanceLess : Predicate
{
protected CalcerVector first;
protected CalcerVector second;
protected float distance;
public PredicateDistanceLess(CalcerVector one, CalcerVector other, float dist)
: base()
{
first = one;
second = other;
distance = dist;
}
public override bool check()
{
if (Vector3.Distance(first.value, second.value) <= distance)
return true;
else
return false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1f98bec35befcf141bfda4291e7aea41
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,14 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
namespace coa4u
{
public class PredicateFalse : Predicate
{
public override bool check()
{
return false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c046509f9d6d55b45a9643e86a29c95c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,14 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
namespace coa4u
{
public class PredicateTrue : Predicate
{
public override bool check()
{
return true;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8f6a4b0a53e20504fa28937299d4df63
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 45d3e250968191147aeb6b6346456173
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using coa4u;
[System.Serializable]
public class SeqActor : Actor
{
protected State[] states;
protected int index;
protected List<int> stateLog = new List<int>();
protected ActionInstant currentStateAction;
public void SetState(int idx)
{
if (idx < states.Length)
{
stateLog.Add(idx);
index = idx;
if (currentStateAction != null)
RemoveAction(currentStateAction);
currentStateAction = states[idx].action;
AttachAction(currentStateAction);
}
else
{
throw new Exception("Actor doesn't have the state " + idx.ToString());
}
}
public void SetState(string name)
{
SetState(Array.FindIndex<State>(states, x => x.name == name));
}
public int currentStateIndex
{
get
{
return index;
}
}
public string currentStateName
{
get
{
return states[index].name;
}
}
public List<int> log
{
get
{
return stateLog;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fe7dfa7af5880d044b663b7fce129ce4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using coa4u;
[System.Serializable]
public class SeqTest : SeqActor
{
public Actor enemy;
Vector3 startPosition;
void Start()
{
startPosition = transformCached.position;
CalcerVector endPosition = new CalcerPosition(enemy) + new CalcerVector(new Vector3(-2F, transformCached.position.y, 0F));
ActionInstant stateDefault = new ActionSequence(
new ActionInstant[]
{
new ActionDelay(3),
new ActionSwitchState(1)
});
ActionInstant stateRoam = new ActionSequence(
new ActionInstant[] {
new ActionHolder<ActionSetDirection>(new CalcerPosition(enemy)),
new ActionHolder<ActionJumpTo>(endPosition, 5, 1, 1),
new ActionDelay(0.5F),
new ActionHolder<ActionMoveTo>(new CalcerPosition(enemy), 0.1F),
new ActionHolder<ActionMoveTo>(endPosition, 0.1F),
new ActionDelay(0.5F),
new ActionJumpTo(startPosition, 5, 1, 1),
new ActionSwitchState(0)
});
states = new State[]
{
new State(stateDefault, "wait"),
new State(stateRoam, "attack")
};
SetState(0);
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a97027e8b127e5049be5e16c73c87275
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: