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

Pages: [1] 2 3 ... 8
1
NGUI 3 Support / UIPanel.enabled being set to false somehow.. any ideas?
« on: January 10, 2017, 04:38:54 PM »
Near as I can tell, I dont have any code doing this, but it's definitely happening and I cant find out why since I cant attach the debugger to the built-in ".enabled" property.

Anyone have any ideas how a UIPanel might be set to disabled in a way that's not obvious? (Not the gameobject, the UIPanel script itself). There was no exception in the debug log.

2
NGUI 3 Support / Using overflow ellipsis with 'resize freely' + 'max width'
« on: December 22, 2016, 01:11:09 PM »
I am using a UITable to center a combination of UISprite + UILabel within a 180 width region. This means that I cannot use 'clamp' content since it won't change the bounds of the text, making the content centering behavior of UITable not possible.

I do also want the ellipses for when the text hits the limits of the space (which I set using MaxWidth of 144), so I looked at UILabel and saw that at line 1337, there is the following code...

  1. bool fits = NGUIText.WrapText(printedText, out mProcessedText, true, false,
  2.         mOverflowEllipsis && mOverflow == Overflow.ClampContent);

which I changed to...

  1. bool fits = NGUIText.WrapText(printedText, out mProcessedText, true, false,
  2.         mOverflowEllipsis);

and it appears to be working perfectly (aside from the fact that I cant toggle the ellipses easily in the inspector). Does this seem like a fairly safe change?

3
NGUI 3 Support / Re: Content driven label size with min/max pixel size
« on: September 13, 2016, 12:36:27 PM »
The problem is I would need something like "NGUIText.GetStartOfLineThatFits" but that doesn't exist, and with all the context stuff it's pretty messy to to add it anywhere besides the same class.

4
NGUI 3 Support / Content driven label size with min/max pixel size
« on: September 11, 2016, 11:38:11 PM »
I've been struggling to find a way to get this to work. I can have "resize freely" or "clamp content", but there is no option that lets allows both.

I could just set it to a fixed size of 300, but I need the label to grow/shrink due to having a background sprite anchored to it.

(NGUIText.GetEndOfLineThatFits is almost what I need (with some extra custom code), but it's giving the wrong side of the string.)

5
NGUI 3 Support / Re: Widget.worldcorners not updating same frame
« on: September 07, 2016, 03:33:25 PM »
SetAnchor already calls both Reset and Update.

What type of object is "TargetThing"? worldCorners has a different implementation for different UI components.

6
NGUI 3 Support / Re: DragDropItem + UICamera Rotation Issue
« on: September 07, 2016, 03:28:13 PM »
Can you not rotate the interface instead? Just curious.

I dont think the issue is NGUI since it's probably just relying on Unity functions to provide the position data.

7
NGUI 3 Support / Re: NGUI 3.10 Unity 5.4 DragDropItem bugs
« on: September 04, 2016, 12:55:09 PM »
Sorry for the delay on this (I dont normally work on OSX).

The stats window, screen.width/height, and NGUITools.screenSize are all the same consistent value.

8
NGUI 3 Support / Re: UI2DSpriteTight (community script)
« on: September 03, 2016, 05:09:31 AM »
ArenMook, I created a quick demonstration video of the issue. I do think this is something you might want to address. When I said it affected mSprite, I meant via use of NGUI's provided UI2DSpriteEditor inspector script.

https://dl.dropboxusercontent.com/u/48790176/UI2DSprite_mSprite_bug.mp4

9
NGUI 3 Support / UI2DSpriteTight (community script)
« on: September 02, 2016, 03:43:01 PM »
See http://www.tasharen.com/forum/index.php?topic=14818.0 for background

Our game has been needing to use tightly packed sprites as much as possible to reduce fill rate and texture usage (Unity is very efficient if you let it use 'tight' packing).

The only downside was that NGUI did not support tight sprites due to most of the internals being based around quads. However, NGUI did not seem to care if the quads were rectangular; nor did it care if they were continuous quads or not. Just that the amount of vertices was a multiple of 4. Unity tightly packed sprites are more like traditional meshes. They are based on being multiples of 3 since they're based on triangles, not quads.

During the process of trying to convert NGUI to work with "multiple of three" meshes, I realized that I could instead just add an extra vertex to each triangle to make it technically a quad- even though the second triangle of the quad would be perceptually invisible. ArenMook confirmed my suspicion, that the few extra vertices shouldn't really cause any noticeable performance hit.

ArenMook, if you want to adopt this into NGUI, feel free to do so. If anyone finds concrete ways to improve the code, please reply to this thread. There may be a few minor bugs.

Note to users: Currently, "Type" is forced to "Simple" since the OnFill math for doing fancier types (Filled, etc) would be pretty complex and outside of my purview.

UI2DSpriteTight.cs (rev 5)
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditMode]
  4. [AddComponentMenu("NGUI/UI/NGUI Unity2D Sprite (Tight)")]
  5. public class UI2DSpriteTight : UI2DSprite
  6. {
  7.     protected override void Awake()
  8.     {
  9.         base.Awake();
  10.  
  11.         if (sprite2D != null && (!sprite2D.packed || sprite2D.packingMode != SpritePackingMode.Tight))
  12.         {
  13.             Debug.LogWarning(GetType() + " should generally only be used on tightly packed sprites!");
  14.         }
  15.  
  16.         if (type != Type.Simple)
  17.         {
  18.             type = Type.Simple;
  19.  
  20.             Debug.LogWarning(GetType() + " does not support complex sprite types! Forcing simple type.");
  21.         }
  22.     }
  23.  
  24.     public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color> cols)
  25.     {
  26.         var spr = sprite2D;
  27.         if (spr == null) return;
  28.  
  29.         var colFlat = drawingColor;
  30.         var sprUVs = spr.uv;
  31.         var sprVerts = spr.vertices;
  32.         var tris = spr.triangles;
  33.         var texRect = spr.rect;
  34.  
  35.         var flip = FlipScalar;
  36.         var size = new Vector2(mWidth, mHeight);
  37.         var scale = new Vector2(size.x / texRect.width * flip.x, size.y / texRect.height * flip.y) * spr.pixelsPerUnit;
  38.         var pivotOff = -size / 2F + Vector2.Scale(size, pivotOffset);
  39.  
  40.         if (FixedAspect) scale.x = scale.y = Mathf.Min(scale.x, scale.y);
  41.  
  42.         for (int i = 0; i < tris.Length; ++i)
  43.         {
  44.             var index = tris[i];
  45.             var vertBase = Vector2.Scale(sprVerts[index], scale);
  46.             var vert = vertBase - pivotOff;
  47.             var uv = sprUVs[index];
  48.             var col = mApplyGradient ? (Color.Lerp(mGradientBottom, mGradientTop, (vertBase.y + size.y * 0.5F) / size.y) * color).GammaToLinearSpace() : colFlat;
  49.  
  50.             verts.Add(vert);
  51.             uvs.Add(uv);
  52.             cols.Add(col);
  53.  
  54.             if (i % 3 == 0)
  55.             {
  56.                 verts.Add(vert);
  57.                 uvs.Add(uv);
  58.                 cols.Add(col);
  59.             }
  60.         }
  61.  
  62.         if (onPostFill != null)
  63.             onPostFill(this, verts.size, verts, uvs, cols);
  64.     }
  65.  
  66.     private Vector2 FlipScalar
  67.     {
  68.         get
  69.         {
  70.             switch (mFlip)
  71.             {
  72.                 case Flip.Horizontally: return new Vector2(-1F, 1F);
  73.                 case Flip.Vertically: return new Vector2(1F, -1F);
  74.                 case Flip.Both: return new Vector2(-1F, -1F);
  75.                 default: return Vector2.one;
  76.             }
  77.         }
  78.     }
  79.  
  80.     public override Type type
  81.     {
  82.         get
  83.         {
  84.             return Type.Simple;
  85.         }
  86.  
  87.         set
  88.         {
  89.             if (base.type != Type.Simple) base.type = Type.Simple;
  90.         }
  91.     }
  92.  
  93.     private bool? fixedAspect = null;
  94.     protected bool FixedAspect
  95.     {
  96.         get
  97.         {
  98.             if (fixedAspect == null)
  99.             {
  100.                 var valueField = GetType().BaseType.GetField("mFixedAspect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
  101.                 var value = valueField.GetValue(this) as bool?;
  102.                 fixedAspect = (value == null) ? false : value;
  103.             }
  104.  
  105.             return fixedAspect.Value;
  106.         }
  107.     }
  108.  
  109. #if UNITY_EDITOR
  110.     private Sprite lastSprite;
  111.     protected override void OnUpdate()
  112.     {
  113.         base.OnUpdate();
  114.  
  115.         if (mType != Type.Simple) mType = Type.Simple;
  116.  
  117.         if (Application.isPlaying && sprite2D != lastSprite)
  118.         {
  119.             lastSprite = sprite2D;
  120.  
  121.             OnInit();
  122.         }
  123.     }
  124. #endif
  125. }
  126.  

UI2DSpriteTightEditor.cs (rev 2)
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Sprites;
  4.  
  5. [CanEditMultipleObjects]
  6. [CustomEditor(typeof(UI2DSpriteTight), true)]
  7. public class UI2DSpriteTightEditor : UI2DSpriteEditor
  8. {
  9.     UI2DSpriteTight mySprite;
  10.  
  11.     protected override void OnEnable()
  12.     {
  13.         base.OnEnable();
  14.  
  15.         mySprite = target as UI2DSpriteTight;
  16.     }
  17.  
  18.     public override void OnPreviewGUI(Rect rect, GUIStyle background)
  19.     {
  20.         if (mySprite != null && mySprite.sprite2D != null)
  21.         {
  22.             Texture2D tex = mySprite.mainTexture as Texture2D;
  23.  
  24.             NGUIEditorTools.DrawSprite(tex, rect, mySprite.color, CalculateTextureRect(mySprite.sprite2D), mySprite.border);
  25.         }
  26.     }
  27.  
  28.     private static Rect CalculateTextureRect(Sprite spr)
  29.     {
  30.         int w = spr.texture.width, h = spr.texture.height;
  31.         var padding = DataUtility.GetPadding(spr); // (x=left, y=bottom, z=right, w=top)
  32.         var uv = DataUtility.GetOuterUV(spr);
  33.  
  34.         return new Rect(
  35.             new Vector2(w * uv.x - padding.x, h * uv.y - padding.y),
  36.             new Vector2(w * (uv.z - uv.x) + padding.x + padding.z, h * (uv.w - uv.y) + padding.y + padding.w)
  37.         );
  38.     }
  39. }
  40.  

Note to ArenMook: My call to OnInit() in OnUpdate() fixes a bug that affects the parent class (UI2DSprite) as well, so you may want to adopt it. It happens when changing mSprite directly (via inspector serialization) when the game is running. It manifests as totally wrong UV values but correct vertex geometry.

10
It's very simple to create your own DragScrollView type class. I do it all the time just so I dont have to extend UIDragScrollView for my 'node' classes.

11
Found a workaround for the "vertices % 4 == 0" rule which is implicitly required / enforced in many spots with NGUI.

Unity's tightly packed Sprites are based on triangles. By adding the first vertex of each tri twice, it effectively turns every triangle into a quad. A very deformed quad with one half effectively invisible (a volume of ~0), but still technically a quad and it seems to work for NGUI (even works with soft clipping panels).

It would be awesome if I can find a way to make NGUI play nice with multiple-of-three vertices meshes, but at least this looks 100% correct and allows for basic use of tight sprites with UI2DSprite. Hopefully the extra phantom vertex doesn't hurt performance much.

  1. if (mSprite.packed && mSprite.packingMode == SpritePackingMode.Tight)
  2. {
  3.     var gc = drawingColor;
  4.     var sprUVs = mSprite.uv;
  5.     var sprVerts = mSprite.vertices;
  6.     var tris = mSprite.triangles;
  7.     var ppu = mSprite.pixelsPerUnit * pixelSize;
  8.  
  9.     for (int i = 0; i < tris.Length; ++i)
  10.     {
  11.         var index = tris[i];
  12.         verts.Add(sprVerts[index] * ppu);
  13.         uvs.Add(sprUVs[index]);
  14.         cols.Add(gc);
  15.  
  16.         if (i % 3 == 0)
  17.         {
  18.             verts.Add(sprVerts[index] * ppu);
  19.             uvs.Add(sprUVs[index]);
  20.             cols.Add(gc);
  21.         }
  22.     }
  23.  
  24.     return;
  25. }
  26.  

12
After using the following code I found some issues with NGUI's support for geometry that isnt a quad...

  1. public override void OnFill (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color> cols)
  2. {
  3.         Texture tex = mainTexture;
  4.         if (tex == null) return;
  5.  
  6. #if UNITY_EDITOR
  7.         if (mSprite.packed && mSprite.packingMode == SpritePackingMode.Tight)
  8.         {
  9.             var gc = drawingColor;
  10.             var sprUVs = mSprite.uv;
  11.             var sprVerts = mSprite.vertices;
  12.             var tris = mSprite.triangles;
  13.             var ppu = mSprite.pixelsPerUnit * pixelSize;
  14.  
  15.             for (int i = 0; i < tris.Length; ++i)
  16.             {
  17.                 verts.Add(sprVerts[tris[i]] * ppu);
  18.                 uvs.Add(sprUVs[tris[i]]);
  19.                 cols.Add(gc);
  20.             }
  21.  
  22.             return;
  23.         }
  24. #endif
  25.  
  26. (rest of method was unchanged)
  27.  

UIDrawCall.GenerateCachedIndexBuffer runs into an IndexOutofRangeException at line 557. I'm guessing this is due to the draw call expecting quads and making certain assumptions in how it reads the vertices. Seems to be something that can NOT be ignored.

UIDrawCall.UpdateGeometry assumed the geometry is bad due to part of the IF check that looks for "(verts.size % 4) == 0". I had to remove that one check and then it seemed to behave fine.

UI2DSpriteEditor.OnPreviewGUI cannot render a preview at line 89 since it also expects a quad based sprite. Though this is easy to skip for tightly packed sprites, for the short term, by adding more conditions in the IF check.

Lastly, the mesh looks 75% correct but the mesh is drawn out of order with several extra triangles even though I'm pretty sure I have the right ordering code for mesh rendering. I'm guessing this is also due to NGUI expecting quads for the mesh, like GenerateCachedIndexBuffer.

(for attachment: left image is UI2DSprite, right image is SpriteRenderer)

13
ArenMook or whomever might know:

Our game uses a lot of sprites that benefit hugely from using tight packing. Rectangle based packing is wasting a lot of valuable texture memory and forces us to mix in SpriteRender components with our NGUI components in cases where we simply cannot afford rectangle based packing in our texture budget.

Edit: Read the last most post for the semi hacky approach that mostly works for using tightly packed sprites with UI2DSprite. This seems like the most realistic way to do it until/unless NGUI supports drawing meshes based on triangles rather than quads.

14
NGUI 3 Support / Re: NGUI 3.10 Unity 5.4 DragDropItem bugs
« on: August 06, 2016, 05:34:27 PM »
I believe it happened in 5.3 as well. It may happen in other spots (besides the editor) but I only observed it in the editor, myself.

Standalone builds worked fine on the same device.

OS X 10.11.4 (El Capitan) on a MacBook Pro (Retina, 13-inch, Early 2015).


15
NGUI 3 Support / Re: NGUI 3.10 Unity 5.4 DragDropItem bugs
« on: August 05, 2016, 03:04:05 AM »
@ArenMook I've also noticed the same issue with DragDropItem moving too fast on high DPI screens. It does not stay with the cursor and seems to definitely be DPI related. It's not an issue on iPads, but always happens with OSX Retina screens while in the Editor.

@markofevil3, as far as OnDragDropRelease and OnDragEnd not firing, that shouldn't happen unless you are interfering with the collider somehow. Are you disabling the parent or something? Recent versions of NGUI are less tolerant when you do that. Older versions were more tolerant.

Pages: [1] 2 3 ... 8