Author Topic: Ver 3.0 upgrade, protection level  (Read 5041 times)

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Ver 3.0 upgrade, protection level
« on: September 22, 2013, 04:20:21 PM »
Hi
Just upgraded. One little problem.
In UiInput.cs I used to access eventReceiver & functionName from another script, they used to be:

  1. public GameObject eventReceiver;
  2. public string functionName = "OnSubmit";

and all was fine.

Now I get this error:

`UIInput.eventReceiver' is inaccessible due to its protection level

I've put the two original lines back in for now, (don't want to edit your scripts each upgrade) but wandered if there is another way to access them as you now have them now:

  1. [HideInInspector][SerializeField] GameObject eventReceiver;
  2. [HideInInspector][SerializeField] string functionName = "OnSubmit";

Many thanks..

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #1 on: September 23, 2013, 05:18:15 AM »
It's deprecated functionality. I kept them private so that older UIs don't get broken, but you shouldn't be using it.

Use this instead:
  1. EventDelegate.Set(input.onSubmit, OnSubmit);

OnSubmit should be:
  1. void OnSubmit() { Debug.Log("Text: " + UIInput.current.value); }

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #2 on: September 23, 2013, 06:17:37 AM »
Thanks,
I'm not exactly sure how to fit that into my script:
  1.  void OnSelect (bool isSelected)
  2.     {
  3.         UIInput input = GetComponent<UIInput>();
  4.        
  5.         if (isSelected){
  6.                
  7.             input.text = "";            //clear field on click
  8.             input.label.text = "";      //clear field on click
  9.         }
  10.        
  11.         else{
  12.                
  13.             input.eventReceiver.SendMessage(input.functionName, input.text, SendMessageOptions.DontRequireReceiver);
  14.         }
  15.     }

(which I added just as a personnel choice on functionality.)

my guess:

  1.  input.eventReceiver.SendMessage(input.onSubmit, input.value, SendMessageOptions.DontRequireReceiver); //??

many thanks if you can put me straight...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #3 on: September 23, 2013, 06:53:46 AM »
Oh you're trying to trigger it? Have a look at EventDelegate.Execute -- http://tasharen.com/ngui/docs/class_event_delegate.html
  1. EventDelegate.Execute(input.onSubmit);

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #4 on: September 23, 2013, 08:43:27 AM »
 :(
I'm a little lost now..
1. Just trying to get this working, I now see in the inspector, I have no slot for the function I'm calling from my Input box ( or it's gameobject ) but it still works! How does UIInput.cs know what function I want to call? I see the new On Submit tab, but on mine, the Notify field says None.

2. I'm a bit out of my depth with the EventDelegate.Execute solution you mentioned, and can't seem to see how I replace the line I had;

  1. input.eventReceiver.SendMessage(input.functionName, input.text, SendMessageOptions.DontRequireReceiver);

using that method..
Sorry, and thanks for any help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #5 on: September 23, 2013, 02:06:42 PM »
1. If you want it to show up in inspector, make it public.

2. You replace it with the exact line I posted.

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #6 on: September 23, 2013, 02:50:08 PM »
ok,
When you say make it public, do you mean the functions (Methods) I'm wanting to call when I submit from a UIInput?

I have been trying to add my gameObject that holds the methods to the 'Notify' slot under UIInput in the inspector, then choosing available 'public' methods. I can only choose methods that have no parameters!

Besides all that, I can't see how existing UiInputs before I upgraded still know what method to call, I see no reference to them (methods) at all in the inspector, yet they still work, where would I change them, now I can't see them? And if it is done under the 'On Submit' & 'Notify' tabs, why can't I select methods with parameters, for example:

  1. public void VarSetDegs(string varD) {
  2.  
  3. }

I would be able to add:

  1. public void VarSetDegs() {
  2.  
  3. }

thanks for any help, sorry for the hassle..

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #7 on: September 23, 2013, 04:13:34 PM »
NGUI keeps references for backwards compatibility, but as soon as you assign any delegate, the legacy fallback will be removed.

You can get the current input that sent the event using UIInput.current. I already showed that in the example I posted several replies back. So you don't need the "string varD" because you can get it via UIInput.current.value.

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Ver 3.0 upgrade, protection level
« Reply #8 on: September 24, 2013, 06:34:31 AM »
got it!
works great, thanks for your help at this busy time  :)