Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on June 08, 2012, 08:32:59 AM

Title: Mega-Fiers morph percent
Post by: jeanfabre on June 08, 2012, 08:32:59 AM
Hi,

 Following this post:
http://hutonggames.com/playmakerforum/index.php?topic=1708.0 (http://hutonggames.com/playmakerforum/index.php?topic=1708.0)


Please find two actions to control morph channels percent, one by channel indexes ( 0 to x), and the other by channels name. You can control only a number of the channels, you don't have to have them all listed.

 It's not bullet proof, meaning if you define two entries with the same channel index, it will conflicts or if you input the wrong name it will fail silently. If you need more robust actions, let me know, but that should do to get you progressing.


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Mega-Fiers")]
[Tooltip("Set MegaMorph percentage for a number of channels using their name reference.")]
public class MegafiersSetMorphPercentByName : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(MegaMorph))]
[Tooltip("The GameObject to check.")]
public FsmOwnerDefault gameObject;

[CompoundArray("Channels", "Name", "Percent")]
public FsmString[] name;
public FsmFloat[] percent;

[Tooltip("Repeat every frame")]
public bool everyFrame;

public override void Reset()
{
gameObject = null;
name = new FsmString[1];
percent = new FsmFloat[1];

everyFrame = false;
}

private MegaMorph megaMorph;

public override void OnEnter()
{


var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
megaMorph = go.GetComponent<MegaMorph>();

if (megaMorph == null)
{
LogError("Missing MegaMorph!");
return;
}

DoSetPercent();

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

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

void DoSetPercent()
{
if ( megaMorph !=null)
{
for (int i = 0; i < name.Length; i++)
{
MegaMorphChan _chan = megaMorph.GetChannel(name[i].Value);
if (_chan != null)
{
int _index = _chan.targ;
float _percent = percent[i].Value ;
if (_percent !=megaMorph.GetPercent(_index) )
megaMorph.SetPercent(_index,_percent );
}
}


}
}
}
}

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Mega-Fiers")]
[Tooltip("Set MegaMorph percentage for a number of channels by their index.")]
public class MegafiersSetMorphPercentByIndex : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(MegaMorph))]
[Tooltip("The GameObject to check.")]
public FsmOwnerDefault gameObject;

[CompoundArray("Channels", "Index", "Percent")]
public FsmInt[] index;
public FsmFloat[] percent;

[Tooltip("Repeat every frame")]
public bool everyFrame;

public override void Reset()
{
gameObject = null;
index = new FsmInt[1];
percent = new FsmFloat[1];

everyFrame = false;
}

private MegaMorph megaMorph;

public override void OnEnter()
{

var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
megaMorph = go.GetComponent<MegaMorph>();

if (megaMorph == null)
{
LogError("Missing MegaMorph!");
return;
}


DoSetPercent();

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

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

void DoSetPercent()
{
if ( megaMorph !=null)
{
for (int i = 0; i < index.Length; i++)
{
int _index = index[i].Value;
float _percent = percent[i].Value ;
if (_percent != megaMorph.GetPercent(_index))
megaMorph.SetPercent(_index,_percent);
}


}
}
}
}

 Bye,

 Jean
Title: Re: Mega-Fiers morph percent
Post by: dihcro on January 11, 2013, 10:29:34 PM
Wa!!!Thank you very much for solve this problem!It's quite easy to make model morph
Title: Re: Mega-Fiers morph percent
Post by: OliverMiguel on January 13, 2013, 06:53:37 AM
Thanks for the full code, it will gonna be very helpful for all the beginners...
Title: Re: Mega-Fiers morph percent
Post by: Adam Z on April 04, 2013, 01:48:08 PM
I added 'Megafiers Set Morph Percent By Name' to my game object with the Mega Morph Attached.

On my camera I have a 'GUI Horizontal Slider', but I dont know how to reference the other FSM Action.

Thoughts? :)
Title: Re: Mega-Fiers morph percent
Post by: Adam Z on April 05, 2013, 11:16:34 AM
Anyone?
Title: Re: Mega-Fiers morph percent
Post by: jeanfabre on April 09, 2013, 02:10:20 AM
Hi,

 It's actually very straight forward, I have attached a scene,

basically, you save the slider value in a float variable and you use this float value in the mprh action under the "percent" property and done.

Bye,

 Jean
Title: Re: Mega-Fiers morph percent
Post by: Adam Z on April 09, 2013, 09:58:02 AM
Hi,

 It's actually very straight forward, I have attached a scene,

basically, you save the slider value in a float variable and you use this float value in the mprh action under the "percent" property and done.

Bye,

 Jean

Perfect, thanks!!