Hello Guest

Author Topic: tk2dUIManager.PressedItem alternative?  (Read 6615 times)

cloudchen

  • Newbie
  • *
  • Posts: 16
    • View Profile
tk2dUIManager.PressedItem alternative?
« on: November 12, 2013, 11:58:50 am »
After updated to version 2.2.3, I've notice the log message
Code: [Select]
It is no longer necessary to hook up a camera to the tk2dUIManager. You can simply attach a tk2dUICamera script to the cameras that interact with UI.I would like to know is there any alternative way to get the pressed item which the tk2dUIManager originally kept? Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #1 on: November 12, 2013, 11:59:54 am »
The old method still works, just isn't necessary any more. You can ignore the message if you want.

cloudchen

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #2 on: November 14, 2013, 07:41:53 am »
I have noticed that If I attached the "tk2dUICamera" to my tk2dCamera, it will automatically created a tk2dUIManager object when the scene get launched. However, the UI Camera field did not been assigned any tk2dCamera.

So if I called tk2dUIManager.Instance.PressedItem.name under this situation, I always get NullReferenceException right?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #3 on: November 14, 2013, 12:55:41 pm »
No it shouldn't be. The uicamera field is null because it has another internal cameras List (instead of just one camera). You can have multiple cameras interacting with the UI, but everything else still behaves the same.

cloudchen

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #4 on: November 15, 2013, 04:19:32 am »
OK, actually I would like to use UIManager's "PressedItem" to help check if user touched on a UIItem to prevent some events been triggered.

So:
Code: [Select]
if (tk2dUIManager.Instance.PressedUIItem != null)
{
Debug.Log(tk2dUIManager.Instance.PressedUIItem.name);
shouldTriggerEvent = false;
}

these lines of code did work before I upgrade to version 2.2.3, but after that I got "NullReferenceException" when system called the Debug.Log line above. Have any idea about it?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #5 on: November 15, 2013, 10:48:13 am »
Oh so now you don't have a tk2dUIManager, and this is null ref-ing? Isn't that the only thing that can be null there? Is there a uimanager in the scene at that point?

cloudchen

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #6 on: November 18, 2013, 03:02:23 am »
I check the existence of tk2dUIManager again, yes it's there. I've noticed that the NullReferenceException seems caused by the UIItem which are inherited from the previous scene  via the DontDestroyOnLoad function. If I pressed the UIItem created in the current scene but not the previous one, everything works perfect!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUIManager.PressedItem alternative?
« Reply #7 on: November 18, 2013, 10:55:37 am »
I think you'll have to debug that to find out why the link is null - it shouldn't be if its DontDestroyOnLoaded, check that all the components on the object are sensible...