Author Topic: Collecting Data Generated Through the UI  (Read 5307 times)

docgonzzo

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 10
    • View Profile
Collecting Data Generated Through the UI
« on: October 16, 2014, 03:21:03 PM »
This should be an easy one..

I have a game object in my hierarchy/scene that has a script containing a list of strings.

Separately in the hierarchy, I have the UIRoot with a "Simple Input Field" control inside.

I would like to have the UI add the contents of the input field to the list of strings upon "Submit".

In general, what is the best approach to take when passing data collected by the UI (names, stats etc) to a separate game object? Collecting and storing the data provided by the UI for future use should be an easy thing, but I'm stuck on how to move forward in the most efficient way.

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Re: Collecting Data Generated Through the UI
« Reply #1 on: October 16, 2014, 03:25:12 PM »
Why not just put a reference to this UIInput on your class  and get the data whenever you want using UIInputField.value? Then just add to the list list.Add(targetInput.value);

docgonzzo

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Collecting Data Generated Through the UI
« Reply #2 on: October 16, 2014, 04:29:20 PM »
I thought about doing that, but is it actually the most efficient way to accomplish this? Forgive me, but I'm still a bit new at unity.

In my old code, before starting with NGUI, i had a GUI.TextField defined inside the script defining the list of strings. It was very straightforward to grab the text from this and add it to the list, all within the same script.

Maybe I'm over-complicating this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Collecting Data Generated Through the UI
« Reply #3 on: October 17, 2014, 04:55:13 AM »
  1. using UnityEngine;
  2.  
  3. public class MyReferences : MonoBehaviour
  4. {
  5.     public UIInput username;
  6.     public UIInput password;
  7.     public UIInput address;
  8. }
Attach this to some game object, reference your input fields. Then when you need their values, GetComponent<MyReferences>(), and access them.