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.


Topics - MoProductions

Pages: [1] 2
1
NGUI 3 Support / UILabel line break/formatting
« on: October 02, 2017, 10:53:44 AM »
We're using a UILabel to display some text info about our game.  We've got it anchored so it forces the Overflow to Shrink Content, which works fine most of the time but we're not happy with the way the line breaks sometimes.  For example, this is one of those cases:



What we want to be able to do is avoid the situation where the 2nd line is very short compared to the top line, so it looks cleaner.  I was going to start looking into ways to detect how many characters were after a line break, but when I tried that it turns out there weren't any.  I looked at the UILabel component and sure enough the string for that above is this:
"we would like to be able to not have the line split here"

(minus the quotes of course). 
Is there some other way that we can find out where the line break appears in the string, or is there perhaps another formatting trick we could try?  Remember this is anchored because we're supporting multiple screen resolutions and will eventually support multiple orientations as well.
Thanks!
-Mo

2
NGUI 3 Support / Strange behavior with advanced anchors
« on: July 21, 2017, 01:05:29 PM »
We're sorting out our multiple aspect ratio issues and came across a weird effect of anchors. I've set up a simplified scene to show off exactly what the issue is so don't mind the Atari 2600 looking art.
The scene is a rectangular blue widget (Menubar) with two square widgets (Pink, Dark Blue) anchored to it's sides.  There's also a white rectangle which represents where these objects are supposed are supposed to be for this aspect ratio, so when the scene starts the Menubar widget's size and transform's position get set via copying the values from the white rectangle, then the anchors are supposed to take care of the two side objects.  We need those two objects on the side to always be anchored to the sides and remain square. 



The way I set up the Pink anchor is I anchored it's left side to the Menubar left, it's top and bottom to Menubar top and bottom, then left the right anchor blank and set the Aspect value on the widget to be Based on Height, which gave me what I needed.



I did the same thing for the Dark Blue but anchored the right instead of left. As you can see in the image above, it looks fine, and changing aspect ratios in the editor looks fine as well.  The issues begin when the scene actually starts or gets loaded at runtime (I've tested this on devices as well).  What's happening is that while the squares end up where they are supposed to be, they don't snap there right away like all the other anchors I've used (and i've used plenty heh).  What happens is that it animates into position over about a half a second. Not much, but certainly noticeable.  The only thing I can think of that's causing it is that missing anchor, because when I anchor all sides to Dark Blue, it doesn't give me the position I need but it does happen automatically.



I've taken a video of what happens when i start the scene and as you can see the Dark Blue square snaps immediately but to the wrong spot, while the Pink square goes to the right spot it just animates. Neither one is what we're looking for.

https://www.youtube.com/watch?v=77P9P8e1v0g&feature=youtu.be

So what I'm wondering is either a) how to get the behavior we need another way or b) stop the animation part for happening.

Any help appreciated!  Thanks!
-Mike

3
NGUI 3 Support / UIDraggableCamera alternate
« on: July 11, 2017, 01:47:19 PM »
OK so our entire control system for the main part of our puzzle game was a combination of UIDraggableCamera, UIDragCamera and SpringPosition.  We were having a weird issue where we wanted to shut off the dragging, but shutting off the UIDraggableCamera didn't do it.  Checked the UIDragCamera code and it doesn't check to see if the UIDraggableCamera is active before calling it's code.  So I went to the forums to find some tips and I discover all sorts of posts about "I don't know why UIDraggableCamera exists" and "UIDraggableCamera is from NGUI 1" etc etc etc.  We've put a TON of time into this system before discovering this, and TBH it's worked out ok for us for the most part.  However, we do need to sort out this issue so I'm wondering if

a) We can just do what we need with UIDraggableCamera and UIDragCamera since they'll never be updated again or
b) We have some sort of alternate solution that won't require us to rewrite our entire control system (we did a ton of stuff on top of the NGUI stuff to get the functionality we wanted).

Any tips appreciated, I hope we didn't waste a TON of time.

-Mo

4
NGUI 3 Support / FitOnScreen but adjusts size, not position
« on: April 11, 2017, 12:04:30 PM »
We're handling all movement and camera zooming with in our game by adjusting the camera, not any objects themselves.  Now I've gotten good at being able to adjust the camera's position to get a transform to be at a certain spot, and I noticed that in NGUITool you have a bunch of FitOnScreen functions.  However, both what I'm doing and what FitOnScreen does is adjust the camera's position, what I need is to be able to get a transform to a certain point just by adjusting the orthographic size.  That might sound sketchy, but our game is a puzzle game that will always have a playing area of a perfect square (thanks to UIGrid heh).  However, the # of cells per side might change.  The grid could be 15x15, 13x13, 20x20.  The cells will always be the same size, but we need to know at what orthographic size to set the camera so that all the elements will fit exactly.  So far, in both Unity and NGUI, I've not seen anything that can accomplish that.  What I've done so far is a crazy, inefficient loop that just tries different sizes until I get what I need (upperLeftPosition is the position at the upper left corner of the first square in the grid):

  1. float size = 1f;
  2. while( size < 1.3f )
  3. {
  4.         puzzleCamera.orthographicSize = size;
  5.         Vector3 wtv = puzzleCamera.WorldToViewportPoint( upperLeftPosition );
  6.         Debug.Log( "wtv: " + wtv2.ToString("0.0000") + ", size: " + size);
  7.         size += .0001f;
  8. }

At orthographic size 1f, the WorldToViewportPoint is at (-0.1113, 1.1113, 0.0000).  Turns out that an orthographic size of 1.222737f is what I need to get that point to (0,1,0).  Is there any way to calculate what size directly with any NGUI tools or code?  Or is it some simple matrix thing that I haven't learned yet?
Or perhaps there is no way? 
Thanks!
-Mo

5
NGUI 3 Support / Sprite sharpness
« on: April 07, 2017, 01:18:59 PM »
I've been fiddling around with shaders all day and can't seem to figure out how to get my sprites to be as sharp as the source material.  In our game, we have very simple black and white squares in a grid.  I'm using this image as the source for the sprite.



However, when I put the UISprite in the game, there's fuzziness around the edges.  It gets more pronounces as we zoom in (zooming is a big part of our functionality).
Here's a single sprite zoomed in:



And when I make a grid of them, with the grid spacing matching the size of the squares exactly, there's little breaks in between the cells.
Here it is with no zooming:



Here it is zoomed in:



Like I said I've been messing around with shaders and can't seem to find anything that makes the squares as sharp as the source material. Is there something else I'm missing that could help out with this?
Thanks!
-Mo

6
NGUI 3 Support / UIRoot behavior with orientation changes
« on: March 09, 2017, 11:51:48 AM »
We plan on supporting all aspect ratios and orientations for our project.  We've gotten the basics down on how to use all the NGUI stuff, but what we were curious about was how the UIRoot deals with orientation changes.  For example, right now our UIRoot is set to 1024x768, Contrained, and both "Fit" buttons are unchecked.  So if we're working on a screen that's at that size, positioning a UISprite at 0,-768 will position the sprite at the bottom of the screen with the bottom half cut off (pivot is all centered).  That makes sense since the screen height is 768.  However, when we switch to Portrait mode, the screen size is now 1024, but to get the sprite positioned at the bottom, you don't set the Y to -1024, you still set it to -768.  I'm sure there's lots of behind the scenes that explains this but it's a bit confusing for laying stuff out, especially with our less technical staff members who want to set up things at the bottom of a Portrait screen but the numbers don't make sense in the current orientation.
What we were thinking of doing is (both at edit time and run time) if an orientation change is detected, we'd update those numbers accordingly.  So in landscape it's 1024x768 and in portrait it's 768x1024, so the layout positions would make more since.
However, since we're still not 100% sure how the UIRoot works behind the scenes, we were wondering if doing this is a horrible idea, a great idea, and what the reasons would be either way.  We're going ahead with testing this but please let us know if there's any reason why this would be bad.
Thank you!! 
-Mo

7
NGUI 3 Support / Scroll Bar Functionality Breaks With 2D Colliders
« on: February 07, 2017, 03:19:31 PM »
The functionality I'm referring to is when the foreground/thumb parts will move immediately to the spot you click on the background.  For example, from the "Example 0 - Control Widgets" scene

Before


Then when I click the mouse, the cursor automatically jumps to that spot:


This is the functionality I'm looking for, and this is the functionality you get with regular 3D box colliders.  However, our entire game is 2D (2D project) and those colliders weren't working so we activated the "NGUI->Extras->Switch to 2D Colliders" feature and all our other widgets started working fine.  However, with 2D box colliders on the UIScrollBar , the foreground/thumb doesn't snap to the spot when you click, you have to click and drag the background to get the foreground/thumb to move.  This is easily repeatable by just switching back and forth between collider types via the pulldown when running the example scene.
My questions is if there's a way we can get the "click to snap" functionality working with 2D colliders instead of it switching to the "drag the background to move the foreground/thumb" functionality?
Thanks!
Mo
My q


8
Part of our game involves a code generated grid of letters.  I'm using a UITable object which I fill with the letters, then call
myTable.Reposition().  For a while everything seemed fine but when we were looking more closely at things due to a bug we noticed that while the elements in the rows/columns line up, the columns themselves are not equidistant from each other.  It's most easily seen when creating a table with zero padding:



Notice how the columns 4 and 5 (top letters are P and Y), and columns 9 and 10 (top letters are L and O) have different spacing.  This has been confirmed by debug code. 
I assume what's happening is that UITable.Reposition() will find out the minimum distance needed between columns based on the two widest elements next to each other, then adds the padding.  Well, since fonts aren't equal sized in that creates inconsistencies.
The solution I was going to try was instead of creating the UITable out of font elements, I would create the table out of
(fontSize x fontSize) sprite elements, making them all the same size.  Then after Reposition() is called, I'd go back through the grid and place each font element at the sprite element's transform.position. 
I'm pretty sure that would work, but is there a way to toggle something in NGUI or UITable that would force consistent spacing between the columns based on the widest spacing needed or perhaps a hardcoded value and not based on elements with different widths?
Thanks!
-Mo

9
NGUI 3 Support / Helper functions for moving a camera, not widgets
« on: December 19, 2016, 11:23:38 AM »
We're working on a project that moves the camera instead of the game objects.  Between Unity's Camera class and the NGUIMath/NGUITools there's lots of functions for moving game objects to be within the bounds of a camera (FitOnScreen, etc).  However, for our game, all of the game objects will be stationary, so what we need is something that isn't telling us where to put an object so that it's at a certain point within the camera's view, but we want to move the camera to the exact spot to get the object where we want it. 
For example, it's easy enough to move a widget to the exact edge of the screen using stuff like ViewpointPorttoWorldPoint(), but is there a way to calculate where we'd need to put the camera to get the widget at the exact edge of the screen?  I've been looking into bounds calculations but I'm still missing something.
BTW we're using a multiple camera setup, camera in camera sort of thing, so we'd need to be able to do this with any camera, not just one that's bounded by the screen.
Thanks!  Let me know if this needs any clarification.
-Mo

10
As an effect in our game we're using a simple script that will create a 500x500 texture, fill each pixel in that texture with a random color, then assign it to a UITexture object with an Until/Texture shader.  Here's a simplified version of our script:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BlitTest : MonoBehaviour {
  5.        
  6.         // Use this for initialization
  7.         void Start ()
  8.         {
  9.                 Texture2D texture = new Texture2D( 500, 500, TextureFormat.ARGB32, false );
  10.                 for( int x = 0; x < 500; x++ )
  11.                 {
  12.                         for( int y = 0; y < 500; y++ )
  13.                         {
  14.                                 texture.SetPixel( x, y, new Color( Random.Range( 0f, 1f ), Random.Range( 0f, 1f ), Random.Range( 0f, 1f ) ) );
  15.                         }
  16.                 }
  17.                 texture.Apply();
  18.                 GameObject.FindObjectOfType<UITexture>().mainTexture = texture;
  19.         }
  20. }
  21.  

When using NGUI 3.10, the results are as expected:


However, when we upgrade to NGUI 3.11, the UITexture no longer shows up in the game:



The only difference between the two screen shots is that the 2nd one uses NGUI 3.11 instead of 3.10.
I noticed in the readme that there's a lot of changes within NGUI as far as UV's, geometry, etc.  Could one of those be causing this issue, and is there a way to resolve it?  I can provide the test project I used for this demo if necessary.
Thanks
-Mo

11
NGUI 3 Support / UITweenScale doesn't effect anything
« on: July 14, 2016, 11:16:20 AM »
So I've been adding a UITweenScale to an object in code in two different ways:

  1.                        
  2. TweenScale tweenScale = NGUITools.AddMissingComponent<TweenScale>( centerButton );
  3. tweenScale.from = new Vector3( 1f, 1f, 1f );
  4. tweenScale.to = new Vector3( 1f, 1f, 10f );
  5. tweenScale.style = UITweener.Style.PingPong;
  6. tweenScale.duration = 2f;
  7. tweenScale.Play();

and

  1. TweenScale ts = TweenScale.Begin( centerButton, 2f, new Vector3( 1f, 1f, 10f ) );
  2. ts.style = UITweener.Style.PingPong;


When I use this code, the tweener shows up and does effect the scale in the Transform properly.  However, nothing is happening to the actual game object.  I've noticed that in the Transform the only thing that actually has an effect, even when adjusting manually, is the Z rotation.  Everything else looks greyed out and doesn't change anything I'm assuming because it's overridden by the Widget size component.  So is there a way to get the UITweenScale to effect the widget, because altering the scale in the Transform doesn't change anything.  I also make sure that the GameObject I'm trying to change has no anchors.
Thanks!
-Mo

12
NGUI 3 Support / Adjusting anchor offsets lerps instead of snaps
« on: June 29, 2016, 08:39:46 AM »
When I adjust the anchor offsets on some of our game objects, the object goes to the new position but it doesn't snap there right away, it goes through a lerp situation.  It appears to be a result of not having every anchor set, but in order to get the behavior we want we only use 3 out of 4 anchors.  Is there a way to have an object without all 4 anchors set move to it's new position right away after adjusting the anchor instead of lerping?
Thanks!
-Mo

13
NGUI 3 Support / Anchor behaves differently if set in code
« on: June 21, 2016, 03:31:23 PM »
I'm noticing some inconsistent behavior with Anchors based on whether it's set up in the Editor or in code.  In the Editor I set up an anchor like this:



everything behaves as I need.  However, if I set those values in code, the object shrinks to 2x2 and starts moving off into infinity and beyond.  The only way to stop the infinity and beyond bit is to set up an Anchor for the bottom.  However, that screws up the behavior we need for adjusting screen sizes. 

Is there something else I need to do to get my anchors to behave the same if it's set up in the editor or in code?  Is there some special way I need to handle null anchors?

Thanks
-Mo

14
NGUI 3 Support / Adding child GameObject moves parent's position.
« on: June 14, 2016, 10:23:25 AM »
Part of the UI for our game shows letters over a box background.  I have a parent UITable, which holds a child background box for each letter, and then the letters are added as needed with this code:

GameObject letter = NGUITools.AddChild( boxes[j].gameObject, letterPrefab );
letter.GetComponent<UILabel>().text = curGame.wordsArray[ i ][ j ].ToString().ToUpper();

However, after I call OnReposition on the UITable, any box with a text child gets it's position adjusted when calling OnReposition() and looks like this:



I don't actually need the background boxes to move, but if I don't call OnReposition() it gets called anyway.  Is there a way to set things up so that the boxes won't move when the child is added?

Thanks!
-Mo

15
I've been working on a full NGUI based project and something odd is happening.  During the screen rotation during an orientation change, our elements are rendering very strangely.  They'll be stretched, duplicated, shunk, all sort of weird stuff but it only happens during the actual rotation.  Every goes back to normal once that's done.  This doesn't happen on other NGUI projects we've used.  Is there anything that could be causing this?   I've added delays in the code of several seconds to make sure that none of our code is being called until way after the rotation is done, so I believe it's something in the way things we're set up.  BTW our elements are UITables and UIGrids filled with squares.
Thanks!
-Mo

Pages: [1] 2