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

Pages: [1]
1
I currently use Unity 4.3.4f1.


2
NGUI 3 Support / Scrambled text with UILabel / UIFont of NGUI 3.5.7
« on: April 14, 2014, 10:55:54 PM »
Hi,

My project suffers from scrambled text with UILabel / UIFont of NGUI 3.5.7.
Scrambled text only appears when running play mode in Unity Editor, and in standalone application, everything is OK.

After debugging,
I found that when running play mode in Unity Editor,
Unity will always create object with default constructor for private fields which class has the attribute [System.Serializable], even if those fields are private.

In UIFont.cs,
  1. public class UIFont : MonoBehaviour
  2. {
  3.     ...
  4.     UISpriteData mSprite = null;
  5.     ...
  6. }
  7.  
because UISpriteData is a pure C# class with the attribute [System.Serializable],
mSprite will be initialized with default constructor when compiled managed DLLs is loaded by UnityEditor.

Therefore, when running play mode in Unity Editor, some initialization logic won'be executed because mSprite is not initialized as null.



To fix this problem,
I put attribute [System.NonSerialized] to mSprite, and it won't be initialized with default constructor anymore, and the rendering of UILabel becomes correct.

  1. public class UIFont : MonoBehaviour
  2. {
  3.     ...
  4.     [System.NonSerialized]
  5.     UISpriteData mSprite = null;
  6.     ...
  7. }
  8.  


Alvin

3
Hi,

UITable is supposed to be able to reposition inactive widgets when hideInactive property is not checked.
However, in the method UITable.RepositionVariableSize,
NGUIMath.CalculateRelativeWidgetBounds is not called with considerInactive.
Hence, for inactive children, calculated bounds will always be zero and not repositioned correctly.

I suggest change the line
  1. Bounds b = NGUIMath.CalculateRelativeWidgetBounds(t);
  2.  
to
  1. Bounds b = NGUIMath.CalculateRelativeWidgetBounds(t, !hideInactive);
  2.  

Alvin

4
NGUI 3 Support / UIPanel will not be rendered in certain situation
« on: February 11, 2014, 01:39:20 AM »
Hi,

I've attach a Testbed project.
It shows a case that UIPanel will not be rendered even if its alpha is set to 1.0.

This issue can be reproduced by the following procedure.
  • Uncompressed the testbed.zip. There will be a unity project.
  • Open the project. Import NGUI 3.4.9.
  • Open the scene testcase01.unity under the folder TestCase01. Note that be sure to import NGUI before open the scene.
  • Hit play button.

Due to the script TestCase01.cs attached to UI Root,
the label should hide after playing, and it will show after 0.5 sec.
However, after 0.5 sec, even though the GameObject "Panel" is active and its UIPanel.alpha is set to 1.0,
the UIPanel is still not be rendered.

I also attach a video clip to demonstrate.

The following is the script TestCase01.cs.
  1. public class TestCase01 : MonoBehaviour {
  2.        
  3.         [SerializeField]
  4.         GameObject _parent; // parent GameObject of target's GameObject
  5.         [SerializeField]
  6.         UIRect _target;
  7.        
  8.         void Start(){
  9.                 StartCoroutine(_Process());
  10.         }
  11.        
  12.         IEnumerator _Process(){
  13.  
  14.                 yield return null;
  15.  
  16.                 _target.alpha = 0.0f;
  17.  
  18.                 yield return null;
  19.  
  20.                 _parent.SetActive(false);
  21.  
  22.                 yield return new WaitForSeconds(0.5f);
  23.  
  24.                 _parent.SetActive(true);
  25.                 _target.alpha = 1.0f;
  26.  
  27.                 yield break;
  28.         }
  29. }
  30.  

Alvin



5
NGUI 3 Support / Re: Font scramble on save bug?
« on: February 05, 2014, 11:44:30 PM »
Hi,

I have found a procedure to reproduce this bug.

  • First create a prefab which contains a UILabel with some text.
    The UILabel uses a bitmap font which atlas also contains other sprites.
  • Create a GameObject under UIPanel, and attach the following component "Testbed" to it.
  • Make _prefab field reference to the prefab you just created. (The one contains UILabel)
  • Save the scene. Close and restart Unity. By default, Unity will load the scene opened before exit Unity.
  • Hit play button.

  1. public class Testbed : MonoBehaviour {
  2.  
  3.         [SerializeField]
  4.         GameObject _prefab;
  5.  
  6.         void Awake(){
  7.                 GameObject go = (GameObject)GameObject.Instantiate(_prefab);
  8.  
  9.                 go.transform.parent = this.transform;
  10.                 go.transform.localPosition = Vector3.zero;
  11.                 go.transform.localScale = Vector3.one;
  12.         }
  13. }
  14.  

Testbed will instantiate the prefab with UILabel, so you will see the text of UILabel.
However, the display text will be garbled.
This is because of miscalculation of mUVRect of UIFont.

By design, mUVRect is computed in the first call of get method of UIFont.uvRect property.
  1.         public Rect uvRect
  2.         {
  3.                 get
  4.                 {
  5.                         if (mReplacement != null) return mReplacement.uvRect;
  6.  
  7.                         if (mAtlas != null && (mSprite == null && sprite != null))
  8.                         {
  9.                                 //compute mUVRect
  10.                         }
  11.                         return mUVRect;
  12.                 }
  13.  

However, if mSprite is assigned and not equal to null due to some reason,
the codition
  1. mAtlas != null && (mSprite == null && sprite != null)
  2.  
will always be false, and mUVRect will be never computed.
I have used debugger to monitor UIFont.mSprite and found that
mSprite will automatically assigned to an empty UISpriteData created by the default constructor when entering play mode.

But I cannot find where UIFont.mSprite is assigned, so I guess UIFont.mSprite is assigned an empty object created by Unity debug serialization in very first stage of launching Play Mode.
To fix the problem, change the condition
  1. mAtlas != null && (mSprite == null && sprite != null)
  2.  
in UISprite.uvRect.get to
  1. mAtlas != null && ( !mSpriteSet && sprite != null)
  2.  
.



Alvin






Pages: [1]