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 - vexe

Pages: [1] 2 3 4
NGUI 3 Support / Elements are not pivoting correctly?
« on: July 06, 2017, 01:51:50 PM »

I'm not sure when or how this happened, but for some reason our Labels and Sprites no longer have the right position when setting their pivot point.

See this picture, that's supposed to be Right-Center aligned, except it looks like it's Right-Bottom aligned.

Any idea what could be causing that?



we're getting weird/bad looking font and clipped sprites on some of our devices but not all.

- We're using bitmap fonts, Arial_12, Arial_14 (Don't want to use Dynamic fonts)
- All our UI is in one atlas, including the font
- UIRoot has "Constrained on mobile" with 480x270 (both with 'Fit' checked)
- Devices it looks bad on: Samsung Galaxy S7 Edge 1080p, and Samsung Galaxy View 18.4" 1080p
- Devices it looks good on: Samsung Galaxy Note 4, Samsung Galaxy S5
- UI Atlas texture filtering is set to Point, Wrap Mode is Clamp, Alpha Is Transparency is checked
- Using Unity 5.4.1f1



What I've tried but didn't do anything:
- Disabling 'Fit' in the UIRoot
- Enabling/Disabling Anti-aliasing in the quality settings
- Changing filter mode in atlas texture

Really appreciate any tips/pointers as to what's going on here.


NGUI 3 Support / Drag drop from world to UI?
« on: August 31, 2016, 09:26:13 AM »

We have a horizontal scrollview/inventory at the bottom of the screen where you can drag objects/train cars into the scene to build your train (2d game). Works fine. I want to go the other way around now. I want to click on a train car in the scene and be able to drag/drop it back to the UI.

One approach I could try is manually picking it up and handle moving it with the mouse and detect if it's released over the UI to add it back to the grid/inventory. Problem with that is depth. It will always appear behind the UI because of depth/sorting issues cause the UI renders on top.

The other approach which I'm trying now is to 'simulate' a UI drag. So when I click on a car in the scene, I 'instantly' add it to the grid, and then send an NGUI 'drag' event of some sort which will snap it to the mouse position and perform its drag.

But I'm not sure how to exactly achieve the latter. I tried calling 'StartDragging' from UIDragDropItem but it didn't do anything. Digging more into the code (UICamera) it seems I have to create a touch or mouse event? I'm not sure.

Maybe there is a better way of doing this?

Any ideas or pointers are appreciated?


On Android, we're having a weird issue where if we build our game with any version of Unity above 5.3.4 we get visual bugs where UI sprites are all black and no fonts render on the screen. We use the latest NGUI. Weird thing if you run the game once it works fine, but if you force-close and reopen the glitches appear, if you restart they disappear, if you restart again they reappear, etc.

Unity forums thread crosslink for adb logs and more details:

Any ideas what's wrong?

[EDIT]: Seems like setting the max atlas texture size to 2kx2k fixed it for one of our games. But we have another game that we tried building (same NGUI, same Unity, same texture settings etc) that still shows black textures.

i.e. support handlers of type "void handler(T arg)" and not just "void handler(void)" - (By handler I mean the target method to be called in the MB to be notified)


NGUI 3 Support / Can you add editor classes support to EventDelegates?
« on: February 26, 2014, 11:39:20 AM »
I have a RenameNotifer MonoBehaviour attached to some of my gameObjects, whenever there's a change in their name, it notifies a method in their editors. However, I had to make a slight adjustment for the delegate to be executed:

  1.                         if (Application.isPlaying) {
  2.                                 call();
  3.                         }
  4.                         else if (call.Target != null) {
  5.                                 System.Type type = call.Target.GetType();
  6.                                 object[] objs = type.GetCustomAttributes(typeof(ExecuteInEditMode), true);
  7.                                 if (objs != null && objs.Length > 0
  8.                                         || type.IsSubclassOf(typeof(UnityEditor.Editor)))
  9.                                         call();
  10.                         }

Can you add this to NGUI's code?


I'm all out of words describing this - see attachment. I'm not sure if this is an issue with the debugger, or... Idk.

NGUI 3 Support / NullReferenceException from NGUITransformInspector?
« on: February 13, 2014, 03:06:33 AM »
Been getting this error quite a lot recently even with the latest NGUI so I thought you should know about it.

  1. NullReferenceException: (null)
  2. UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/SerializedPropertyBindings.cs:69)
  3. UnityEditor.Editor.GetSerializedObjectInternal () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/EditorBindings.cs:117)
  4. UnityEditor.Editor.get_serializedObject () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/EditorBindings.cs:110)
  5. NGUITransformInspector.OnEnable () (at Assets/External/NGUI/Scripts/Editor/NGUITransformInspector.cs:168)

It happens during editor-time - My console gets blown with +999 errors.

There's also the same error for GameObjectInspector too - "Inspector/GameObjectInspector.cs:91"


I have a "MonoBehaviour" with a "List<EventDelegate>" called "onUse" - In my custom editor, I just want to get a 'valid' reference to "onUse" via serialized properties, and then cast the property back to a List<EventDelegate> so that I could draw it - But I'm failing though.

I'm getting the property successfully:
  1. sp_onUse = serializedObject.FindProperty("onUse");

But I don't know what to do here:
  1. NGUIEditorTools.DrawEvents("On Use", use, ???);

On the side: I see in your editor scripts, sometimes you use SerializedProperties and other times you manually register for undo and use target instead. I can see two reasons why you would use target: 1- you wrote the editors before SerailizedProperties came about 2- (same reason I don't use SPs) SPs are very annoying, unpredictable and really tough to work with, debug, etc.

What approach you suggest I go forward with? stick with target and manually register undo, multiple edit, etc? or Wrestle with SPs?

Thanks a lot in advance.

The new anchoring system overcomes the weaknesses in the old system and it does a better job than the previous Anchor+Stretch.

But it's really annoying in terms of practical usage - I mean, I just wanna anchor something to the top left corner of a background, it's just so tedious... What should I do with those 4 values? Previously, I just set the anchor to topleft and that's it. Now we have 4 values... what for? (I've seen the anchor demo video - but it just didn't cut it... )

Please explain what those four values mean - (what does it mean for the right of my object, to be in the right/center/left, etc of the target?)

I just have a very simple Colored slider that I want to anchor to the topleft of a background yet no matter how much I mess with the values, I can't seem to get the right ones....

Please explain.


So after I upgraded to 3.0.6 - I "accidentally" opened an old atlas (created in 2.6.4) - Now I'm stuck with a broken atlas maker (See attachment), since now NGUI "remembers" stuff - Closing/Reopening Unity won't fix it - NOR does removing and re-importing NGUI!!

I'm now stuck with a broken atlas maker - I can't do anything.

What can be done about this? - Where does NGUI "remember" stuff? Is there a clear cache button or some cache some where that I could erase?

@Aren please this problem has been around for a while now and I know I'm not the first one to come across it.

(For the future: Please consider removing the atlas thing all together, or at least, make it transparent user-wise)


EDIT: Just read you patched it - well, it's still there it seems.

EDIT: Check out the attachment, for the latest full screen version of the bug :D - I can't minimize, nor do anything but stare at it. (Happens automatically when opening the AtlasMaker)

In my inventory, I add and rotate items. But when I rotate and then add, things go wrong since the pivot hasn't been adjusted.

Adding - (in Item.cs):
  1. public void Notify_HasBeenAdded(Slot toSlot)
  2. {
  3.         // stuff
  4.         cachedTransform.localPosition = toSlot.cachedTransform.localPosition;
  5.         // stuff
  6. }

  1. public void RotateItem(RotationDirection rotDir)
  2. {
  3.         // stuff
  4.         var tween = TweenRotation.Begin(parent.gameObject, rotAnimTime, parent.localRotation * Quaternion.Euler(0, 0, (rotDir == RotationDirection.Clockwise) ? -90 : 90));
  5.         // stuff
  6. }

When I rotate and then add, here's how it looks - See attachment - It was originally topleft, I rotated 90 dgs clkwise, if you look at it, you wouldn't think the pivot is topleft, it would look like as if it was topright, right? but in fact, it's still topleft but rotated.

Using localCorners wouldn't work here cause it relies on getting the offset from the pivot, which is topleft, but looks like topright.

I solved this problem by writing a piece of code that adjusts the pivot according to the rotation.
But I don't wanna use that - it's just not very reusable. So I thought, why not write a method that sets a REAL corner in a widget to a certain position? Like: widget.SetCornerTo(Corners.TopLeft, pos); - That way I could always set the REAL top left corner, without having to worry about rotation, pivots, etc.

I tried, and came up with a formula that says:
  1. newPos = reqPos + (realPivotOffset X realDimensions)

  1. newPos: is the position where the widget will reside by its real pivot.
  2. reqPos:  is the position required to set a certain corner at.
  3. realPivotOffset: is the dist from the corner we're trying to set and the real pivot.
  4. realDimensions: is the real dimensions of the widget - taking rotation into consideration.

I'm having trouble getting it to work since I can't seem to find a way to get the realPivotOffset.

realDimensions is easy to find. Originally, the sprite was 150x100 - when I rotated 90 dgs the real dims are 100x150, rotate again back to 150x100, etc. So:

  1. if (widget.localRotation.x % 180 == 90) {
  2.     reaDim.width = widget.height;
  3.     reaDim.height = widget.width;
  4. } else {
  5.     reaDim.width = widget.width;
  6.     reaDim.height = widget.height;
  7. }

But just to illustrate, in my attachment example (2nd picture) - (let's set the topleft corner) it would be:
  1. newPos = reqPos + ((1, 0) X (100, 150)) // the gun is actually 150x100, but since it's rotated, it's now 100x150
  2.                                   // the (1, 0) is the dist from the topleft corner, to the real pivot at the topright
  3. newPos = reqPos + (100, 0)
  4. newPos = reqPos + (width, 0)

If it wasn't for rotation, it would be as simple as:
  1. 0- cache the original pivot.
  2. 1- set the current pivot to the required corner.
  3. 2- set the widget's position to the required position.
  4. 3- rollback to the original pivot.

I also thought of multiplying the localCorners by a transformation (rotation) matrix - that rotates the corners by the rotation of the item - But no idea how to do that... Not even sure how it would help.

To recap, how can I set a widget's position by its corners regardless of its rotation or original pivot? - Something like widget.SetTopLeft(pos);

Thanks a lot!

PS: Had to write the question twice [very frustrating] since the site logged me out the first time I tried to submit.

NGUI 3 Support / Sprite dimensions don't correspond to screen dimensions?
« on: November 23, 2013, 06:05:26 AM »
This is one of those weird things that I've always wanted to get rid of in NGUI.

I have a sliced sprite of 150x100 dimensions. Yet if I click on its right-most edge, I get an x value of around 125, and not 150! (See attachment)

  1. var screen = NGUITools.FindCameraForLayer(fromSlot.gameObject.layer).WorldToScreenPoint(Slot.background.cachedTransform.position);
  2. float x = (Input.mousePosition.x - screen.x);
  3. float y = (screen.y - Input.mousePosition.y);
  4. Debug.Log("x: " + x + "y: " + y);

I need this to figure our how many slots I'm clicking away from the top-left slot. After I get the difference, I divide by the slot's template size (50) to get the right number:

  1. // continuation from previous code...
  2. float colDif = x / Owner.SlotSize;
  3. float rowDif = y / Owner.SlotSize;
  4. Debug.Log("col: " + Mathf.FloorToInt(colDif) + " rowDif: " + Mathf.FloorToInt(rowDif) + " sSize: " + Owner.SlotSize);
  5. AddingOffset = new Index2D((int)rowDif, (int)colDif);

This will only work well, if I get a correct x and y. But since they're a bit lesser than the original values (~125 and not 150 for the width, and ~80 and not 100 for the height), my calculations all will go wrong.

Can somebody tell me why this is happening, and how to go about doing it the right way?

Thanks a lot!

NGUI 3 Support / [SOLVED] Can't get the right on-screen coords of a widget?
« on: November 23, 2013, 03:46:52 AM »

WorldToScreenPoint is acting funny with me - as I'm not able to use it to calculate the right on-screen coords of the top left corner of my inventory slot. See my question if you so please:

I don't know why but, I think there's some NGUI factor related to the problem.




I'm still working on my inventory system - I keep finding better ways of doing stuff.

My items in the scene are just gameObjects, with a hierarchy of:

Item: (Has Item script)
-- Model
-- Sprite (Has UISprite)

Of course, one should add widgets to a panel otherwise it wouldn't look right - I was wondering if there's a way to create a sprite just like that (outside a panel) - And then when the item is picked, it gets added to my inventory (which has a panel) - I was hoping I could do that, and the sprite would correct itself- Since the item's parent now is a slot in the inventory - But it didn't seem to correct itself too well.

I tried:
  1. sprite.ParentHasChanged();

  1. sprite.panel.Refresh();

But none worked :(

Again, I'm creating the sprite in a gameObject (the item) outside any panel - and then adding the item to the inventory which has a panel. How can I tell the item's sprite to correct itself?

If I can't do that, what's the right approach?

Thanks! :)

PS: Currently, I have an ItemTemplate reference in my inventory, whenever I add an item, I instantiate that template and add it as a child to the item and then set the atlas and sprite accordingly all in code. But I found that to be a bit of a hassle - I'm really hoping to get it working the way I want (ie create the sprite outside)

Pages: [1] 2 3 4