Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - delzhand

Pages: [1]
1
NGUI 3 Support / Understanding dimensions in scene vs game view
« on: April 12, 2014, 12:27:14 PM »
I have my UIRoot set to FixedSize with a manual height of 720.  When I click on it in scene view, it shows me the dimensions 720x1281 (seems like it should be 1280 but that's less important).



Yet when I position ui components using advanced anchors to align them to the screen edges, they don't appear where I'd expect in scene view, and it makes it very hard to lay things out.



And yet, when I start the game, the game screen does display them in the correct place.



Is there something I need to configure differently?

2
NGUI 3 Support / Re: Anchor sprite to screen corner at runtime?
« on: February 09, 2014, 10:42:03 AM »
Okay, I think maybe I've got it figured out - someone can correct me if I'm wrong.

The anchor panel of the UI is an abstraction and only makes sense in the context of the ui.  If you want to set the position of something to the corner of the screen, you can use Screen.width or whatever, because you're not going to be using the UI to change things in the actual game.

3
NGUI 3 Support / Re: Anchor sprite to screen corner at runtime?
« on: February 08, 2014, 07:12:36 PM »
And as a followup question, how come the top image here is left 0 top 0, and not the second one?  Where on earth is that 0 pixels from the left or top of the containing panel?


4
NGUI 3 Support / Anchor sprite to screen corner at runtime?
« on: February 08, 2014, 05:50:41 PM »
I'm having trouble figuring out what the best practice is for this case.  I came up with this based on another forum post:

  1.      
  2.       UIRect uiRect = sprite.GetComponent<UIRect>();
  3.  
  4.       uiRect.topAnchor.target = parent;
  5.       uiRect.bottomAnchor.target = parent;
  6.       uiRect.rightAnchor.target = parent;
  7.       uiRect.leftAnchor.target = parent;
  8.  
  9.       uiRect.leftAnchor.absolute = 10;
  10.       uiRect.rightAnchor.absolute = 210;
  11.       uiRect.topAnchor.absolute = -10;
  12.       uiRect.bottomAnchor.absolute = 35;
  13.  

But that anchors left to left side, right to right side, etc.  My I want my sprite to be 200 wide, starting 10 from the left edge.  This is easy as pie in the UI - I just set the sprite anchor's "left" to "target left" with a value of 10, and "right" to "target left" with a value of 210.

I thought maybe SetToNearest was a possible option, but the description and variable names make that function completely inscrutable to me.  I'm sure things will be easier once I can figure out the abstraction from the data storage to the ui, but as it stands I have no clue what variables the Anchor panel represents.

5
NGUI 3 Support / Re: NGUITools.AddChild creates duplicate objects
« on: February 06, 2014, 09:39:52 PM »
Mystery solved!

The last call was closest to correct.  However, Resources.Load() returns an object, not a GameObject, so C# was interpreting it as a bool and calling the AddChild(GameObject, bool) instead of AddChild(GameObject, GameObject).

I hope this helps someone else in the future!

6
NGUI 3 Support / NGUITools.AddChild creates duplicate objects
« on: February 06, 2014, 09:35:25 PM »
I've been using the demo version of NGUI for about a year, and I finally bought the license for the full version today.  While most of it makes a lot of sense, I'm not sure I understand the "correct" way to do things when creating things programmatically.

I think I'm calling NGUITools.AddChild incorrectly in some circumstances.  If I call it like this:

  1. NGUITools.AddChild(uiRoot, new GameObject("Test"));

it works like I expect, it creates a basic GameObject (although it does add "(Clone)" to the name, which is irksome but fixable).

However, when I try to instantiate an actual prefab, like so:

  1. NGUITools.AddChild(uiRoot, Instantiate(Resources.Load("Prefabs/MyPrefab")));

then MyPrefab(Clone) is instantiated in the hierarchy root, and 'New Game Object' is created as a child of uiRoot.

Thinking that I'd done it wrong and that maybe the prefab needs to be pre-instantiated, I tried:

  1. NGUITools.AddChild(uiRoot, (GameObject)UnityEngine.Object.Instantiate(Resources.Load("Prefabs/MyPrefab")));
  2.  

but that creates MyPrefab(Clone) in the hierarchy root, and MyPrefab(Clone)(Clone) as a child of uiRoot.

At this point I took a look at the actual code of AddChild, and saw that it actually calls GameObject.Instantiate on line 386.  So I tried this:

  1. NGUITools.AddChild(uiRoot, Resources.Load("Prefabs/MyPrefab"));

which creates 'New Game Object' as a child of uiRoot, but it's just a basic GameObject with no components, meshes, etc.

At this point I'm at a loss, the code of AddChild isn't especially complex, so it has to be with my call, right?

Pages: [1]