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

Pages: [1]
1
NGUI 3 Support / Re: Update UI2DSprite.sprite2D in place
« on: July 09, 2014, 10:02:31 PM »
Thanks it works! Do you think it worth to update NGUI upstream for this patch?

2
NGUI 3 Support / Support custom pivot like Unity Sprite?
« on: July 09, 2014, 07:16:17 AM »
Just curious if there's plan to support custom pivot like Unity Sprite x => (0, 1), y => (0, 1). Current implementation limited to Left, Right, Center, Top and Bottom. Sometime I do find that's convenience to use this feature to rotate special sprite without wrapper it with a parent GameObject.

3
NGUI 3 Support / Re: Update UI2DSprite.sprite2D in place
« on: July 08, 2014, 10:10:43 PM »
Attached an example project so you can debug. The left sprites are rendered by Unity Sprite, the right ones are rendered by UI2DSprite. All animated by Unity Animation Panel. Try play to see the sprites "flash" and toggle the nextSprite line in UI2DSpriteAnimationHelper.cs to see the 1 frame delay (hat should be animated to perfect follow the hero sprite animation)

4
NGUI 3 Support / Re: Update UI2DSprite.sprite2D in place
« on: July 08, 2014, 09:57:13 PM »
I have set my script execution order before UIPanel, problems remain.

- If I assigned UI2DSprite.sprite2D in script, no matter in LateUpdate or Update, the sprite will be removed from screen in current frame => make the sprite looks "flash".
- Change UI2DSprite.nextSprite works fine, (I guess for the current way NGUI works, UI2DSprite.sprite2D has to be updated in UI2DSprite.OnUpdate like the way nextSprite be handled). However that will intro 1 frame delay in animation.


5
NGUI 3 Support / Update UI2DSprite.sprite2D in place
« on: July 08, 2014, 08:15:19 AM »
Hi, I want to change UI2DSprite.sprite after "unity internal animation update", so I can sync my UI2DSprite with Unity SpriteRenderer.sprite. According to "Execution Order of Event Functions" (http://docs.unity3d.com/Manual/ExecutionOrder.html) I need put the logic in LateUpdate callback. however if I change UI2DSprite.sprite2D directly, it will be removed from screen 1 frame whenever the sprite changed. If I change UI2DSprite.nextSprite, it will delay 1 frame. Any idea for this?

My intention to sync UI2DSprite with SpriteRenderer is that, I want to animate sprite with Unity Animation Panel (Dope Sheet) and manage display using NGUI. Some complex animation requires coordinate with other objects carefully, so I prefer this way.

Here's my code,

  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Small script that sync SpriteRenderer.sprite to UI2DSprite.nextSprite.
  5. /// </summary>
  6.  
  7. [RequireComponent(typeof(UI2DSprite))]
  8. [RequireComponent(typeof(SpriteRenderer))]
  9. [ExecuteInEditMode]
  10. public class UI2DSpriteAnimationHelper : MonoBehaviour
  11. {
  12.         UnityEngine.SpriteRenderer mUnitySpriteRdr;
  13.         UI2DSprite mNguiSprite;
  14.  
  15.         void Awake()
  16.         {
  17.                 mUnitySpriteRdr = GetComponent<UnityEngine.SpriteRenderer>();
  18.                 mNguiSprite = GetComponent<UI2DSprite>();
  19.                 mUnitySpriteRdr.enabled = false;
  20.         }
  21.  
  22. #if false
  23.         void Update()
  24.         {
  25.                 if (Application.isEditor && !Application.isPlaying)
  26.                         LateUpdate();
  27.         }
  28. #endif
  29.        
  30.         void LateUpdate()
  31.         {
  32.                 if (mNguiSprite.sprite2D.name != mUnitySpriteRdr.sprite.name) {
  33.                         mNguiSprite.sprite2D = mUnitySpriteRdr.sprite;
  34.                         // mNguiSprite.nextSprite = mUnitySpriteRdr.sprite;
  35.                 }
  36.         }
  37. }
  38.  

6
NGUI 3 Support / Re: Weird Clipping Panel.IsVisible(Vector3) result
« on: June 29, 2014, 01:04:46 AM »
Yes, fixed.

7
NGUI 3 Support / Re: Weird Clipping Panel.IsVisible(Vector3) result
« on: June 26, 2014, 01:30:55 PM »
Great, will double check after receiving the Friday update. Thanks!

8
NGUI 3 Support / Re: Weird Clipping Panel.IsVisible(Vector3) result
« on: June 25, 2014, 12:48:18 PM »
Sure, see the zip in attachment.

9
NGUI 3 Support / Weird Clipping Panel.IsVisible(Vector3) result
« on: June 25, 2014, 05:44:03 AM »
  1. UI Root           # panel.depth = 0
  2.   Camera
  3.     Panel         # height = 800
  4.       Bg Collider # a full screen collider
  5.       Clip Panel  # panel.depth = 1, size 300x300
  6.         Button
  7.  

In a simple 2d UI setup as above, I put a full screen "Bg Collider" at the bottom and a small "Clip Panel" with a "Button" inside on the top. Kind like a trivial modal dialog. If I click the button, it will response me. If I click the rest part of the screen, the "Bg Collider" will capture the event to avoid it pass to any widgets behind the panel. Now the tricky thing is that if I changed transform.localPosition.y of "Clip Panel" to any number bigger than 150, say 160, the button will no longer receive the event.

Digging into NGUI source code, I found that in UICamera.Raycast(Vector3 inPos), mHits will be [Button,Bg Collider], but later IsVisible(lastWorldPosition, Button)) return false. But it shouldn't.

If change the "Clip Panel" to no clipping, then it works again.

Is this a bug? or I shouldn't move a clipping panel by change it's transform?

Please check out the test project at https://bitbucket.org/favoyang/2dhitordertest (you need import NGUI 3.6.5)

10
Same issue in v3.6.2, but only happens if changes the UILabel.text while it's inactive.

11
NGUI 3 Support / Re: iPhone 5 Height and different aspect ratio
« on: January 15, 2013, 10:10:55 AM »
I have similar issue that the game is original designed on 3:2 screen, then need support 16:9 aspect ratio for iPhone5, 4:3 ratio for iPad. My approach is that 1) keep 3:2 as default design ratio which is the mid aspect ratio of [1.33, 1.5, 1.75], 2) use UIAnchor to adjust UI to stick to edge. However, sometime the 16:9 ratio is too taller / narrower that some UI get cropped.

So I use below script to adjust UIRoot.manualHeight to make it UIRoot follow manualWidth instead of manualHeight. For example, if pick 3:2 as default ratio, UIRoot.manualHeight = 960. Then you need set manualWidth to 640. During runtime, the script will change UIRoot.manualHeight to 1136 on iPhone5, so the width will be 640 as expected.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. // The script make UIRoot scale based on manualWidth instead of UIRoot.manualHeight.
  5. // if current aspect ratio > maxAcceptAspectRatio.
  6. [RequireComponent(typeof(UIRoot))]
  7. public class UIRootHelper : MonoBehaviour {
  8.  
  9.     UIRoot uiRoot;
  10.     public int manualWidth;
  11.     public float maxAcceptAspectRatio = 1.67f;
  12.  
  13.     void Awake() {
  14.         uiRoot = GetComponent<UIRoot>();
  15.     }
  16.  
  17.     void OnEnable() {
  18.         UpdateHeight();
  19.     }
  20.  
  21.     void UpdateHeight() {
  22.         float aspect = (float)Screen.height / Screen.width;
  23.         if (aspect > maxAcceptAspectRatio) {
  24.             // Change manualHeight to simulate scale based on manualWidth.
  25.             int manualHeight = (int)(manualWidth * aspect);
  26.             if (uiRoot.manualHeight != manualHeight)
  27.                 uiRoot.manualHeight = manualHeight;
  28.         }
  29.     }
  30. }
  31.  

12
Yes, padding only for specific rows.

13
NGUI 3 Support / UITable children paddings and HTML/CSS box concept.
« on: July 26, 2012, 09:54:38 PM »
I use UITable to layout a form like UI, so the row size can match the content size.

There's an issue for UILabel only rows, that I need some extra paddings. The workaround is that wrap the row with a dummy UISlicedSprite background object, which describes the row size. Then disable the UISlicedSprite component, so it's not get rendered. A bit complicated and if the UILabel size changed, I have to manually calculate UISlicedSprite size.

I wonder shall NGUI add a box concept like the one in HTML/CSS. So that each UI element have a padding concept and know it's actually size. Then UITable / UIAnchor can aware of that property.

14
NGUI 3 Support / Atlas with mipmapEnabled=true looks blur
« on: May 06, 2012, 02:35:55 AM »
I found texture atlas by default with mipmapEnabled=true. This caused the my UI layer looks blur. Is there any reason to keep it on?

Pages: [1]