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

Pages: [1] 2 3 ... 8
1
NGUI 3 Documentation / Re: UILabel
« on: March 17, 2015, 07:00:00 AM »
I would love to have a bbcode-like tag like so:

  1. label.text = "I'm a text with [size=+10] big parts[/size] and [size=-10] small parts[/size] and a [size=14]absolute sized part[/size]"
  2.  

To generate a single label with multiple sizes

I'm a text with big parts and small parts and an absolute sized part.

Since designers tend to want that and right now I have to create multiple UILabels and align them and all sorts of shenanigans to fill out each individual label with data.

I second this. Designers sure can get sad when you deny them this... :)

2
Your functionality makes the image no longer correspond to the collider dimensions. My approach does, but  it also makes it not work if you happen to have it constrained and try to use it as a slider's foreground (as that's what drawRegion was originally written for). The way I see it the incompatibility with being a slider's foreground when the option is active is a lesser evil. It's not a fully ideal solution, but better.

Also, what's AspectFill? Image's texture must always remain within the bounds of the widget. It must never exceed it.

Well, now you're talking about implementation details for your framework, which much comes down to the split of widgets and panels (ideally every widget AKA "view" should be able to clip it's content).
I'm really just talking about common functionality expected in the components you try to mimic (comparing to long-time developed standards created by for example Google and Apple). Since I come from that background, that is what I mostly compare with.

See contentMode for UIView (also see the available flags): https://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/contentMode

Aspect Fill is when the content is scaled up to fill up the boundaries completely, still keeping the aspect ratio of the content (image in this case). And again, this is where the widget should be able to clip its own content. Still, even without clip, it is still useful for fullscreen UITextures etc.

3
Here's another more complicated version that will make a UITexture always fit the content image within the widget's bounds:
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditMode]
  4. [RequireComponent(typeof(UITexture))]
  5. public class UIFitTexture : MonoBehaviour
  6. {
  7.         UITexture mTex;
  8.  
  9.         void Awake () { mTex = GetComponent<UITexture>(); }
  10.  
  11.         void Update ()
  12.         {
  13.                 Texture tex = mTex.mainTexture;
  14.  
  15.                 if (tex != null)
  16.                 {
  17.                         float widgetWidth = mTex.width;
  18.                         float widgetHeight = mTex.height;
  19.                         float widgetAspect = widgetWidth / widgetHeight;
  20.                         float textureAspect = (float)tex.width / tex.height;
  21.  
  22.                         if (textureAspect < widgetAspect)
  23.                         {
  24.                                 widgetWidth = widgetHeight * textureAspect;
  25.                                 float x = (mTex.width - widgetWidth) / mTex.width * 0.5f;
  26.                                 mTex.drawRegion = new Vector4(x, 0f, 1f - x, 1f);
  27.                         }
  28.                         else
  29.                         {
  30.                                 widgetHeight = widgetWidth / textureAspect;
  31.                                 float y = (mTex.height - widgetHeight) / mTex.height * 0.5f;
  32.                                 mTex.drawRegion = new Vector4(0f, y, 1f, 1f - y);
  33.                         }
  34.                 }
  35.         }
  36. }

This latter is more like it, but still missing the AspectFill-mode (also running in update).

This is default behaviour so you should really consider integrate it with UITexture (and UISprite also really).

Cheers!

4
Something like this would be trivial to do with an extra script attached to UITexture.

Not sure which definition of trivial you sought for, but my point was more in the way that this should be part of the implementation already and not something you "mod in, in case you need it" (if that's what you meant).

5
Got a little surprised when there was no option to set "Aspect Ratio" (eg. Aspect fit & aspect fill) for a UITexture. No need to argue about the numerous times the aspect is not known until runtime (downloaded textures).

Just to be clear, the current "Aspect Ratio"-setting is not what I mean. One should be able to set the UITexture-widget to be of any size, but let the raw texture be rendered within this rect based on a setting that is either "Fill", "Aspect Fit" or "Aspect Fill" (leaving am empty area in the case if aspect fit). That way you can show textures with different resolutions within the same rect. Just a guess is that this should be calculated in the UITexture.drawingDimensions.

Any plans on implementing this with a nice drop-down list in the inspector? Mandatory IMO.

Cheers!

Edit.
Just to save you the trouble, I wrapped up a quick solution (needs minor optimisations, like caching of values etc.).

UITexture.cs:

  1. public enum AspectRatio{
  2.                 Fill,
  3.                 AspectFill,
  4.                 AspectFit
  5.         }
  6.         [SerializeField, HideInInspector] private AspectRatio m_AspectRatioMode = AspectRatio.Fill;
  7.         public AspectRatio AspectRatioMode{
  8.                 get{
  9.                         return m_AspectRatioMode;
  10.                 }
  11.                 set{
  12.                         if(m_AspectRatioMode != value){
  13.                                 m_AspectRatioMode = value;
  14.                                 MarkAsChanged();
  15.                         }
  16.                 }
  17.         }
  18.  
  19. [...]
  20.  
  21. public override Vector4 drawingDimensions
  22.         {
  23. Vector2 size = localSize;
  24.  
  25.                         if(mainTexture != null){
  26.                                 switch (m_AspectRatioMode) {
  27.                                 case AspectRatio.Fill:
  28.                                         break;
  29.                                 case AspectRatio.AspectFill:
  30.                                 {
  31.                                         Vector2 maxSize = size;
  32.                                        
  33.                                         float xRatio = maxSize.x / mainTexture.width;
  34.                                         float yRatio = maxSize.y / mainTexture.height;
  35.                                         float maxRatio = Mathf.Max(xRatio, yRatio);
  36.                                        
  37.                                         size = new Vector2(mainTexture.width * maxRatio, mainTexture.height * maxRatio);
  38.                                 }
  39.                                         break;
  40.                                 case AspectRatio.AspectFit:
  41.                                 {
  42.                                         Vector2 maxSize = size;
  43.  
  44.                                         float xRatio = maxSize.x / mainTexture.width;
  45.                                         float yRatio = maxSize.y / mainTexture.height;
  46.                                         float minRatio = Mathf.Min(xRatio, yRatio);
  47.                                        
  48.                                         size = new Vector2(mainTexture.width * minRatio, mainTexture.height * minRatio);
  49.                                 }
  50.                                         break;
  51.                                 default:
  52.                                         throw new System.ArgumentOutOfRangeException();
  53.                                 }
  54.                         }
  55. [...]
  56.  

UITextureInspector.cs:
  1. mTex.AspectRatioMode = (UITexture.AspectRatio)EditorGUILayout.EnumPopup("Aspect Mode:", mTex.AspectRatioMode);
  2.  

6
NGUI 3 Support / Re: Texture.GetPixels AFTER shading applied
« on: August 15, 2014, 07:03:26 AM »
you would want to draw the texture to a render texture (unity pro only), you could then save the render texture to PNG or draw it else where, upto you

Thanks, I'll check that out!

7
NGUI 3 Support / Texture.GetPixels AFTER shading applied
« on: August 15, 2014, 05:13:16 AM »
Hi!

This might not be considered a "pure" NGUI-question but in case it's because of how UITexture works, I ask here anyways... :)

Basically, I want to "print" a Texture2D (UITexture.mainTexture), but not the raw, default texture, but the texture AFTER the shading has been applied (like alpha, texture-flip etc., everything that get's applied in a shader). I seriously have no clue at all how to go about this: Accessing the texture from the material (tested without success)?...

Any thoughts? Thanks!

Edit. Or is it just so easy that I wait for end of frame using a coroutine?
  1. yield  return new WaitForEndOfFrame();
  2.  

Edit2. Nope.

Edit3. To have a fallback-solution I read (which I knew would work, but want to avoid) the pixels directly from screen like this:
  1. int previousDepth = depth;
  2.                 depth = int.MaxValue;
  3.  
  4.                 yield return new WaitForEndOfFrame();
  5.  
  6.                 tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
  7.                 tex.Apply();
  8.  
  9.                 depth = previousDepth;
  10.                
  11.                 yield return new WaitForEndOfFrame(); //<-- symbolic to be in correct state when "done"
  12.  

Problem with this is that:

1. It flickers (barely noticeable though) and
2. It's more of a hack (I hate hacks).
3. It relies on the texture being at front.
4. It's just hard to maintain.

8
NGUI 3 Support / Re: soft clip panel error
« on: August 14, 2014, 08:54:22 AM »
Yes, shader replacement going by shader name. The only other alternative would be to have one shader, but have #ifdefs inside and use multi-compilation. Multiple shader approach is cleaner as it's easier to read, at least for me.

Alright.

Well the problem is that you limit the folder-path to your internal one. If I want clipping, I'll have to place my shader among yours (HIDDEN/Unlit/) to "fake" it so I don't get the clipping-warning. You should instead just look for shaderName + mClippingCount in the same folder as the current shader IMO, and get rid of all the string-checks.

9
NGUI 3 Support / Re: soft clip panel error
« on: August 14, 2014, 05:10:34 AM »
That shader doesn't come with NGUI (at least not the recent versions) and as such it doesn't support clipping.

So how does one go about supporting clipping for custom shaders? I've got a masked shader, but I also need it to be "flippable".

Edit. Oh, so you determine by shader-name? Wow... Why? Was there no more usable way? Like, just a property fetched from the shader telling nr. of clips supported?

10
NGUI 3 Support / Re: Using SetMatrix on UITexture
« on: August 13, 2014, 08:14:27 AM »
Use shader globals to pass the values that can then be used in the shader to rotate the UVs.

As suspected this is not going too well... Shader written, material.SetMatrix() used, but nothing, zip, bagel. I even found some dude with a tested shader, copy-pasted it, same calculations but still nothing... Any clue?

Look at the bottom of this page for tested solution: http://forum.unity3d.com/threads/webcamtexture-rotated-and-flipped-on-iphone-when-applied-to-renderer-material-texture.126702/

His code (but with test-values):
  1. Quaternion rotation = Quaternion.Euler(45f, 30f, 90f);
  2. Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, rotation, new Vector3(1, 1, 1));
  3. material.SetMatrix("_Rotation", rotationMatrix);
  4.  

Attached file is same as above but with color-blending.

11
NGUI 3 Support / Re: Using SetMatrix on UITexture
« on: August 12, 2014, 04:15:06 AM »
Use shader globals to pass the values that can then be used in the shader to rotate the UVs.

Hmm... Yeah that was what I've been trying actually... Must have missed something (write shaders once a year, tops...), I'll check again! TY!

12
NGUI 3 Support / Re: Using SetMatrix on UITexture
« on: August 12, 2014, 04:06:22 AM »
You can set UIWidget.onRender callback now in the last Pro version, and it receives a Material parameter inside. You can then do whatever you like to this material.

Well, I don't have pro, and I can't update to the latest version of NGUI for that matter (lots of custom implementations and we have a deadline for the current product september 1)... Any suggestions on what can be done ATM?

13
NGUI 3 Support / Re: Using SetMatrix on UITexture
« on: August 11, 2014, 09:37:56 AM »
So... I'm doing something similar (WebCamTexture with UITexture), but I also can't get the SetMatrix to take effect. Not sure if I understood what you meant (I didn't for sure), but I do have a custom shader and a material along with it setup on the UITexture, but material.SetMatrix does nothing. I can't rotate the widget because that will break the positioning and sizing of UITexture.

15
Misc Archive / Game: Try out our game "What if..."
« on: June 12, 2014, 03:08:28 PM »
To keep it short: We've released an update to our old, 48 hours jam game called "What if...". It's a simple game where you just answer "Yes" or "No" to ultimatums, and see statistics of what other people answered... Yey!

Just a quick feature-overlook (copy/paste from the change log):
  • Completely new design!
  • Submit YOUR OWN questions and follow its statistics!
  • Choose theme for the questions!
  • Choose your own background color!
  • Write your own personal message when you post a question to Facebook!
  • A LOT of new questions added every day!

TIP: If you're a little bit sadistic, save up for the "Outrageous"-mode...   8)

iOS:
https://itunes.apple.com/us/app/what-if../id708700174?ls=1&mt=8
Android:
https://play.google.com/store/apps/details?id=se.ace.whatif

Pages: [1] 2 3 ... 8