Author Topic: Managing Multiple Inventory Windows (Moving, Organization)  (Read 3014 times)

Lairinus

  • Guest
Managing Multiple Inventory Windows (Moving, Organization)
« on: December 26, 2013, 02:00:19 PM »
Hey guys!

I'm still pretty new at NGUI but I've managed to do what I want with the help of a few workarounds. The main issue that I'm having now, though, is managing more than 1 inventory window.

Let me elaborate:

I have 3 characters, and each character has their own inventory. There are 2 states in which you can see in the inventory; when you hit the inventory button, and when you're in the shop buying items. I also set up an inventory drag system that's working ideally at the moment with my two test inventories.

I've derived two questions from this:

1. How can I change the position of my Inventory GUI at runtime?


 -If only one character is selected I want to see a large inventory, but if all three are selected I want to see 3 smaller inventories that take up as much space as the one large one. (I can manage that part, it's just the moving that I can't do!) I'm scared to touch the transform.position due to previously yielding way way WAY undesirable results.

2. What is the best method for organizing your inventory? Do you make <X> amount of different UI roots, or do you place them all under one? Is there a difference, and does it matter?

With GameObject.active the functionally seems the same but I don't want to encounter a massive problem down the line after I have 40+ inventory screens. I guess the worst-case scenario would be finding every Inventory UICamera in the scene and using RaycastAll() but... yeah.

Thanks for any help with this!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Managing Multiple Inventory Windows (Moving, Organization)
« Reply #1 on: December 26, 2013, 06:46:22 PM »
You should only have one UIRoot, and your different windows should be underneath it. Enable/disable them as needed.

To change the position of something, move its transform like you would with any other game object.

Lairinus

  • Guest
Re: Managing Multiple Inventory Windows (Moving, Organization)
« Reply #2 on: December 26, 2013, 07:26:24 PM »
Thanks for the response!

I was looking to see if there was any method for movement built into NGUI, but it's not a problem because I'm a method junkie. Ended up writing a little one that's specific for the "PixelPerfect" setting.

It probably won't help anyone but, anyway here it is:

  1.     static public void SetPosition(Transform t, float x, float y)
  2.     {
  3.         if (t != null)
  4.         {
  5.             float newX = x - (Screen.width / 2);
  6.             float newY = y - (Screen.height / 2);
  7.  
  8.             t.localPosition = new Vector3(newX, newY);
  9.         }
  10.     }
  11. }

Also it's good to know that about the UIRoot. I didn't want to make a List<Camera> so I could add one type of functionality lol...

Thanks again!