playMaker

Author Topic: Get Property help [SOLVED]  (Read 439 times)

tomraegan

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Get Property help [SOLVED]
« on: December 08, 2017, 04:37:59 PM »
Hi.


I'm trying to get my variable, grid_01_value into PlayMaker from a script, but I can't find evidence of it being read by my FSM. I'm using Get Property and dragged the component itself into the Target Object field. grid_01_value is a public variable and I can list it as the Property. I then store it as 01_int_display_g. I'm then trying to convert and view the result. This is where I can't get a result.

Here is the FSM.


The variable grid_01_value is set from this code:
Code: [Select]
[size=8pt]using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Read_From_Centre : MonoBehaviour {

public UICenterOnChild myGrid;
public int grid_01_value;

public GameObject[] gridItems = new GameObject[4];

public void knowWhatIsCentered(GameObject _centeredItem)
{
if(_centeredItem == gridItems[0])
{
print("item 0 selected");
grid_01_value = 0;
Debug.Log("grid_01_value = " + grid_01_value);
}
else if(_centeredItem == gridItems[1])
{
print("item 1 selected");
grid_01_value = 1;
Debug.Log("grid_01_value = " + grid_01_value);
}
else if(_centeredItem == gridItems[2])
{
print("item 2 selected");
grid_01_value = 2;
Debug.Log("grid_01_value = " + grid_01_value);
}
else
{
print("item 3 selected");
grid_01_value = 3;
Debug.Log("grid_01_value = " + grid_01_value);
}
}
// Use this for initialization
void Start () {

myGrid.onCenter = knowWhatIsCentered;
}

// Update is called once per frame
void Update () {
}
}[/size]

I'm a complete scripting n00b and the above is mostly copied, but it is working as intended. I attach this script to a GameObject and fill the Public field "My Grid" with the NGUI Scroll grid object. I then populate the other fields with the grid objects. All of this part works.


I've noticed the FSM state "Get and Convert Grid Value" doesn't pulse green when I click on the scroller. The debug console updates with the correct values, but my data isn't getting into PM.

edit: Forgot to mention that the NGUI Label , irrespective of my scroller selection, sits on 0.

I'd appreciate some help. Thanks.
« Last Edit: December 10, 2017, 11:54:28 AM by djaydino »

tomraegan

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Get Property help
« Reply #1 on: December 09, 2017, 01:04:13 AM »
I keep doing this (posting, then figuring it out, so sorry if it's a bother. I had spent a day on it before posting and it wasn't going to give. Then I mowed the lawn and gave my daughter a swing. Next thing I know...)

When I've worked out exactly how I did it (still a bit of a mystery to me), I'll post an update.

Edit: I cannot make Center on Child in the NGUI package work. On Click works, On Drop, no problem. But Center on Child remains a mystery. It would be convenient if it did work. This would mean I could create a single FSM on the NGUI Scroll Grid that governed all its children. As it sands, using On Click instead, means two things:

1. User interaction will rely on clicking the object
2. FSM's need to be placed on each child

Neither of these things are too bothersome, but if anyone can see why the Center on Child isn't working, please let me know.

Thanks.
« Last Edit: December 09, 2017, 01:30:08 AM by tomraegan »

Deek

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Get Property help
« Reply #2 on: December 09, 2017, 08:24:13 AM »
Since you already have those global events like "ON DROP" I assume you have the NGUI PlayMaker Proxy in your scene (which contributes those global events). If not you can get it from https://hutonggames.fogbugz.com/?W1111 or the Ecosystem.
But those global events only work when you also attach the "NGuiEventsToPlaymakerFsmEvents"-script to the GameObject you want to detect changes on. These events also only get fired when the FSM is on the GameObject with the grid.

Alternatively you could use your current setup and use ON CHANGE instead of ON CLICK which at least removes your first problem.

In your first post you also only have your state be called on START, which only gets fired once at the start of your scene, the same in your script where you only call "knowWhatIsCentered" in Start(), thus it won't update in any way when you interact with your grid at runtime.

So you only need one FSM on your GameObject with the UIGrid (and maybe the NGuiEventsToPlaymakerFsmEvents component) and it will detect ON CENTER ON CHILD, ON CHANGE and so on.

tomraegan

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Get Property help
« Reply #3 on: December 09, 2017, 01:21:38 PM »
Thanks kindly, Deek. I tried your suggestions and have made this discovery.

My script stops NGUI/On Center on Child from firing.

If I disable the script, the NGUI/On Center on Child Global Transition in my FSM fires. If I enable the script, it does not. So the problem isn't with the FSM, it's within the script.

Can you identify anything in the script that would interfere with the NGUI event firing in the FSM?

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

public class Read_From_Centre : MonoBehaviour {

public UICenterOnChild myGrid;
public int grid_01_value;

public GameObject[] gridItems = new GameObject[4];

public void knowWhatIsCentered(GameObject _centeredItem)
{
if(_centeredItem == gridItems[0])
{
print("item 0 selected");
grid_01_value = 1;
Debug.Log("grid_01_value = " + grid_01_value);
}
else if(_centeredItem == gridItems[1])
{
print("item 1 selected");
grid_01_value = 2;
Debug.Log("grid_01_value = " + grid_01_value);
}
else if(_centeredItem == gridItems[2])
{
print("item 2 selected");
grid_01_value = 3;
Debug.Log("grid_01_value = " + grid_01_value);
}
else
{
print("item 3 selected");
grid_01_value = 4;
Debug.Log("grid_01_value = " + grid_01_value);
}
}
// Use this for initialization
void Start () {

myGrid.onCenter = knowWhatIsCentered;

}

// Update is called once per frame
void Update () {


}
}

Deek

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Get Property help
« Reply #4 on: December 09, 2017, 04:59:34 PM »
Your script looks fine, but it could be that the UICenterOnChild class interferes with the event or that you already call the onCenter event. You could try to use UIGrid instead of UICenterOnChild and use its onPositionChanged (or called similarly) event instead of onCenter, but that might not make much of a difference.

Why even use that script when ON CENTER ON CHILD works without it, then you can just get the active/centered child with Get Property from the UIGrid in the state it fires to.

tomraegan

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Get Property help
« Reply #5 on: December 10, 2017, 12:09:48 AM »
Thanks for that last sentence, Deeks. It opened up a new vein of exploration.

Inside Get Property with the UI Grid set as Target Object, I cannot find a Property of UI Grid that allows for the active/centered grid item to be received. Here they are, minus sub-menus.



Now, obviously, right at the top, it says "active". But it's a bool allowing true/false data only. Can this be interpreted to allow the range of values to be read, like an int?

I've also added other components, attempting to receive updates from the NGUI event. The event triggers in PM without fail but I cannot capture data from the grid children.

You are correct in that my script caused interference to NGUI Center on Child.

As I'm a complete beginner, I appreciate it's not up to experts to provide solutions. In truth, I've developed a taste for experimenting and I'm in no great rush. But any tips anyone has I would appreciate.
« Last Edit: December 10, 2017, 12:12:09 AM by tomraegan »

tomraegan

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Get Property help
« Reply #6 on: December 10, 2017, 12:33:44 AM »
Ok.

 ::)

I assigned tags to each of the separate Grid children and yep...it works.