blob: 36d9a29fa6ae5a5bd1c185a43f0ad018438d601f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityVector2
{
[TaskCategory("Basic/Vector2")]
[TaskDescription("Performs a math operation on two Vector2s: Add, Subtract, Multiply, Divide, Min, or Max.")]
public class Operator : Action
{
public enum Operation
{
Add,
Subtract,
Scale
}
[Tooltip("The operation to perform")]
public Operation operation;
[Tooltip("The first Vector2")]
public SharedVector2 firstVector2;
[Tooltip("The second Vector2")]
public SharedVector2 secondVector2;
[Tooltip("The variable to store the result")]
public SharedVector2 storeResult;
public override TaskStatus OnUpdate()
{
switch (operation) {
case Operation.Add:
storeResult.Value = firstVector2.Value + secondVector2.Value;
break;
case Operation.Subtract:
storeResult.Value = firstVector2.Value - secondVector2.Value;
break;
case Operation.Scale:
storeResult.Value = Vector2.Scale(firstVector2.Value, secondVector2.Value);
break;
}
return TaskStatus.Success;
}
public override void OnReset()
{
operation = Operation.Add;
firstVector2 = secondVector2 = storeResult = Vector2.zero;
}
}
}
|