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

Pages: [1]
NGUI 3 Support / Assigning string to GUIStyle
« on: August 20, 2014, 10:32:46 AM »
Hey guys

I was reading through some NGUI code when I hit a bunch of lines that look like:

  1. if (mBlueDot == null) mBlueDot = "sv_label_1";

Where mBlueDot is a GUIStyle.

This is absolutely fascinating to me on a bunch of levels, because I didn't know you could assign strings to GUIStyles, and I don't know what the operation here is actually intending to do.

Can someone please explain this to me?


NGUI 3 Support / UIScrollView - Disable bounds caching
« on: June 27, 2014, 03:34:42 AM »
Hey guys

We have a scenario where we have a UILabel with a UIInput as an immediate child to a UIScrollView panel.

In editor, changing the text value of the label causes the UIScrollView bounds (the orange box) to be recalculated, which is ideal. However, while running the scene, the bounds do not seem to update.

I'm not sure why this behaviour would be different while playing, but it seems to me that the reason the bounds aren't being recalculated is because of the following property in UIScrollView:

  1.         /// <summary>
  2.         /// Calculate the bounds used by the widgets.
  3.         /// </summary>
  5.         public virtual Bounds bounds
  6.         {
  7.                 get
  8.                 {
  9.                         if (!mCalculatedBounds)
  10.                         {
  11.                                 mCalculatedBounds = true;
  12.                                 mTrans = transform;
  13.                                 mBounds = NGUIMath.CalculateRelativeWidgetBounds(mTrans, mTrans);
  14.                         }
  15.                         return mBounds;
  16.                 }
  17.         }

I can't imagine it being particularly expensive to calculate the bounds for a few rects. Perhaps we could have the option to disable caching bounds in the inspector?

For now I believe I can work around this by calling InvalidateBounds() as needed.


NGUI 3 Support / Flickering when setting anchors at runtime
« on: June 18, 2014, 11:50:51 AM »
Hey guys

This is probably an easy one. At runtime we instantiate UIRect prefabs and set anchors, transform, depth and size. It looks like there is an initial frame where the rect occupies the full screen, producing a "flicker" effect.

I assume that the parent orients the rect correctly on the following Update call. I'm wondering if there's a way to schedule an immediate re-orientation?


NGUI 3 Support / Mac UIInput issues
« on: June 16, 2014, 06:01:24 AM »
Hey guys

I'm having trouble getting text input on Mac devices. The problems range from being unable to type into UIInputs to being unable to delete/backspace inputs.

I've done some googling and I've hit a number of threads from the past couple years:

2010 (potentially related?)



The general consensus seems to be that it's a problem with Unity, and that a mythical fix will eventually arrive. Unfortunately, given the age of the problem, I don't have much faith in this being patched any time soon.

Was anyone ever able to find a fix or workaround for these problems?


NGUI 3 Support / SpriteSelector not selecting sprites
« on: June 10, 2014, 04:21:31 AM »
Hi all

I'm trying to bash together a SpriteData PropertyAttribute with a custom property drawer:

It's not a perfect copy of the atlas and sprite fields that NGUI draws in the inspector, but it's at a stage where it's working pretty well.

The only problem I have is that I can't select sprites. I'm using the following code to build the "Sprite" button:

  1.         if (GUI.Button(new Rect(position.x, position.y,
  2.                                 PREFIX_BUTTON_WIDTH, position.height), "Sprite"))
  3.         {
  4.                 NGUISettings.atlas = atlas.objectReferenceValue as UIAtlas;
  5.                 NGUISettings.selectedSprite = sp.stringValue;
  6.                 SpriteSelector.Show((string spriteName) => SelectSprite(serializedObject,
  7.                                                                                         prop.FindPropertyRelative("m_SpriteName"),
  8.                                                                                        sp.stringValue));
  9.         }
  11.         /// <summary>
  12.         ///     Sprite selection callback function.
  13.         /// </summary>
  14.         private void SelectSprite(SerializedObject serializedObject, SerializedProperty serializedProperty,
  15.                                   string spriteName)
  16.         {
  17.                 Debug.Log(spriteName);
  19.                 serializedObject.Update();
  20.                 serializedProperty.stringValue = spriteName;
  21.                 serializedObject.ApplyModifiedProperties();
  22.                 NGUISettings.selectedSprite = spriteName;
  23.         }

When I press the "Sprite" button I get the SpriteSelector window, but when I click on sprites I get a debugged sprite name of "":

Furthermore, I can see that the typical green rect is not drawn on the sprites in the editor window, indicating to me that I don't seem to be making any meaningful selection.

Opening sprite selector from UISprite:

Opening sprite selector from custom property drawer:

I'm attaching the property and the drawer in case anyone wants to take a look. It's pretty short but the drawer gets messy.

If anyone has any ideas on how I can get the SpriteSelector to work, I'd love to hear them.


NGUI 3 Support / Disable UIInput
« on: June 04, 2014, 05:28:58 AM »
Hey guys

I'm looking into disabling the UIInput component. I've come accross this thread:

Disabling the collider sounds like it would work for mouse events, but what happens with keyboard events, such as tabbing?

What is the most comprehensive way of preventing user interaction while keeping the widget visible?


NGUI 3 Support / UIPanel and Uniform Anchor
« on: March 11, 2014, 02:04:35 PM »
Hey guys

I'm having trouble finding information on this.

I want to be able to set a UIPanel to Unified anchor mode and have it follow a GameObject. Is this possible?

From reading the source it looks like I need to set a clipping mode, but none of the clipping modes seem to do exactly what I need.


NGUI 3 Support / Unreliable anchoring
« on: March 11, 2014, 07:50:40 AM »
Hi all

I'm extremely close to getting my anchoring working correctly, but this one last thing is causing me to lose sleep.

I have a perspective camera, I have an orthographic camera in my menu hierarchy, and I have some GameObjects that are rotating around a (invisible) sphere:

I'm instantiating some UITextures via NGUITools.AddChild(uiRoot, prefab) and using SetAnchor to make them follow my GameObjects.

This is what it should look like:

(Perspective camera, gizmos)

(Both cameras)

However, when I first start my scene I get this (Yellow lines show where the anchor is with respect to the UIRect):

(perspective camera)

(both cameras)

Now, my UITextures are hooked up, via click event, to a mechanism that essentially calls SetAnchor a bunch of times. By clicking all UITextures in turn I can "fix" the anchoring:

Alternatively, moving the GameObjects does not fix the anchoring:

Can anyone offer any suggestions as to how I can fix my anchoring?

From reading the NGUI source, if I was to hazard a guess, I would say the issue would be to do with the way UIRect looks up the camera for each side.

Hey guys

I'm probably reinventing the wheel here, but I'm trying to write a component for tracking a given UIRect in screen space to a GameObject in world space.

I'm basically trying to abstract the process of setting a UIRect to Unified anchor mode and assigning a camera. Unfortunately my panels still don't seem to move away from the center of the screen.

Apologies for the code dump, I promise it isn't complicated!

The component:

  1.         [ExecuteInEditMode]
  2.         /// <summary>
  3.         /// Anchor class which anchors a NGUI object to a GameObject
  4.         /// </summary>
  5.         public class AnchorNguiToGameObject : AthgoMonoBehaviour
  6.         {
  7.                 #region Properties
  9.                 private UIRect m_Target;
  10.                 /// <summary>
  11.                 /// Gets or sets the UIRect we are anchoring.
  12.                 /// </summary>
  13.                 /// <value>The target.</value>
  14.                 public UIRect target
  15.                 {
  16.                         get
  17.                         {
  18.                                 return this.m_Target;
  19.                         }
  20.                         set
  21.                         {
  22.                                 this.SetTarget(value);
  23.                         }
  24.                 }
  26.                 /// <summary>
  27.                 /// Gets or sets the target camera.
  28.                 /// </summary>
  29.                 /// <value>The target camera.</value>
  30.                 public Camera targetCamera
  31.                 {
  32.                         get
  33.                         {
  34.                                 return this.GetTargetCamera();
  35.                         }
  36.                         set
  37.                         {
  38.                                 this.SetTargetCamera(value);
  39.                         }
  40.                 }
  42.                 #endregion
  44.                 #region Methods
  46.                 /// <summary>
  47.                 /// Sets the target that is being anchored to the GameObject.
  48.                 /// </summary>
  49.                 /// <param name="target">Target.</param>
  50.                 public void SetTarget(UIRect target)
  51.                 {
  52.                         if (target == this.m_Target)
  53.                                 return;
  55.                         this.m_Target = target;
  57.                         if (this.m_Target is UIPanel)
  58.                                 (this.m_Target as UIPanel).clipping = UIDrawCall.Clipping.ConstrainButDontClip;
  60.                         foreach (UIRect.AnchorPoint anchor in this.GetAnchorPoints())
  61.                        = this.transform;
  62.                 }
  64.                 /// <summary>
  65.                 /// Returns the camera that is used to track the UIRect.
  66.                 /// </summary>
  67.                 /// <returns>The target camera.</returns>
  68.                 public Camera GetTargetCamera()
  69.                 {
  70.                         foreach (UIRect.AnchorPoint anchor in this.GetAnchorPoints())
  71.                                 return anchor.targetCam;
  73.                         return null;
  74.                 }
  76.                 /// <summary>
  77.                 /// Sets the camera that is used to track the UIRect.
  78.                 /// </summary>
  79.                 /// <param name="camera">Camera.</param>
  80.                 public void SetTargetCamera(Camera camera)
  81.                 {
  82.                         if (this.m_Target == null)
  83.                                 throw new Exception("Can't set target Camera. No target!");
  85.                         foreach (UIRect.AnchorPoint anchor in this.GetAnchorPoints())
  86.                                 anchor.targetCam = camera;
  87.                 }
  89.                 /// <summary>
  90.                 /// Returns the list of anchor points for the current target.
  91.                 /// </summary>
  92.                 /// <returns>The anchor points.</returns>
  93.                 public List<UIRect.AnchorPoint> GetAnchorPoints()
  94.                 {
  95.                         List<UIRect.AnchorPoint> anchorPoints = new List<UIRect.AnchorPoint>();
  97.                         if (this.m_Target != null)
  98.                         {
  99.                                 anchorPoints.Add(this.m_Target.bottomAnchor);
  100.                                 anchorPoints.Add(this.m_Target.topAnchor);
  101.                                 anchorPoints.Add(this.m_Target.leftAnchor);
  102.                                 anchorPoints.Add(this.m_Target.rightAnchor);
  103.                         }
  105.                         return anchorPoints;
  106.                 }
  108.                 #endregion
  109.         }

The result:

It's a coincidence that the first anchor is above the sphere:

But the second and third anchors are to the right and below the sphere:

My first question:
Am I missing anything important from my component to get a given UIRect to reliably anchor to the GameObject?

Second question:
I suspect the reason the UIRects are stuck in the center of the screen is because they are parented to the center anchor. If this is the case, what should they be parented to? It doesn't make sense to parent them to my tracking component since I don't want them moving in world space.

As always, please let me know if my hierarchy is garbage. I think the hierarchy stuff is the hardest part for me to grasp with NGUI.


Hi all

I'm trying to figure out the correct approach to changing the scale of a UIRect at runtime.

In my experience, changing the scale of the GameObject does work, but I tend to see the scale changing again on the next frame.

Can anyone advise the correct way to scale a UIRect programatically?


NGUI 3 Support / Couldn't bind to method 'OnSelectionChange'
« on: December 04, 2013, 06:58:59 PM »
NGUI 3.0.4
Unity Pro 4.2.1f


We are trying to connect via delegate to the OnSelectionChange event in the UIPopupList.

We get the following exception:

  1. ArgumentException: Couldn't bind to method 'OnSelectionChange'.
  2. System.Delegate.GetCandidateMethod (System.Type type, System.Type target, System.String method, BindingFlags bflags, Boolean ignoreCase, Boolean throwOnBindFailure) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:351)
  3. System.Delegate.CreateDelegate (System.Type type, System.Object target, System.String method, Boolean ignoreCase, Boolean throwOnBindFailure) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:397)
  4. System.Delegate.CreateDelegate (System.Type type, System.Object target, System.String method, Boolean ignoreCase) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:406)
  5. System.Delegate.CreateDelegate (System.Type type, System.Object target, System.String method) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:300)
  6. EventDelegate.Get () (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:143)
  7. EventDelegate.Execute () (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:205)
  8. EventDelegate.Execute (System.Collections.Generic.List`1 list) (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:267)
  9. UIPopupList.set_value (System.String value) (at Assets/NGUI/Scripts/Interaction/UIPopupList.cs:204)

I have stripped the project down to the scene/scripts that result in the error:

edit: removed NGUI from the project

Please let me know if there is anything we can do to resolve or work around this issue.


NGUI 3 Support / UIButtonColor - Immediately setting the default colour
« on: November 22, 2013, 05:08:36 PM »
NGUI version 3.0.4

Hi all

I am using a delegate method to control the colour of buttons when an event occurs:

  1. // Called when the cue is selected
  2. private void __selectedChanges(bool selected)
  3. {
  4.         UIButton button = this.gameObject.GetComponent<UIButton>();
  6.         if(selected)
  7.         {
  8.                 button.defaultColor = new Color32(0,124,249,255);
  9.                 button.hover = new Color32(0,124,249,255);
  10.         }
  11.         else
  12.         {
  13.                 button.defaultColor = new Color32(124,124,124,255);
  14.                 button.hover = new Color32(255,255,255,255);
  15.         }
  17.         // This is a hack to get the colour to change immediately
  18.         button.OnHover(false);
  19. }

It seems that this does set the correct colour values in the inspector, however the change only occurs when the user hovers their cursor over the button again. You can see I am able to force this change by directly calling the OnHover event method.

My question is: is it possible to immediately set the colour of the button?

By looking at the source of the UIButtonColor it seems no refresh method is called after the colour is set:

  1. public Color defaultColor
  2. {
  3.         ....
  4.         set
  5.         {
  7.                 if (!Application.isPlaying) return;
  8. #endif
  9.                 Start();
  10.                 mColor = value;
  11.         }
  12. }

At first glance it appears the lines "Start();" and "mColor = value;" should perhaps be swapped, though making this change still doesn't allow for immediate colour changing.

Am I using the UIButtonColor class incorrectly?


NGUI 3 Support / NGUI Crashing Unity Editor
« on: November 21, 2013, 04:48:07 PM »
Unity Pro - 4.2.1f4
NGUI - 3.0.4

Both myself and the other programmer on the project are experiencing Unity crashes that are 100% reproducible in our application. These crashes appear to be caused when instantiating multiple NGUI prefabs.

Our instantiation code:

  1. GameObject prefab = ResourceManager.getResource<GameObject>(path, name);
  2. GameObject instance = NGUITools.AddChild(null, prefab);
  3. return instance.AddComponent<T>();

Our NGUI prefabs are relatively simple, consisting of a Panel with a number of child controls (buttons and labels).

Are there any known issues with using NGUI in this fashion? We are developing a large, complex application with many menus and submenus, which means it is impractical to have all of the menus available in the scene at any given time. If we continue down this route of instantiating NGUI objects on demand are we likely to see more resistance?

I'm going to try and strip down the project to a point where I can post it here.


NGUI 3 Support / Does NGUI support multiline text editing?
« on: October 20, 2013, 07:44:13 PM »
Hi all

Apologies if this is the wrong place; I'm currently trying to evaluate if NGUI is a technology my team will start using, and a contingency of this is the support of multiline text editing.

I've been looking at the available examples, reading forum posts and looking at Youtube videos. So far I can see that multiline text is possible by feeding "\n" into a label, but I'm struggling to find information on how good the input functionality is.

Can anyone please tell me if any of the following is supported in the latest version of NGUI?

  • Moving cursor in a body of text, via mouse or arrow keys
  • Highlighting text
  • Copy/paste

I appreciate these may be outside the scope of NGUI. Perhaps there are extensions that implement these?


Pages: [1]