playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Krileon

Pages: 1 [2] 3 4 ... 8
16
PlayMaker Help / Re: Action name separate from class name
« on: April 14, 2014, 01:36:53 PM »
I can't think of it off the top of my head but I thought I found an action that did this a while back (maybe not, haven't had my coffee yet)... I'll see if I can find it.

If you manage to find it that'd be great. I really don't want to have to change my classes, but right now some new actions have funky action names as seen above. Would be awesome if this is available now or can at least be added soon.

17
Share New Actions / Re: String Regex Is Match
« on: April 13, 2014, 03:26:09 PM »
New String Regex Match action can be found below.

http://hutonggames.com/playmakerforum/index.php?topic=7006.0

18
Share New Actions / Re: String Regex Replace
« on: April 13, 2014, 03:25:57 PM »
New String Regex Match action can be found below.

http://hutonggames.com/playmakerforum/index.php?topic=7006.0

19
Share New Actions / String Regex Match
« on: April 13, 2014, 03:25:36 PM »
Yet another string regex action. This one, similar to String Regex Is Match, can do a true/false event based off the match, but it also stores the result of the match to another string variable instead of storing true/false to boolean.

[edit] You can now get it directly from the Ecosystem

StringRegexMatch

Code: [Select]
using UnityEngine;
using System.Text.RegularExpressions;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexMatch : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public RegexOptions[] options;
[UIHint(UIHint.Variable)]
public FsmString storeMatch;
[UIHint(UIHint.Variable)]
public FsmEvent trueEvent;
[UIHint(UIHint.Variable)]
public FsmEvent falseEvent;
public bool everyFrame;

public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
options = new RegexOptions[0];
storeMatch = null;
trueEvent = null;
falseEvent = null;
everyFrame = false;
}

public override void OnEnter() {
DoAction();

if ( ! everyFrame ) {
Finish();
}
}

public override void OnUpdate() {
DoAction();
}

void DoAction() {
Match match = null;

if ( options.Length > 0 ) {
RegexOptions optionsBit = 0;

foreach ( RegexOptions option in options ) {
optionsBit |= option;
}

match = Regex.Match( stringVariable.Value, regex.Value, optionsBit );
} else {
match = Regex.Match( stringVariable.Value, regex.Value );
}

storeMatch.Value = match.Value;

if ( match.Success ) {
if ( trueEvent != null ) {
Fsm.Event( trueEvent );
}
} else {
if ( falseEvent != null ) {
Fsm.Event( falseEvent );
}
}
}
}
}

You can find my other String Regex actions as follows.

String Regex Is Match:
http://hutonggames.com/playmakerforum/index.php?topic=7005.0

String Regex Replace:
http://hutonggames.com/playmakerforum/index.php?topic=7004.0

20
Share New Actions / Re: String Regex Replace
« on: April 13, 2014, 03:15:13 PM »
Ok, created a String Regex Is Match action, which you can find below.

http://hutonggames.com/playmakerforum/index.php?topic=7005.0

21
Share New Actions / String Regex Is Match
« on: April 13, 2014, 03:14:31 PM »
Just sharing another regex action. This one fires a true/false event based off the regex match or just stores the result of the match (you pick).

[Edit] Youc an get it directly from the Ecosystem

StringRegexMatch

Code: [Select]
using UnityEngine;
using System.Text.RegularExpressions;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexIsMatch : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public RegexOptions[] options;
[UIHint(UIHint.Variable)]
public FsmBool storeMatch;
[UIHint(UIHint.Variable)]
public FsmEvent trueEvent;
[UIHint(UIHint.Variable)]
public FsmEvent falseEvent;
public bool everyFrame;

public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
options = new RegexOptions[0];
storeMatch = null;
trueEvent = null;
falseEvent = null;
everyFrame = false;
}

public override void OnEnter() {
DoAction();

if ( ! everyFrame ) {
Finish();
}
}

public override void OnUpdate() {
DoAction();
}

void DoAction() {
if ( options.Length > 0 ) {
RegexOptions optionsBit = 0;

foreach ( RegexOptions option in options ) {
optionsBit |= option;
}

storeMatch.Value = Regex.IsMatch( stringVariable.Value, regex.Value, optionsBit );
} else {
storeMatch.Value = Regex.IsMatch( stringVariable.Value, regex.Value );
}

if ( storeMatch.Value ) {
if ( trueEvent != null ) {
Fsm.Event( trueEvent );
}
} else {
if ( falseEvent != null ) {
Fsm.Event( falseEvent );
}
}
}
}
}

For my String Regex Replace action please see the below topic.

http://hutonggames.com/playmakerforum/index.php?topic=7004.0

22
Share New Actions / String Regex Replace
« on: April 13, 2014, 02:57:31 PM »
I wanted to use REGEX for my replacement usage so I created a String Regex Replace. Thought I'd go ahead and share it as it's a pretty generic and useful action.

[edit] It's now available directly on the Ecosystem

StringRegexReplace

Code: [Select]
using UnityEngine;
using System.Text.RegularExpressions;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexReplace : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public FsmString with;
public RegexOptions[] options;
[RequiredField, UIHint(UIHint.Variable)]
public FsmString storeResult;
public bool everyFrame;

public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
with = new FsmString { Value = "" };
options = new RegexOptions[0];
storeResult = null;
everyFrame = false;
}

public override void OnEnter() {
DoAction();

if ( ! everyFrame ) {
Finish();
}
}

public override void OnUpdate() {
DoAction();
}

void DoAction() {
if ( options.Length > 0 ) {
RegexOptions optionsBit = 0;

foreach ( RegexOptions option in options ) {
optionsBit |= option;
}

storeResult.Value = Regex.Replace( stringVariable.Value, regex.Value, with.Value, optionsBit );
} else {
storeResult.Value = Regex.Replace( stringVariable.Value, regex.Value, with.Value );
}
}
}
}

I'll probably be adding other regex actions as well such as Match. Anyway, hope others find as much use out of this as I have.

23
PlayMaker Help / Action name separate from class name
« on: April 12, 2014, 12:53:08 PM »
It's possibly to specify a category string name, but it's not possible from what I can tell to specify an action string name. It always uses the class name and the algorithm used to generate a spaced name from class isn't what I'd prefer. Is it possible for such a feature to be implemented? I'd really like to be able to supply my own string name instead of always using the class name.

For example the below is not very sightly.

Class: EZSave2SaveVariable
Name: EZ Save 2Save Variable
Wanted: EZSave2 Save Variable

I prefix all of my classes to avoid conflicts and make it easier to see at a glance what action belongs to what when it's in use. This works really well, but I've to be annoyingly creative with my class names so they don't look terrible as the action name.

24
PlayMaker Help / Re: FsmProperty limitations, workaround?
« on: February 18, 2014, 08:47:35 AM »
I'm using JSON .Net asset from the asset store as it provides the best implementation compared to JSON .Net free DLL. It works perfectly fine and I'm already working on custom converters to handle data properly (my PM action can filter to or exclude object properties as well). So far I've JSON for an object property (good for array object properties or just to JSON a single property) and I'll be working on others to encode entire components, etc..

No, I had no plans to release it. I don't have time, or even the desire, to provide support so if I released it there's a bit of obligation to do so. It also uses a custom converter I wrote so that'd need to be released too.

There's also a current bug with it handling Texture2D properties that I'm working on resolving (it should encode it to name property, but fails).

I also plan to extend this to handle arrays of data, because I hate having to use a proxy for array maker. If I encode/decode on the fly it should be pretty reasonable to have arrays of data. Obviously I can't encode everything, but it should work for most cases (like inventory data, etc..).

25
PlayMaker Help / Re: FsmProperty limitations, workaround?
« on: February 16, 2014, 06:26:07 PM »
Ok, I just used an FsmString and grabbed the property from the object based off the string. It's not as elegant as a nice dropdown, but it'll work.

26
PlayMaker Help / FsmProperty limitations, workaround?
« on: February 16, 2014, 11:01:39 AM »
FsmProperty only displays the properties that PM can store as FSM variables. My issue is I don't want to store it as an FSM variable. I have a playmaker action for my JSON.Net implementation that takes property and encodes it. All I want to do is send that property to the FSM. I don't actually want to store it as an FSM variable (I'll store the JSON string output by the FSM).

How can I have a property dropdown that shows all of a components properties regardless if PM can store them or not? Can I implement my own type like FsmProperty that'd handle this? If so can you provide an example? I decompiled the FsmProperty, but am unsure if copy/paste/modify into a new script will even work.

Edit: Ok, copy/paste/modify of FsmProperty doesn't work for sure. So I guess that's not an option unfortunately.

27
Share New Actions / Re: Realtime Cubemaps
« on: January 25, 2014, 01:39:13 PM »
Please "Realtime Cubemaps" give up the sample files designed to appreciate it.
What sample files? It's just an action that adds the camera, creates the cubemap, then maps it to your material. Use it however you want.


It needs a mesh renderer (or any renderer) component on the target object and updates the Reflection Cubemap in its material.

That's exactly what it's supposed to do.


But it doesn't update the actual material which means it's only good for the one target object... That's still pretty cool, but seems like it has limited application when you can only target one object. If this had fed back into the original material then it would be significantly more capable.
I don't feed into the material, because then it modifies the material. The point is for it to function at runtime only without modifying the material (prefab by prefab usage). If you want it to feed into the material then modify it to do so. Setting it to run once is the best way to have prefabs that you can reuse anywhere with a accurate cubemap based off their location. The alternative is you need to make a cubemap for every single prefab for each location it's going to be in, which is annoying to do. If you feed into the material then you change the cubemap for every prefab using that material, which doesn't make sense if those prefabs are in completely different locations.

28
Share New Actions / Realtime Cubemaps
« on: December 31, 2013, 09:41:37 AM »
THIS WILL ONLY WORK IN UNITY PRO

Had to make that warning pretty clear. This is a Unity limitation so there is no workaround for this.

Ok, so I've been looking into realtime reflections and the best I could find at the moment is realtime cubemap generation. The alternative is a post processing affect that pulls from buffer, but that's above my current experience.

The below PlayMaker action will generate cubemaps at realtime for the target object and update the shader as needed. It has built in optimization to prevent performance from dieing. Basically what it does is on start will populate all 6 sides then every 5 frames it'll populate 1 face. This keeps performance from going to crap while still giving realtime reflections. You can customize a lot of the camera properties from the playmaker action as well as debug it (helps to make sure your positioning is correct).

The camera generated to pull the cubemaps is added as a child object of the target object so all position/rotation supplied is local. This lets the cubemap generation follow the object (cars, marbles, etc..).

The action can also be used as a fire and forget usage. Meaning it'll generate the 6 sides then destroy the camera and end the action. This is good for static objects that you're reusing throughout your level and need each with their own cubemap.

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.Camera)]
public class CameraRenderToCubemap : FsmStateAction {
[RequiredField]
public FsmOwnerDefault targetGameObject;
[ActionSection("Camera")]
public FsmVector3 position;
public FsmQuaternion rotation;
public FsmColor backgroundColor;
[RequiredField, HasFloatSlider(1,179)]
public FsmFloat fieldOfView;
[RequiredField]
public FsmFloat nearCipPlane;
[RequiredField]
public FsmFloat farClipPlane;
public FsmBool HDR;
[ActionSection("Culling")]
[UIHint(UIHint.Layer)]
public FsmInt[] cullingMask;
public FsmBool invertMask;
[ActionSection("Cubemap")]
[RequiredField]
public FsmInt cubemapSize;
[RequiredField]
public FsmString[] namedCubemaps;
[ActionSection("Realtime")]
public bool everyFrame;
public int frameDelay;
public bool oneFacePerFrame;
public bool debugCamera;

private GameObject target;
private GameObject camera;
private RenderTexture texture;
private int frames;
private int[] faces;
private int face;

public override void Reset() {
targetGameObject = null;
position = new FsmVector3 { UseVariable = true };
rotation = new FsmQuaternion { UseVariable = true };
backgroundColor = new FsmColor { UseVariable = true };
fieldOfView = new FsmFloat { Value = 60f };
nearCipPlane = new FsmFloat { Value = 0.01f };
farClipPlane = new FsmFloat { Value = 100f };
HDR = new FsmBool { Value = false };
namedCubemaps = new FsmString[1];
namedCubemaps[0] = new FsmString { Value = "_Cube" };
cubemapSize = new FsmInt { Value = 128 };
cullingMask = new FsmInt[0];
invertMask = false;
everyFrame = true;
frameDelay = 0;
oneFacePerFrame = true;
debugCamera = false;

faces = new int[6];
faces[0] = ( 1 << (int) CubemapFace.NegativeX ); // 2
faces[1] = ( 1 << (int) CubemapFace.NegativeY ); // 8
faces[2] = ( 1 << (int) CubemapFace.NegativeZ ); // 32
faces[3] = ( 1 << (int) CubemapFace.PositiveX ); // 1
faces[4] = ( 1 << (int) CubemapFace.PositiveY ); // 4
faces[5] = ( 1 << (int) CubemapFace.PositiveZ ); // 16

frames = 0;
face = 0;
}

public override void OnEnter() {
target = Fsm.GetOwnerDefaultTarget( targetGameObject );

if ( target == null ) {
return;
}

camera = new GameObject( "CubemapCamera", typeof( Camera ) );
camera.hideFlags = ( debugCamera ? HideFlags.DontSave : HideFlags.HideAndDontSave );
camera.transform.parent = target.transform;
camera.transform.localPosition = position.Value;
camera.transform.localRotation = rotation.Value;

camera.camera.backgroundColor = backgroundColor.Value;
camera.camera.cullingMask = ActionHelpers.LayerArrayToLayerMask( cullingMask, invertMask.Value );
camera.camera.fieldOfView = fieldOfView.Value;
camera.camera.nearClipPlane = Mathf.Min( 0.01f, nearCipPlane.Value );
camera.camera.farClipPlane = farClipPlane.Value;
camera.camera.hdr = HDR.Value;
camera.camera.enabled = false;

texture = new RenderTexture( cubemapSize.Value, cubemapSize.Value, 16 );
texture.isCubemap = true;
texture.hideFlags = HideFlags.HideAndDontSave;

if ( namedCubemaps.Length > 0 ) foreach ( FsmString namedCubemap in namedCubemaps ) {
target.renderer.material.SetTexture( namedCubemap.Value, texture );
}

camera.camera.RenderToCubemap( texture, 63 );

if ( ! everyFrame ) {
Object.Destroy( camera );
Finish();
}
}

public override void OnLateUpdate() {
if ( ( target == null ) || ( camera == null ) ) {
return;
}

if ( frameDelay > 0 ) {
if ( frames == frameDelay ) {
frames = 0;
} else {
frames++;
return;
}
}

if ( oneFacePerFrame ) {
camera.camera.RenderToCubemap( texture, faces[face] );

if ( face == 5 ) {
face = 0;
} else {
face++;
}
} else {
camera.camera.RenderToCubemap( texture, 63 );
}
}

public override void OnExit() {
if ( camera == null ) {
return;
}

Object.Destroy( camera );
}
}
}

Please understand I do not have time to provide support. I'm providing this as it was a nightmare for me to figure this out on my own and Unity documentation sucks. So hopefully this will reduce the pain and suffering for another.

29
PlayMaker Help / Re: Add FSM Template at Runtime?
« on: December 28, 2013, 01:13:34 PM »
Upgraded Add Fsm Template even more. Now it can return and store the fsm component object. It can also send an event if the template already exists or when the template is replaced. There's also a new variable under the replace event to force replace to not destroy the fsm. The primary usage for that is if you want your own cleanup inside of a different fsm, but you still want it to add the fsm.

Code: [Select]
using System.Collections.Generic;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.StateMachine)]
public class AddFsmTemplate : FsmStateAction {
[RequiredField]
public FsmOwnerDefault gameObject;
[RequiredField]
public FsmTemplate template;
public FsmString name;
public FsmBool active;
public FsmBool unique;
public FsmBool replace;
[CompoundArray("Variables", "Name", "Variable")]
[RequiredField]
public FsmString[] variableNames;
[RequiredField]
public FsmVar[] variables;
[ObjectType(typeof(PlayMakerFSM)), UIHint(UIHint.Variable)]
public FsmObject storeComponent;
[ActionSection("Exists Event")]
public FsmEventTarget existsEventTarget;
public FsmString existsSendEvent;
[ActionSection("Replace Event")]
public FsmBool doNotDestroy;
public FsmEventTarget replaceEventTarget;
public FsmString replaceSendEvent;

private GameObject previousGo;
private List<PlayMakerFSM> fsms;

public override void Reset() {
gameObject = null;
template = null;
name = new FsmString { UseVariable = true };
active = new FsmBool { Value = true };
unique = new FsmBool { Value = false };
replace = new FsmBool { Value = false };
variableNames = new FsmString[0];
variables = new FsmVar[0];
storeComponent = null;
existsEventTarget = null;
existsSendEvent = null;
doNotDestroy = new FsmBool { Value = false };
replaceEventTarget = null;
replaceSendEvent = null;
}

public override void OnEnter() {
var go = Fsm.GetOwnerDefaultTarget( gameObject );

if ( go == null ) {
return;
}

bool exists = false;

if ( ( ! unique.Value ) || replace.Value ) {
if ( go != previousGo ) {
fsms = new List<PlayMakerFSM>();

fsms.AddRange( go.GetComponents<PlayMakerFSM>() );

previousGo = go;
}

if ( fsms.Count > 0 ) foreach ( PlayMakerFSM fsm in fsms ) {
if ( ( ( name.Value != "" ) && ( fsm.FsmName == name.Value ) ) || ( ( fsm.FsmTemplate != null ) && ( fsm.FsmTemplate.name == template.name ) ) ) {
if ( replace.Value ) {
if ( replaceSendEvent.Value != "" ) {
Fsm.Event( replaceEventTarget, replaceSendEvent.Value );
}

if ( ! doNotDestroy.Value ) {
Object.Destroy( fsm );
}
} else {
storeComponent.Value = fsm;
exists = true;
}
}
}
}

if ( ! exists ) {
PlayMakerFSM newFsm = go.AddComponent<PlayMakerFSM>();

if ( name.Value != "" ) {
newFsm.FsmName = name.Value;
}

if ( ( ! active.Value ) || ( variableNames.Length > 0 ) ) {
newFsm.enabled = false;
}

newFsm.SetFsmTemplate( template );

if ( variableNames.Length > 0 ) {
if ( variableNames.Length > 0 ) for ( int i = 0; i < variableNames.Length; i++ ) {
if ( ! variableNames[i].IsNone ) {
NamedVariable target = newFsm.Fsm.Variables.GetVariable( variableNames[i].Value );

if ( target != null ) {
variables[i].ApplyValueTo( target );
}
}
}

if ( active.Value && ( ! newFsm.enabled ) ) {
newFsm.enabled = true;
}
}

if ( ( ! unique.Value ) || replace.Value ) {
fsms.Add( newFsm );
}

storeComponent.Value = newFsm;
} else {
if ( existsSendEvent.Value != "" ) {
Fsm.Event( existsEventTarget, existsSendEvent.Value );
}
}

Finish();
}
}
}

30
PlayMaker Help / Re: Add FSM Template at Runtime?
« on: December 27, 2013, 11:07:41 PM »
Upgraded Add Fsm Template with a variable to replace a matching template. This basically can be used to refresh a buff, etc..

Code: [Select]
using System.Collections.Generic;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.StateMachine)]
public class AddFsmTemplate : FsmStateAction {
[RequiredField]
public FsmOwnerDefault gameObject;
[RequiredField]
public FsmTemplate template;
public FsmString name;
public FsmBool active;
public FsmBool unique;
public FsmBool replace;
[CompoundArray("Variables", "Name", "Variable")]
[RequiredField]
public FsmString[] variableNames;
[RequiredField]
public FsmVar[] variables;

private GameObject previousGo;
private List<PlayMakerFSM> fsms;

public override void Reset() {
gameObject = null;
template = null;
name = new FsmString { UseVariable = true };
active = new FsmBool { Value = true };
unique = new FsmBool { Value = false };
replace = new FsmBool { Value = false };
variableNames = new FsmString[0];
variables = new FsmVar[0];
}

public override void OnEnter() {
var go = Fsm.GetOwnerDefaultTarget( gameObject );

if ( go == null ) {
return;
}

bool exists = false;

if ( ( ! unique.Value ) || replace.Value ) {
if ( go != previousGo ) {
fsms = new List<PlayMakerFSM>();

fsms.AddRange( go.GetComponents<PlayMakerFSM>() );

previousGo = go;
}

if ( fsms.Count > 0 ) foreach ( PlayMakerFSM fsm in fsms ) {
if ( ( ( name.Value != "" ) && ( fsm.FsmName == name.Value ) ) || ( ( fsm.FsmTemplate != null ) && ( fsm.FsmTemplate.name == template.name ) ) ) {
if ( replace.Value ) {
Object.Destroy( fsm );
} else {
exists = true;
}
}
}
}

if ( ! exists ) {
PlayMakerFSM newFsm = go.AddComponent<PlayMakerFSM>();

if ( name.Value != "" ) {
newFsm.FsmName = name.Value;
}

if ( ( ! active.Value ) || ( variableNames.Length > 0 ) ) {
newFsm.enabled = false;
}

newFsm.SetFsmTemplate( template );

if ( variableNames.Length > 0 ) {
if ( variableNames.Length > 0 ) for ( int i = 0; i < variableNames.Length; i++ ) {
if ( ! variableNames[i].IsNone ) {
NamedVariable target = newFsm.Fsm.Variables.GetVariable( variableNames[i].Value );

if ( target != null ) {
variables[i].ApplyValueTo( target );
}
}
}

if ( active.Value && ( ! newFsm.enabled ) ) {
newFsm.enabled = true;
}
}

if ( ( ! unique.Value ) || replace.Value ) {
fsms.Add( newFsm );
}
}

Finish();
}
}
}

Pages: 1 [2] 3 4 ... 8