Hello Guest

Author Topic: UI Advanced Paging  (Read 4707 times)

bochicoine

  • Newbie
  • *
  • Posts: 15
    • View Profile
UI Advanced Paging
« on: October 25, 2013, 03:46:48 pm »
Using Version: 2.2.3

What is the best set up for a main menu that shows/hides various windows when specific menu options are chosen?

The criteria is that the main menu MUST be anchored to the Top Left side of the screen, for this anchors are used but it seems that disabling/enabling windows causes any transforms to be applied to all the children inside an object. My current hierarchy is shown below, is there a better way given that I may end up with multiple windows and buttons?

GUI_code (an empty game object with a single controller script.)
Camera (regular camera with 'tk2dUICamera' script attached.)
     Anchor (UpperLeft)
          Window_A
              button
              button
     Anchor (MiddleCentre)
          Window_B
              button
          Window_C
              button

The script is for the most part a copy of the UIDemoController script, which allows users to define gameobjects and a prev/next button. In this case I ahve 2 windows but for the sake of making it work I am only using Window_A and Window_B, the buttons in each window are used as the prev/next controls.

bochicoine

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: UI Advanced Paging
« Reply #1 on: October 25, 2013, 05:04:25 pm »
For a simpler example,

Take the UI Demo file.... where would you add an anchor to get the first window linked to the camera?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: UI Advanced Paging
« Reply #2 on: October 25, 2013, 08:27:54 pm »
How are you showing or hiding the window?

bochicoine

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: UI Advanced Paging
« Reply #3 on: October 26, 2013, 11:11:13 am »
I realize I am perhaps addressing two issues at once so apologies for that.

For the sake of reaching a conclusion, I believe it may be easier to look at the hierarchical setup first and then to address the script/code.

My question is this:

If we take the DemoScene (that comes with a fresh install of 2dtk), and we wanted to have the initial window anchored to the camera, what would be the best way of achieving this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: UI Advanced Paging
« Reply #4 on: October 26, 2013, 05:51:12 pm »
The problem with the demo scenes, e.g. animate window and co, is that they are made to work with Unity 3.5 & 4. Which is a massive pain in the butt, as in Unity 3.5, you can't SetActive to hide something - you have to use SetActiveRecursively which tends to do bad things :( The demo code is crippled by that - it can be a lot simpler if we don't have to care about Unity 4.x.

1. Use window.gameObject.SetActive(...) to show or hide a window.
2. Position the window where it should be, and linked to an anchor that positions it correctly to the edge of the screen you're interested in. Eg.
camera
   bottomAnchor
     relativePosObj
        window1
   topAnchor
     relativePosObj
        window2
   middleAnchor
     relativePosObj
        window3
I would keep transform.localPos on windows = 0,0,0 when its visible.

3. On game start, just hide the windows, or move them out of view (localPos = something other than 0,0,0) and SetActive(false) on them.

4. When you need to show a window, set its localPos = 0,0,0 and SetActive(true). Or animate it.

That should be it.