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

Pages: 1 [2] 3
16
NGUI 3 Support / UICheckboxPlus (UITexture instead of UISprite)
« on: September 09, 2013, 03:53:09 PM »
I modified the code of the UICheckbox to handle a UITexture instead of a UISprite. This came in handy for me, so I figure perhaps there is someone else out there who could benefit from it. So here you are.


  1. //----------------------------------------------
  2. //            NGUI: Next-Gen UI kit
  3. // Copyright © 2011-2013 Tasharen Entertainment
  4. //----------------------------------------------
  5.  
  6. using UnityEngine;
  7. using AnimationOrTween;
  8.  
  9. /// <summary>
  10. /// Simple checkbox functionality. If 'option' is enabled, checking this checkbox will uncheck all other checkboxes with the same parent.
  11. /// </summary>
  12.  
  13. [AddComponentMenu("NGUI/Interaction/Checkbox")]
  14. public class UICheckboxPlus : MonoBehaviour
  15. {
  16.         static public UICheckboxPlus current;
  17.         public delegate void OnStateChange (bool state);
  18.  
  19.         /// <summary>
  20.         /// Sprite that's visible when the 'isChecked' status is 'true'.
  21.         /// </summary>
  22.  
  23.         public UITexture checkSprite;
  24.  
  25.         /// <summary>
  26.         /// Animation to play on the checkmark sprite, if any.
  27.         /// </summary>
  28.  
  29.         public Animation checkAnimation;
  30.  
  31.         /// <summary>
  32.         /// If checked, tween-based transition will be instant instead.
  33.         /// </summary>
  34.  
  35.         public bool instantTween = false;
  36.  
  37.         /// <summary>
  38.         /// Whether the checkbox starts checked.
  39.         /// </summary>
  40.  
  41.         public bool startsChecked = true;
  42.  
  43.         /// <summary>
  44.         /// If the checkbox is part of a radio button group, specify the root object to use that all checkboxes are parented to.
  45.         /// </summary>
  46.  
  47.         public Transform radioButtonRoot;
  48.  
  49.         /// <summary>
  50.         /// Can the radio button option be 'none'?
  51.         /// </summary>
  52.  
  53.         public bool optionCanBeNone = false;
  54.  
  55.         /// <summary>
  56.         /// Generic event receiver that will be notified when the state changes.
  57.         /// </summary>
  58.  
  59.         public GameObject eventReceiver;
  60.  
  61.         /// <summary>
  62.         /// Function that will be called on the event receiver when the state changes.
  63.         /// </summary>
  64.  
  65.         public string functionName = "OnActivate";
  66.  
  67.         /// <summary>
  68.         /// Delegate that will be called when the checkbox's state changes. Faster than using 'eventReceiver'.
  69.         /// </summary>
  70.  
  71.         public OnStateChange onStateChange;
  72.  
  73.         // Prior to 1.90 'option' was used to toggle the radio button group functionality
  74.         [HideInInspector][SerializeField] bool option = false;
  75.  
  76.         bool mChecked = true;
  77.         bool mStarted = false;
  78.         Transform mTrans;
  79.  
  80.         /// <summary>
  81.         /// Whether the checkbox is checked.
  82.         /// </summary>
  83.  
  84.         public bool isChecked
  85.         {
  86.                 get { return mChecked; }
  87.                 set { if (radioButtonRoot == null || value || optionCanBeNone || !mStarted) Set(value); }
  88.         }
  89.  
  90.         /// <summary>
  91.         /// Legacy functionality support -- set the radio button root if the 'option' value was 'true'.
  92.         /// </summary>
  93.  
  94.         void Awake ()
  95.         {
  96.                 mTrans = transform;
  97.  
  98.                 if (checkSprite != null) checkSprite.alpha = startsChecked ? 1f : 0f;
  99.  
  100.                 if (option)
  101.                 {
  102.                         option = false;
  103.                         if (radioButtonRoot == null) radioButtonRoot = mTrans.parent;
  104.                 }
  105.         }
  106.  
  107.         /// <summary>
  108.         /// Activate the initial state.
  109.         /// </summary>
  110.  
  111.         void Start ()
  112.         {
  113.                 if (eventReceiver == null) eventReceiver = gameObject;
  114.                 mChecked = !startsChecked;
  115.                 mStarted = true;
  116.                 Set(startsChecked);
  117.         }
  118.  
  119.         /// <summary>
  120.         /// Check or uncheck on click.
  121.         /// </summary>
  122.  
  123.         void OnClick () { if (enabled) isChecked = !isChecked; }
  124.  
  125.         /// <summary>
  126.         /// Fade out or fade in the checkmark and notify the target of OnChecked event.
  127.         /// </summary>
  128.  
  129.         void Set (bool state)
  130.         {
  131.                 if (!mStarted)
  132.                 {
  133.                         mChecked = state;
  134.                         startsChecked = state;
  135.                         if (checkSprite != null) checkSprite.alpha = state ? 1f : 0f;
  136.                 }
  137.                 else if (mChecked != state)
  138.                 {
  139.                         // Uncheck all other checkboxes
  140.                         if (radioButtonRoot != null && state)
  141.                         {
  142.                                 UICheckboxPlus[] cbs = radioButtonRoot.GetComponentsInChildren<UICheckboxPlus>(true);
  143.  
  144.                                 for (int i = 0, imax = cbs.Length; i < imax; ++i)
  145.                                 {
  146.                                         UICheckboxPlus cb = cbs[i];
  147.                                         if (cb != this && cb.radioButtonRoot == radioButtonRoot) cb.Set(false);
  148.                                 }
  149.                         }
  150.  
  151.                         // Remember the state
  152.                         mChecked = state;
  153.  
  154.                         // Tween the color of the checkmark
  155.                         if (checkSprite != null)
  156.                         {
  157.                                 if (instantTween)
  158.                                 {
  159.                                         checkSprite.alpha = mChecked ? 1f : 0f;
  160.                                 }
  161.                                 else
  162.                                 {
  163.                                         TweenAlpha.Begin(checkSprite.gameObject, 0.15f, mChecked ? 1f : 0f);
  164.                                 }
  165.                         }
  166.  
  167.                         current = this;
  168.  
  169.                         // Notify the delegate
  170.                         if (onStateChange != null) onStateChange(mChecked);
  171.  
  172.                         // Send out the event notification
  173.                         if (eventReceiver != null && !string.IsNullOrEmpty(functionName))
  174.                         {
  175.                                 eventReceiver.SendMessage(functionName, mChecked, SendMessageOptions.DontRequireReceiver);
  176.                         }
  177.                         current = null;
  178.  
  179.                         // Play the checkmark animation
  180.                         if (checkAnimation != null)
  181.                         {
  182.                                 ActiveAnimation.Play(checkAnimation, state ? Direction.Forward : Direction.Reverse);
  183.                         }
  184.                 }
  185.         }
  186. }
  187.  

17
NGUI 3 Support / UICheckbox CheckSprite
« on: September 05, 2013, 12:02:02 PM »
I would like to use a GameObject with a UITexture as the Check Sprite. Right now I'm limited to using a UISprite. Any thoughts on how I can make that happen?

Thanks!

18
NGUI 3 Support / Re: Orphaned GUI Elements solution?
« on: August 29, 2013, 04:16:45 PM »
Perhaps this error could be a part of it. The issue came right back even after unnesting objects.


  1. ArgumentException: GUILayout: Mismatched LayoutGroup.Repaint
  2. UnityEngine.GUILayoutUtility.BeginLayoutGroup (UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options, System.Type LayoutType)
  3. UnityEngine.GUILayout.BeginHorizontal (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options)
  4. UnityEngine.GUILayout.BeginHorizontal (UnityEngine.GUILayoutOption[] options)
  5. UnityEditor.EditorGUILayout.ObjectField (System.String label, UnityEngine.Object obj, System.Type objType, Boolean allowSceneObjects, UnityEngine.GUILayoutOption[] options)
  6. UITextureInspector.DrawProperties () (at Assets/NGUI/Scripts/Editor/UITextureInspector.cs:48)
  7. UIWidgetInspector.OnInspectorGUI () (at Assets/NGUI/Scripts/Editor/UIWidgetInspector.cs:766)
  8. UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty)
  9. UnityEditor.DockArea:OnGUI()

19
NGUI 3 Support / Orphaned GUI Elements solution?
« on: August 29, 2013, 01:55:42 PM »
I brought this up last week and nothing was resolved. It was thought that NGUI was updated improperly but after confirming it was indeed updated correctly, the issue still stood.

I'm coming back now with some findings:

It seems that if UI elements are deeply nested, there is something about it that breaks and causes them to become orphaned and require either restarting Unity or Force Deleting the objects. The bug only begins after entering Play mode, you'll see the UI elements 'stuck' and don't go away even after disabling them, and even after exiting Play mode.

Our only solution now is to just not nest UI elements so deeply.

20
NGUI 3 Support / Re: NGUI stray UI elements
« on: August 23, 2013, 03:15:25 PM »
The panels GameObject.

21
NGUI 3 Support / Re: NGUI stray UI elements
« on: August 23, 2013, 02:30:01 PM »
I disable the panel that has the check boxes and re enable a different panel, for switching windows. But my point is, its the act of disabling the panel that causes the problem. Should I not be disabling the panel?

22
NGUI 3 Support / Re: NGUI stray UI elements
« on: August 23, 2013, 02:11:20 PM »
Latest version of Unity 4.2, Pulling latest NGUI from bit repository. Haven't changed NGUI code. The objects are 6 radio connected check boxes, so upon pressing play all but one disable.

23
NGUI 3 Support / Re: NGUI stray UI elements
« on: August 23, 2013, 11:14:04 AM »
I appreciate the quick feedback.

NGUI was properly imported, even still I just reimported it following the exact instructions.

When this glitch occurs, restarting Unity does resolve the issue, but only until I press Play again and the issue comes right back.

24
NGUI 3 Support / NGUI stray UI elements
« on: August 23, 2013, 09:39:06 AM »
My team is having this strange issue where a panel is displayed, but when it is turned off, some of the UI elements that don't actually exist in the hierarchy stay in the scene. We found that they could be Force Deleted from the Game Object menu, but that doesn't help during runtime.

I've attached an image of the issue.

Any ideas on how to prevent this from happening?

Thanks,

-Jacob S.


25
Other Packages / Re: StarLink GameWebRequest
« on: August 22, 2013, 12:57:13 PM »
Could you give me an example on how to retrieve the item that was downloaded?

The method is void, so I'm not sure on how I would assign the downloaded object (texture in my case) to a Texture2D variable.

26
Other Packages / StarLink GameWebRequest
« on: August 22, 2013, 11:00:07 AM »
Could someone give me a good example of how to use the GameWebRequest script. I've tried quite a few different ways to get it working.

I'm trying to use it to download a .png and assign it to a Texture2D variable.

Thanks

-Jacob S

27
NGUI 3 Support / Variable Names
« on: August 21, 2013, 10:06:05 AM »
I'm just wondering why variable names are named as such:
I see this a lot in NGUI source, the variable starts with 'm'.

  1. static string mName;
  2. static int mFull = -1;
  3. static int mHints = -1;
  4. static int mWifi = -1;
  5. static int mExp = -1;
  6. static int mPowerSaving = -1;

28
NGUI 3 Support / NGUI Git
« on: August 15, 2013, 06:12:31 PM »
No submodule mapping found in .gitmodules for path 'Assets/NGUI'

I have NGUI in my server repository, and when I try cloning it onto a new machine, I get this error^.

Any ideas as to why? I've tried removing NGUI from the Assets folder, and putting it back in, and git shows that it was put into the server repository, but still this error happens.

-Jacob S.

29
NGUI 3 Support / NGUI Table expand from center
« on: August 15, 2013, 11:51:56 AM »
Aren I realize the functionality of having tables expand from the center is available in the forums linked. My question is, will you be integrating this into a future update of NGUI?

http://www.tasharen.com/forum/index.php?topic=2648.0
http://www.tasharen.com/forum/index.php?topic=2214.msg11058#msg11058

Thanks,

Jacob S.

30
NGUI 3 Support / NGUI Grid to start in selected position?
« on: August 01, 2013, 10:57:31 AM »
I have N amount of items dynamically loading into my horizontally scrolling grid when the scene is loaded. I also have the CenterObject script on my grid. I'm having a hard time getting a specific item to be the focused object in the center because the grid always repositions the items with the left side being the start point. Does this make sense? Any ideas?

Thanks,

-Jacob

Pages: 1 [2] 3