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

Pages: [1]
1
NGUI 3 Support / Re: UIPanel bug in editor
« on: March 14, 2014, 12:49:02 PM »
nGui: 3.04
Unity: 4.3.4f1

2
NGUI 3 Support / UIPanel bug in editor
« on: March 13, 2014, 05:01:55 PM »
Adjusting the values for center and size for UIPanel under AlphaClip do not update what is seen in the scene view.

As a hack I added
UpdateDrawcalls(); to Update() which fixed it just so I could see what the extents of my clip was.

3
NGUI 3 Support / Cancel key not passed to UICamera::mCurrentSelection
« on: December 13, 2013, 06:16:54 PM »
BUG: This line is making it so when I press escape, the currently selected widget does not get KeyCode.ESCAPE

  1. // Clear the selection on the cancel key, but only if mouse input is allowed
  2.                 if (useMouse && mCurrentSelection != null && ((cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0)) ||
  3.                         (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1)))) selectedObject = null;
  4.  

The widget should get KeyCode.ESCAPE so it knows it lost focus. I could use OnSelect, except then I don't know if the user clicked on nothing, navigated to another widget, or pressed escape.

This is a pretty common use-case. In my case, pressing cancel should go back to the prior screen and not just lose focus.

Also, onCustomInput is useless because there are no parameters to the delegate.

4
NGUI 3 Support / Re: UIScale act on sliced sprite dimensions
« on: December 04, 2013, 08:47:35 PM »
Sorry, yes. UIButtonScale. I'll try TweenWidth and TweenHeight

5
NGUI 3 Support / UIScale act on sliced sprite dimensions
« on: December 04, 2013, 05:32:24 PM »
UIScale scales the transform of the object. But with a sliced sprite this results in the edges being scaled. I would instead like the Widget Dimensions to be scaled by the corresponding X / Y scale values, and for the containing game object's scale to remain unchanged. How would I do this? I tried writing a script but I'm not sure which public members to set of UISprite.

6
NGUI 3 Support / UIButtonKeys backtrace selection
« on: November 22, 2013, 02:08:50 PM »
I've added a backtrace selection feature to UIButtonKeys that I think should go in the main branch. It makes it so if you press one direction, then the opposite direction, you end up at the same UIButtonKeys element you started at. Currently this does not happen if you have two or more UIButtonKeys that both go to one UIButtonKeys using the same direction. For example, if you have a menu at the top of the screen "Games, Movies, Apps", and you press down, then up, you would normally expect to go back to movies. But as-is, it would always end back up at the same item (probably games).

It would also help if the classes in NGui were virtual so I could derive from them rather than entirely copy/paste.

  1. //----------------------------------------------
  2. //            NGUI: Next-Gen UI kit
  3. // Copyright © 2011-2013 Tasharen Entertainment
  4. //----------------------------------------------
  5.  
  6. using UnityEngine;
  7. using System.Collections.Generic;
  8.  
  9. /// <summary>
  10. /// Attaching this script to a widget makes it react to key events such as tab, up, down, etc.
  11. /// </summary>
  12.  
  13. [RequireComponent(typeof(Collider))]
  14. [AddComponentMenu("NGUI/Interaction/Button Keys 2")]
  15. public class UIButtonKeys2 : MonoBehaviour
  16. {
  17.         public bool backtraceSelection = true;
  18.         public bool startsSelected = false;
  19.         public UIButtonKeys2 selectOnClick;
  20.         public UIButtonKeys2 selectOnUp;
  21.         public UIButtonKeys2 selectOnDown;
  22.         public UIButtonKeys2 selectOnLeft;
  23.         public UIButtonKeys2 selectOnRight;
  24.  
  25.         void OnEnable ()
  26.         {
  27.                 if (startsSelected)
  28.                 {
  29.                         if (UICamera.selectedObject == null || !NGUITools.GetActive(UICamera.selectedObject))
  30.                         {
  31.                                 UICamera.selectedObject = gameObject;
  32.                                 UICamera.Notify(gameObject, "OnHover", true);
  33.                         }
  34.                 }
  35.         }
  36.          
  37.         void OnKey (KeyCode key)
  38.         {
  39.                 if (enabled && NGUITools.GetActive(gameObject))
  40.                 {
  41.                         switch (key)
  42.                         {
  43.                         case KeyCode.LeftArrow:
  44.                                 if (selectOnLeft != null)
  45.                                 {
  46.                                         UICamera.selectedObject = selectOnLeft.gameObject;
  47.                                         if (backtraceSelection)
  48.                                                 selectOnLeft.selectOnRight = this;                                     
  49.                                 }
  50.                                 break;
  51.                         case KeyCode.RightArrow:
  52.                                 if (selectOnRight != null)
  53.                                 {
  54.                                         UICamera.selectedObject = selectOnRight.gameObject;
  55.                                         if (backtraceSelection)
  56.                                                 selectOnRight.selectOnLeft = this;                                     
  57.                                 }
  58.                                 break;
  59.                         case KeyCode.UpArrow:
  60.                                 if (selectOnUp != null)
  61.                                 {
  62.                                         UICamera.selectedObject = selectOnUp.gameObject;
  63.                                         if (backtraceSelection)
  64.                                                 selectOnUp.selectOnDown = this;
  65.                                 }
  66.                                 break;
  67.                         case KeyCode.DownArrow:
  68.                                 if (selectOnDown != null)
  69.                                 {
  70.                                         UICamera.selectedObject = selectOnDown.gameObject;
  71.                                         if (backtraceSelection)
  72.                                                 selectOnDown.selectOnUp = this;
  73.                                 }
  74.                                 break;
  75.                         case KeyCode.Tab:
  76.                                 if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
  77.                                 {
  78.                                         if (selectOnLeft != null)
  79.                                         {
  80.                                                 UICamera.selectedObject = selectOnLeft.gameObject;
  81.                                                 if (backtraceSelection)
  82.                                                         selectOnLeft.selectOnRight = this;                             
  83.                                         }
  84.                                         else if (selectOnUp != null)
  85.                                         {
  86.                                                 UICamera.selectedObject = selectOnUp.gameObject;
  87.                                                 if (backtraceSelection)
  88.                                                         selectOnUp.selectOnDown = this;
  89.                                         }
  90.                                         else if (selectOnDown != null)
  91.                                         {
  92.                                                 UICamera.selectedObject = selectOnDown.gameObject;
  93.                                                 if (backtraceSelection)
  94.                                                         selectOnDown.selectOnUp = this;
  95.                                         }
  96.                                         else if (selectOnRight != null)
  97.                                         {
  98.                                                 UICamera.selectedObject = selectOnRight.gameObject;
  99.                                                 if (backtraceSelection)
  100.                                                         selectOnRight.selectOnLeft = this;     
  101.                                         }
  102.                                 }
  103.                                 else
  104.                                 {
  105.                                         if (selectOnRight != null)
  106.                                         {
  107.                                                 UICamera.selectedObject = selectOnRight.gameObject;
  108.                                                 if (backtraceSelection)
  109.                                                         selectOnRight.selectOnLeft = this;     
  110.                                         }
  111.                                         else if (selectOnDown != null)
  112.                                         {
  113.                                                 UICamera.selectedObject = selectOnDown.gameObject;
  114.                                                 if (backtraceSelection)
  115.                                                         selectOnDown.selectOnUp = this;
  116.                                         }
  117.                                         else if (selectOnUp != null)
  118.                                         {
  119.                                                 UICamera.selectedObject = selectOnUp.gameObject;
  120.                                                 if (backtraceSelection)
  121.                                                         selectOnUp.selectOnDown = this;
  122.                                         }
  123.                                         else if (selectOnLeft != null)
  124.                                         {
  125.                                                 UICamera.selectedObject = selectOnLeft.gameObject;
  126.                                                 if (backtraceSelection)
  127.                                                         selectOnLeft.selectOnRight = this;
  128.                                         }
  129.                                 }
  130.                                 break;
  131.                         }
  132.                 }
  133.         }
  134.  
  135.         void OnClick ()
  136.         {
  137.                 if (enabled && selectOnClick != null)
  138.                 {
  139.                         UICamera.selectedObject = selectOnClick.gameObject;
  140.                 }
  141.         }
  142. }
  143.  
  144.  

7
NGUI 3 Support / UIInput, Starts Selected, Enter
« on: November 13, 2013, 09:19:27 PM »
If you have UIInput and UIButtonKeys on the same GameObject, and Starts Selected is checked, it does not start selected. I can still select it with up/down/left/right though if I have something else set as Starts Selected first. Is this a bug? Using 3.0.4

Also, I have multiple UIInput entries and would like to select the next one when the user hits enter. Right now it works only if they push down (due to Select On Down). I tried to do it with Select On Click, but that made it so if I clicked the UIInput field to enter text to start with it would immediately select the next one. How do I do this correctly?

Thanks.

8
NGUI 3 Support / UIToggle with two different textures
« on: November 05, 2013, 01:42:50 PM »
I have a checkbox with two different textures - checked, and unchecked. Only one should show at a time. But UIToggle's Sprite field only turns on or off one sprite, rather than alternate between them.

I can do this with code, but I am thinking nGui already has a way to do this. Maybe with Group?

Thanks for any suggestions.

9
I found the problem, it was not nGUI. I was using a string based callback but every instantiated game object had the same name.

10
UIDrawCall does not have a member dynamicMaterial.

11
I tried setting the texture to nothing as specified in this thread
http://www.tasharen.com/forum/index.php?topic=3613.msg17836#msg17836

It did not fix the problem. Doing that only displays the "Color Tint" value.

12
NGUI 3 Support / UITexture only changes texture on first instance of prefab
« on: November 01, 2013, 07:04:34 PM »
I have a prefab with a UITexture. I instantiate it 4 times. On each of the 4 instances I call a script on the prefab to change the texture using the WWW class and a URL.

Each of the 4 instances downloads the texture, then runs the code to change it.

  1. uiTextureComponent.material = new Material(uiTextureComponent.material.shader);
  2. uiTextureComponent.mainTexture = downloadedTexture2D;
  3.  

However, the first texture changes 4 times in quick succession, while the other 3 remain black. Through breakpoints I have confirmed that each of the 4 instances is downloading its own texture. It's like the material or texture is shared among all instances when it should not be.

Thanks for the help.

13
NGUI 3 Support / Localization with fonts improvement
« on: October 14, 2013, 03:53:59 PM »
I saw this post
http://www.tasharen.com/forum/index.php?topic=313.msg1468#msg1468
ArenMook said to use an OnLocalize event to change fonts. However, that is not the best solution since it requires a separate script to implement Localize() with every usage of UILabel. And that script will need to hardcode which font goes with what language. BMFont doesn't have the capability to combine fonts, so every localized game that uses non-English characters is going to run into this problem.

As a suggested alternative, I added a singleton class LocalizationFontMap (attached) where you associate a language resource file with a font prefab.

I then changed UILocalize to use the font specified by LocalizationFontMap in the Localize() function.

Original UILocalize :
  1. if (lbl != null)
  2. {
  3.         // If this is a label used by input, we should localize its default value instead
  4.         UIInput input = NGUITools.FindInParents<UIInput>(lbl.gameObject);
  5.         if (input != null && input.label == lbl) input.defaultText = val;
  6.         else lbl.text = val;
  7. }
  8. else if (sp != null)
  9. {
  10.         sp.spriteName = val;
  11.         sp.MakePixelPerfect();
  12. }
  13.  

Changed UILocalize:
  1. UIFont newFont = null;
  2. if (LocalizationFontMap.instance != null)
  3. {
  4.         newFont = LocalizationFontMap.instance.GetCurrentFont();
  5. }      
  6.  
  7. if (lbl != null)
  8. {
  9.         // If this is a label used by input, we should localize its default value instead
  10.         UIInput input = NGUITools.FindInParents<UIInput>(lbl.gameObject);
  11.         if (input != null && input.label == lbl)
  12.         {
  13.                 input.defaultText = val;
  14.         }
  15.         else
  16.         {
  17.                 if (newFont != null)
  18.                         lbl.font = newFont;
  19.                 lbl.text = val;
  20.         }
  21. }
  22. else if (sp != null)
  23. {
  24.         sp.spriteName = val;
  25.         sp.MakePixelPerfect();
  26. }
  27.  

Let me know if you have suggestions for improvement.

14
NGUI 3 Support / UIButtonTween resetOnPlay fails every other time
« on: October 07, 2013, 02:00:49 PM »
In UIButtonTween, if I set resetOnPlay to true, it will fail every other time it runs, starting the 2nd time

This happens between of this code:

// Toggle or activate the tween component
if (playDirection == Direction.Toggle) tw.Toggle();
else tw.Play(forward);
if (resetOnPlay) tw.Reset();

tw.Play(forward) will call Play(), with mFactor already set to 1.0 due to the prior execution

public void Play (bool forward)
{
   mAmountPerDelta = Mathf.Abs(amountPerDelta);
   if (!forward) mAmountPerDelta = -mAmountPerDelta;
   enabled = true;
   Update();
}

With Style.Once, Update() will then run this code:

// Disable this script unless the function calls above changed something
if (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f)
{
enabled = false;
}

Lastly, Reset() will reset mFactor, but too late.


public void Reset ()
{
   mStarted = false;
   mFactor = (mAmountPerDelta < 0f) ? 1f : 0f;
   Sample(mFactor, false);
}

I believe the correct fix is in UIButtonTween.cs, it should call tw.Reset() first, then tw.Play() second.

Pages: [1]