playMaker

Author Topic: [SOLVED]NGUI HUD Text Help needed  (Read 3455 times)

Nazca

  • Playmaker Newbie
  • *
  • Posts: 4
[SOLVED]NGUI HUD Text Help needed
« on: April 09, 2013, 05:33:13 PM »
Hi,

I would like to get NGUI Hud Text plugin to work with Playmaker by invoking its "Add" function, which takes 3 parameters (float, color, float).

Following what have been suggested in this topic http://hutonggames.com/playmakerforum/index.php?topic=1437.0
I gave a try at writing a custom action, but I got stuck in the process. ???

By barely modifying the scripts jeanfabre attached to the above topic, here's what I came up with
MyScriptBridge
Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.ScriptControl)]
[Tooltip("Call MyMethod of MyScript.")]
public class MyScriptBridge : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(MyScript))]
public FsmOwnerDefault gameObject;

public HUDText hudText;
public FsmFloat numericValue;
public FsmColor color;
public FsmFloat fadingDelay;


public override void Reset()
{
hudText = null;
numericValue = null;
color = null;
fadingDelay = null;
result = null;

}

public override void OnEnter()
{
// check that we have MyScript referenced

GameObject go  = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

MyScript myScript = go.GetComponent<MyScript>();

if (myScript == null)
{
return;
}

hudText.Add(numericValue.Value,color.Value,fadingDelay.Value);

Finish();
}


}
}

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

public class MyScript : MonoBehaviour
{
public class Add(float aFloat,Color aColor,float aFloat);

}


I know it might seems obvious to many, but it's paramount for a noob like me.
Could anyone give suggest me how to get it to work?

Thanks in advance! :)
« Last Edit: April 18, 2013, 11:12:25 AM by Nazca »

Nazca

  • Playmaker Newbie
  • *
  • Posts: 4
Re: NGUI HUD Text Help needed
« Reply #1 on: April 18, 2013, 11:11:56 AM »
bump :)

After a few days I was somehow able to put together a custom action which invoke the Add method.

here's the code I used:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.ScriptControl)]
[Tooltip("Call Add of HUDText.")]
public class MyBridge : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(HUDText))]
public FsmOwnerDefault gameObject;

public HUDText hudText;
public FsmInt obj;
public FsmColor c;
public FsmFloat stayDuration;


public override void Reset()
{

obj = null;
c = null;
stayDuration = null;

}

public override void OnEnter()
{
// check that we have MyScript referenced

GameObject go  = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

HUDText hudtext = go.GetComponent<HUDText>();

if (hudtext == null)
{
return;
}

hudText.Add(obj.Value,c.Value,stayDuration.Value);

Finish();
}


}
}

In addition, here's the script I had to attach to the HUDText itself.

Code: [Select]
using UnityEngine;

[RequireComponent(typeof(HUDText))]
public class test2 : MonoBehaviour
{
void Update ()
{

HUDText hudText = GetComponent<HUDText>();

}
}

It works for me, I hope it will be helpful for someone out there too.

For some reason I fail when it comes to invoke the Add() method more than once in the same state using different parameters.

Again, I am not a coder so I am not able to nail the problem.

Cheers!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: [SOLVED]NGUI HUD Text Help needed
« Reply #2 on: April 24, 2013, 01:36:55 AM »
Hi,

 I am glad you managed to make a custom action

 your test2 class doesn't really do anything, maybe you forgot to add the rest of the script?

This action you wrote will perform like any other, if you want to call it again, you will need to enter the state again via a transition or a global event. Now I don't own HUD plugin so maybe oyu need to reset your hud or something so that several add call works.

bye

Jean

bye,

 Jean