Skip to content

Commit a9cd64c

Browse files
committed
action files added
Added the .cs files. of the package.
1 parent ce433e7 commit a9cd64c

13 files changed

+870
-0
lines changed

Actions/3DCompass.cs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2014 F. Rick Reich.
2+
3+
using UnityEngine;
4+
using System.Collections;
5+
6+
namespace HutongGames.PlayMaker.Actions {
7+
[ActionCategory("Advanced Actions")]
8+
[Tooltip("Builds a compass to show the direction to a set target.")]
9+
public class Compass3D : FsmStateAction {
10+
11+
[RequiredField]
12+
public FsmOwnerDefault gameObject;
13+
14+
[RequiredField]
15+
public FsmGameObject targetObject;
16+
17+
[HasFloatSlider(0f,5)]
18+
public FsmFloat adjustmentSpeed;
19+
20+
public FsmBool debug;
21+
22+
private Quaternion lastRotation;
23+
private Quaternion desiredRotation;
24+
25+
public override void Reset() {
26+
gameObject = null;
27+
targetObject = null;
28+
adjustmentSpeed = 2.5f;
29+
}
30+
31+
public override void OnLateUpdate() {
32+
DoOrientate3D();
33+
}
34+
35+
void DoOrientate3D() {
36+
37+
var upVector = new FsmVector3 { UseVariable = true};
38+
var go = Fsm.GetOwnerDefaultTarget(gameObject);
39+
if (go == null)
40+
{
41+
return;
42+
}
43+
44+
var goTarget = targetObject.Value;
45+
46+
Vector3 lookAtPos = goTarget.transform.position;
47+
lookAtPos.y = go.transform.position.y;
48+
49+
var diff = lookAtPos - go.transform.position;
50+
if (diff != Vector3.zero && diff.sqrMagnitude > 0)
51+
{
52+
desiredRotation = Quaternion.LookRotation(diff, upVector.IsNone ? Vector3.up : upVector.Value);
53+
}
54+
55+
lastRotation = Quaternion.Slerp(lastRotation, desiredRotation, adjustmentSpeed.Value * Time.deltaTime);
56+
go.transform.rotation = lastRotation;
57+
58+
if (debug.Value)
59+
{
60+
Debug.DrawLine(go.transform.position, lookAtPos, Color.red);
61+
}
62+
}
63+
64+
}
65+
}

Actions/AutoRotate.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2014 F. Rick Reich.
2+
3+
using UnityEngine;
4+
using System.Collections;
5+
6+
namespace HutongGames.PlayMaker.Actions
7+
{
8+
[ActionCategory("Advanced Actions")]
9+
[Tooltip("Constantly Rotates an object along an axis, using a speed value.")]
10+
public class AutoRotate : FsmStateAction
11+
{
12+
13+
public FsmOwnerDefault gameObject;
14+
public FsmVector3 rotation;
15+
public bool everyFrame;
16+
17+
public override void Reset()
18+
{
19+
gameObject = null;
20+
rotation = null;
21+
everyFrame = false;
22+
}
23+
24+
public override void OnEnter()
25+
{
26+
DoRotate();
27+
28+
if (!everyFrame)
29+
{
30+
Finish();
31+
}
32+
}
33+
34+
public override void OnUpdate()
35+
{
36+
DoRotate();
37+
}
38+
39+
void DoRotate()
40+
{
41+
var go = Fsm.GetOwnerDefaultTarget(gameObject);
42+
if (go == null)
43+
{
44+
return;
45+
}
46+
47+
if (gameObject!=null)
48+
{
49+
go.transform.Rotate(rotation.Value * Time.deltaTime, Space.World);
50+
}
51+
}
52+
}
53+
}

Actions/BoolExchange.cs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
2+
3+
using UnityEngine;
4+
5+
namespace HutongGames.PlayMaker.Actions
6+
{
7+
[ActionCategory("Advanced Actions")]
8+
[Tooltip("Sets an Array of bools to the opposite of the parent bool.")]
9+
public class BoolExchange : FsmStateAction
10+
{
11+
[RequiredField]
12+
public FsmBool parentBool;
13+
14+
[ActionSection("Data")]
15+
16+
[CompoundArray("Count", "boolVariable", "boolValue")]
17+
18+
[UIHint(UIHint.Variable)]
19+
public FsmBool[] boolVariable;
20+
public FsmBool[] boolValue;
21+
22+
public override void OnEnter()
23+
{
24+
25+
DoBoolExchange();
26+
27+
Finish();
28+
29+
}
30+
31+
void DoBoolExchange() {
32+
33+
var currentBool = true;
34+
35+
if(parentBool.Value == true) {
36+
currentBool = false;
37+
}
38+
if(parentBool.Value == false) {
39+
currentBool = true;
40+
}
41+
42+
for(int i = 0;i<boolVariable.Length;i++) {
43+
44+
boolValue[i].Value = currentBool;
45+
boolVariable[i].Value = boolValue[i].Value;
46+
47+
}
48+
49+
}
50+
}
51+
}

Actions/ClockTimer.cs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) 2014 F. Rick Reich.
2+
3+
using UnityEngine;
4+
using System;
5+
using System.Collections;
6+
7+
namespace HutongGames.PlayMaker.Actions
8+
{
9+
[ActionCategory("Advanced Actions")]
10+
[Tooltip("Create an analog clock using system date time.")]
11+
public class ClockTimer : FsmStateAction
12+
{
13+
14+
public FsmInt hours;
15+
16+
public FsmInt minutes;
17+
18+
public FsmInt seconds;
19+
20+
public FsmInt milliseconds;
21+
22+
public FsmGameObject hoursGameObject;
23+
24+
public FsmGameObject minutesGameObject;
25+
26+
public FsmGameObject secondsGameObject;
27+
28+
public FsmGameObject millisecondsGameObject;
29+
30+
public bool everyFrame;
31+
32+
public bool debug;
33+
34+
public override void OnEnter()
35+
{
36+
DoTimer();
37+
38+
if (!everyFrame)
39+
Finish();
40+
}
41+
42+
public override void OnUpdate()
43+
{
44+
DoTimer();
45+
}
46+
47+
void DoTimer() {
48+
49+
TimeSpan timespan = DateTime.Now.TimeOfDay;
50+
51+
DateTime time = DateTime.Now;
52+
53+
var hoursToDegrees = 360f / 12f;
54+
var minutesToDegrees = 360f / 60f;
55+
var secondsToDegrees = 360f / 60f;
56+
57+
var hoursObject = hoursGameObject.Value;
58+
var minutesObject = minutesGameObject.Value;
59+
var secondsObject = secondsGameObject.Value;
60+
var millsecondsObject = millisecondsGameObject.Value;
61+
62+
milliseconds.Value = int.Parse(DateTime.Now.ToString("fff"));
63+
seconds.Value = int.Parse(DateTime.Now.ToString("ss"));
64+
minutes.Value = int.Parse(DateTime.Now.ToString("mm"));
65+
hours.Value = int.Parse(DateTime.Now.ToString("hh"));
66+
67+
68+
hoursObject.transform.localRotation = Quaternion.Euler(0f, 0f, (float)timespan.TotalHours * -hoursToDegrees);
69+
minutesObject.transform.localRotation = Quaternion.Euler(0f, 0f, (float)timespan.TotalMinutes * -minutesToDegrees);
70+
secondsObject.transform.localRotation = Quaternion.Euler(0f, 0f, time.Second * -secondsToDegrees);
71+
millsecondsObject.transform.localRotation = Quaternion.Euler(0f, 0f, (float)timespan.TotalSeconds * -secondsToDegrees);
72+
73+
if (debug)
74+
{
75+
Debug.DrawLine(hoursObject.transform.position, hoursObject.transform.position + hoursObject.transform.up * 1.5f, Color.yellow);
76+
Debug.DrawLine(minutesObject.transform.position, minutesObject.transform.position + minutesObject.transform.up * 1.5f, Color.yellow);
77+
Debug.DrawLine(secondsObject.transform.position, secondsObject.transform.position + secondsObject.transform.up * 1.5f, Color.yellow);
78+
Debug.DrawLine(millsecondsObject.transform.position, millsecondsObject.transform.position + millsecondsObject.transform.up * 1.5f, Color.red);
79+
}
80+
81+
}
82+
}
83+
}

Actions/ConvertUnitsToImperials.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2014 F. Rick Reich.
2+
3+
using UnityEngine;
4+
using System.Collections;
5+
6+
namespace HutongGames.PlayMaker.Actions
7+
{
8+
[ActionCategory("Advanced Actions")]
9+
[Tooltip("Converts a float value to Imperial units.")]
10+
public class ConvertUnitsToImperials : FsmStateAction
11+
{
12+
13+
public enum Unit
14+
{
15+
Inch,
16+
Foot,
17+
Yard,
18+
Mile
19+
}
20+
21+
[RequiredField]
22+
public FsmFloat UnitVariable;
23+
24+
public Unit SelectedUnit;
25+
26+
[RequiredField]
27+
public FsmFloat CalculatedValue;
28+
29+
public bool everyFrame;
30+
31+
public override void Reset()
32+
{
33+
UnitVariable = null;
34+
everyFrame = false;
35+
}
36+
37+
public override void OnEnter()
38+
{
39+
DoCalculate();
40+
41+
if (!everyFrame)
42+
Finish();
43+
}
44+
45+
public override void OnUpdate()
46+
{
47+
DoCalculate();
48+
}
49+
50+
void DoCalculate() {
51+
52+
switch (SelectedUnit)
53+
{
54+
case Unit.Inch:
55+
CalculatedValue.Value = UnitVariable.Value * 39.37f;
56+
break;
57+
58+
case Unit.Foot:
59+
CalculatedValue.Value = UnitVariable.Value * 3.28f;
60+
break;
61+
62+
case Unit.Yard:
63+
CalculatedValue.Value = UnitVariable.Value * 1.09f;
64+
break;
65+
66+
case Unit.Mile:
67+
CalculatedValue.Value = UnitVariable.Value * 0.00062f;
68+
break;
69+
}
70+
71+
}
72+
73+
}
74+
}

0 commit comments

Comments
 (0)