Author Topic: Best practices for showing details on the current selection?  (Read 4211 times)

justkevin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
This is a common feature in games: the UI shows details on the current selected object, with the behavior varying on the object type. I've come up with a way of doing this, and I'm interested in hearing suggestions on easier or more flexible solutions:

  • The player controller caches a reference to the Scanner panel (a script attached to an NGUI panel)
  • Any time a player selects a game object (e.g., clicks on it), the controller checks if the object has a component implementing IScannable
  • IScannable has a GetScanObejct() method which instantiates a Game Object (e.g., from a prefab reference), which contains one or more UIWidgets. The instance is given a reference to the instantiating game object so it can reflect changes, like damage.
  • The scan instance is passed to Scanner panel's SetScanTarget() method, which clears itself by destroying its children and adds the new instance (by setting its parent and local transforms).

Does this seem like a reasonable approach?


justkevin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Best practices for showing details on the current selection?
« Reply #1 on: May 07, 2014, 05:51:38 PM »
After further investigation, it appears that NGUI doesn't like it if you modify the transform hierarchy manually, instead the preferred method is to use AddChild().

So my new plan is to change IScannable's signature to have an AttachToNGUI(GameObject parent) method.

I'm still interested in how others have handled this functionality.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best practices for showing details on the current selection?
« Reply #2 on: May 08, 2014, 02:32:53 AM »
You can modify the transform hierarchy, but you need to let the widgets know that you've done so (NGUITools.MarkParentAsChanged).