Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: vonchor on September 21, 2011, 11:30:30 AM

Title: Some more actions of various types
Post by: vonchor on September 21, 2011, 11:30:30 AM
Here are a few more actions:

1. GetPointInGameObject: tests to see if a point is inside a GO's renderer's bounds.
2.  RWFloatArray, RWIntArray,StringArray,TextureArray,Vec3Array.  Allow indexing into an array of preset values (as input via the inspector) or into a pseudo-array of individual variables of these types. The "RW" actions allow reading or writing from the array elements. Note that use of the RW actions in the "W" mode when the array is preset values (as opposed to actual variables) is undefined. Not sure how to test for the preset/variable mode.

The "array" actions only simulate arrays. They don't create any variables. If (for example) you create a bunch of strings as FSM variables you can use StringArray to access an indexed "member" of that set. Likewise, if you create a bunch of Ints you can use RWIntArray to read or write them. If you use these actions in the mode where you enter values into the action inspector then you can only use the values set in an action in that particular action. Hope this makes sense  ;D

DO NOT set the write checkbox in the "RW" actions unless you're indexing into actual variables named in the variable inspector. Writing to "inspector variables" is probably like crossing the streams in GhostBusters or something like that  :)

Code: [Select]
// Jeff Sasmor, AKA Vonchor. Sept 2011

using System;

using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

    [ActionCategory(ActionCategory.GameObject)]

    [Tooltip("Tests if a targetPoint is inside a GO's renderer's bounds")]

public class GetPointInGameObject : FsmStateAction

{

[RequiredField]

[CheckForComponent(typeof(Renderer))]

public FsmOwnerDefault gameObject;

[RequiredField]

public FsmVector3 targetPoint;

[UIHint(UIHint.Variable)]

[RequiredField]

public FsmBool boolVariable;





public override void Reset()

{

gameObject = null;

targetPoint = null;

boolVariable = null;





}



public override void OnEnter()

{

            if (gameObject.OwnerOption == OwnerDefaultOption.UseOwner)

                ChkPtInside(Owner);

            else

                ChkPtInside(gameObject.GameObject.Value);

           

            Finish();

}



        void ChkPtInside(GameObject go)

{

Vector3 testVec = new Vector3(targetPoint.Value.x,targetPoint.Value.y,targetPoint.Value.z);



if (go == null) return;

            if (go.renderer == null)

            {   

Debug.LogError("Missing Renderer in GetPointInGameObject!");

                return;

            }



            boolVariable.Value = go.renderer.bounds.Contains(testVec);



    }

}

 

}

Code: [Select]
// Jeff Sasmor, AKA Vonchor. Sept 2011



using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

[ActionCategory(ActionCategory.Math)]

[Tooltip("R or W Index into an array of floats. Index is 0-based.")]

public class RWFloatArray : FsmStateAction

{

[RequiredField]

public FsmFloat[] floats;

public FsmInt index;

public FsmBool write;

[RequiredField]

[UIHint(UIHint.Variable)]

public FsmFloat io;





public override void Reset()

{

floats = new FsmFloat[3];

io = null;

write = false;

index = 0;



}



public override void OnEnter()

{

if ((index.Value > floats.Length - 1)) {

Debug.Log("index > # of floats in Action: RWFloatArray");

return;

}

if (write.Value)

floats[index.Value].Value = io.Value;

else

io.Value = floats[index.Value].Value;

Finish();

}



}

}


Code: [Select]
// Jeff Sasmor, AKA Vonchor. Sept 2011



using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

[ActionCategory(ActionCategory.Math)]

[Tooltip("R or W Index into an array of ints. Index is 0-based.")]

public class RWIntArray : FsmStateAction

{

[RequiredField]

public FsmInt[] ints;

public FsmInt index;

public FsmBool write;

[RequiredField]

[UIHint(UIHint.Variable)]

public FsmInt io;





public override void Reset()

{

ints = new FsmInt[3];

io = null;

write = false;

index = 0;



}



public override void OnEnter()

{

if ((index.Value > ints.Length - 1)) {

Debug.Log("index > # of ints in Action: RWIntArray");

return;

}

if (write.Value)

ints[index.Value].Value = io.Value;

else

io.Value = ints[index.Value].Value;

Finish();

}



}

}


Code: [Select]
// Jeff Sasmor, AKA Vonchor. Sept 2011



using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

[ActionCategory(ActionCategory.String)]

[Tooltip("Index into an array of strings. Indexed value stored. Index is 0-based.")]

public class StringArray : FsmStateAction

{

[RequiredField]

public FsmString[] strings;

public FsmInt index;

[RequiredField]

[UIHint(UIHint.Variable)]

public FsmString output;





public override void Reset()

{

strings = new FsmString[3];

output = null;

index = 0;



}



public override void OnEnter()

{

if ((index.Value > strings.Length - 1)) {

Debug.Log("string index > # of strings in Action: StringArray");

return;

}

output.Value = strings[index.Value].Value;

Finish();

}



}

}


Code: [Select]
// Jeff Sasmor, AKA Vonchor. Sept 2011



using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

[ActionCategory(ActionCategory.Material)]

[Tooltip("Index into an array of textures. Indexed value stored. Index is 0-based.")]

public class TextureArray : FsmStateAction

{

[RequiredField]

public FsmTexture[] textures;

public FsmInt index;

[RequiredField]

[UIHint(UIHint.Variable)]

public FsmTexture output;





public override void Reset()

{

textures = new FsmTexture[3];

output = null;

index = 0;



}



public override void OnEnter()

{

if ((index.Value > textures.Length - 1)) {

Debug.Log("string index > # of strings in Action: StringArray");

return;

}

output.Value = textures[index.Value].Value;

Finish();

}



}

}



Code: [Select]
// Jeff Sasmor, AKA Vonchor. Sept 2011



using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

[ActionCategory(ActionCategory.Vector3)]

[Tooltip("Index into an array of strings. Indexed value stored. Index is 0-based.")]

public class Vec3Array : FsmStateAction

{

[RequiredField]

public FsmVector3[] vector3s;

public FsmInt index;

[RequiredField]

[UIHint(UIHint.Variable)]

public FsmVector3 output;





public override void Reset()

{

vector3s = new FsmVector3[3];

output = null;

index = 0;



}



public override void OnEnter()

{

if ((index.Value > vector3s.Length - 1)) {

Debug.Log("index > # of Vector3s in Action: Vector3Array");

return;

}

output.Value = vector3s[index.Value].Value;

Finish();

}



}

}