This is my page for storing playmaker scripts for later. I'll update stuff as I see fit. And yeah I really should explain the scripts and reformat them to look pretty....
Mecanim Set Value Script
//Last edit 5-2-14 Ashley Hooper
//Used to set a value on the mecanim animation such as bool, float, int, etc...
using UnityEngine;
using System.Collections;
public enum ValueType {_Bool, _Float, _Int, _Trigger};
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Changes a value in the Mecanim animation.")]
public class MecanimSetValue : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animation))]
[Tooltip("Game Object to play the animation on.")]
public FsmOwnerDefault gameObject;
private Animator _animator;
public string valueName;
public ValueType valueType;
public FsmBool boolValue;
public FsmFloat floatValue;
public FsmInt intValue;
[Tooltip("Exit Event")]
public FsmEvent Exit;
#region OnEnter
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
var a = Fsm.GetOwnerDefaultTarget(gameObject);
_animator = a.GetComponent("Animator") as Animator;
}
if(_animator == null){
Debug.Log ("No animator component found on gameObject!");
}
}
#endregion
#region onUpdate
public override void OnUpdate()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
var a = Fsm.GetOwnerDefaultTarget(gameObject);
_animator = a.GetComponent("Animator") as Animator;
}
switch(valueType){
case ValueType._Bool:
_animator.SetBool(valueName, boolValue.Value);
Fsm.Event(Exit);
break;
case ValueType._Float:
_animator.SetFloat(valueName, floatValue.Value);
Fsm.Event(Exit);
break;
case ValueType._Int:
_animator.SetInteger(valueName, intValue.Value);
Fsm.Event(Exit);
break;
default:
break;
//trigger events here...
}
}
#endregion
#region ErrorCheck
public override string ErrorCheck()
{
if (gameObject == null)
return "gameObject is null!";
return "";
}
#endregion
}
}
Bool Compare
//Ashley Hooper 5-14-14
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends Events based state of bool")]
public class BoolCompare : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The bool.")]
public FsmBool Bool;
[Tooltip("Event sent if bool is true.")]
public FsmEvent True;
[Tooltip("Event sent if bool is false.")]
public FsmEvent False;
[Tooltip("Repeat every frame. Useful if the variables are changing and you're waiting for a particular result.")]
public bool everyFrame;
public override void Reset()
{
Bool = false;
True = null;
False = null;
everyFrame = false;
}
public override void OnEnter()
{
DoCompare();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoCompare();
}
void DoCompare()
{
if (Bool.Value == true)
{
Fsm.Event(True);
return;
}
if (Bool.Value == false)
{
Fsm.Event(False);
}
}
public override string ErrorCheck()
{
if (FsmEvent.IsNullOrEmpty(True) &&
FsmEvent.IsNullOrEmpty(False))
return "Action sends no events!";
return "";
}
}
}
Mecanim Set Value Script
//Last edit 5-2-14 Ashley Hooper
//Used to set a value on the mecanim animation such as bool, float, int, etc...
using UnityEngine;
using System.Collections;
public enum ValueType {_Bool, _Float, _Int, _Trigger};
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Changes a value in the Mecanim animation.")]
public class MecanimSetValue : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animation))]
[Tooltip("Game Object to play the animation on.")]
public FsmOwnerDefault gameObject;
private Animator _animator;
public string valueName;
public ValueType valueType;
public FsmBool boolValue;
public FsmFloat floatValue;
public FsmInt intValue;
[Tooltip("Exit Event")]
public FsmEvent Exit;
#region OnEnter
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
var a = Fsm.GetOwnerDefaultTarget(gameObject);
_animator = a.GetComponent("Animator") as Animator;
}
if(_animator == null){
Debug.Log ("No animator component found on gameObject!");
}
}
#endregion
#region onUpdate
public override void OnUpdate()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
var a = Fsm.GetOwnerDefaultTarget(gameObject);
_animator = a.GetComponent("Animator") as Animator;
}
switch(valueType){
case ValueType._Bool:
_animator.SetBool(valueName, boolValue.Value);
Fsm.Event(Exit);
break;
case ValueType._Float:
_animator.SetFloat(valueName, floatValue.Value);
Fsm.Event(Exit);
break;
case ValueType._Int:
_animator.SetInteger(valueName, intValue.Value);
Fsm.Event(Exit);
break;
default:
break;
//trigger events here...
}
}
#endregion
#region ErrorCheck
public override string ErrorCheck()
{
if (gameObject == null)
return "gameObject is null!";
return "";
}
#endregion
}
}
Bool Compare
//Ashley Hooper 5-14-14
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends Events based state of bool")]
public class BoolCompare : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The bool.")]
public FsmBool Bool;
[Tooltip("Event sent if bool is true.")]
public FsmEvent True;
[Tooltip("Event sent if bool is false.")]
public FsmEvent False;
[Tooltip("Repeat every frame. Useful if the variables are changing and you're waiting for a particular result.")]
public bool everyFrame;
public override void Reset()
{
Bool = false;
True = null;
False = null;
everyFrame = false;
}
public override void OnEnter()
{
DoCompare();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoCompare();
}
void DoCompare()
{
if (Bool.Value == true)
{
Fsm.Event(True);
return;
}
if (Bool.Value == false)
{
Fsm.Event(False);
}
}
public override string ErrorCheck()
{
if (FsmEvent.IsNullOrEmpty(True) &&
FsmEvent.IsNullOrEmpty(False))
return "Action sends no events!";
return "";
}
}
}