playMaker

Author Topic: Mega-Fiers morph percent  (Read 6963 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15398
  • Official Playmaker Support
    • View Profile
Mega-Fiers morph percent
« on: June 08, 2012, 05:32:59 AM »
Hi,

 Following this post:
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

dihcro

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: Mega-Fiers morph percent
« Reply #1 on: January 11, 2013, 08:29:34 PM »
Wa!!!Thank you very much for solve this problem!It's quite easy to make model morph

OliverMiguel

  • Playmaker Newbie
  • *
  • Posts: 1
    • View Profile
Re: Mega-Fiers morph percent
« Reply #2 on: January 13, 2013, 04:53:37 AM »
Thanks for the full code, it will gonna be very helpful for all the beginners...

Adam Z

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: Mega-Fiers morph percent
« Reply #3 on: April 04, 2013, 10:48:08 AM »
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? :)
« Last Edit: April 04, 2013, 02:33:50 PM by adamzeliasz »

Adam Z

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: Mega-Fiers morph percent
« Reply #4 on: April 05, 2013, 08:16:34 AM »
Anyone?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15398
  • Official Playmaker Support
    • View Profile
Re: Mega-Fiers morph percent
« Reply #5 on: April 08, 2013, 11:10:20 PM »
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

Adam Z

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: Mega-Fiers morph percent
« Reply #6 on: April 09, 2013, 06: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!!