Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started 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.
// (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 );
}
}
}
}
}
}
// (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
-
Wa!!!Thank you very much for solve this problem!It's quite easy to make model morph
-
Thanks for the full code, it will gonna be very helpful for all the beginners...
-
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? :)
-
Anyone?
-
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
-
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!!