Author Topic: UIButton,UIToggle and actions small improvements proposal  (Read 2860 times)

Neogene

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
UIButton,UIToggle and actions small improvements proposal
« on: October 27, 2014, 03:36:02 AM »
hi all, i started using NGUI 3.7.4  and it's really nice, after a couple of hours i manage to develop hundreds of operations without coding a single line :) I faced some "issues" which i believe may be improved to reduce developing time:

UIButton: i didn't find a way to disable the automatic color tween of the component, because even if i set to "none" the target the code reassign it to the gameobject if it's "none" , this creates some issues with a parent tweening alpha (1->0) in my case (randomly the automatic color tween of the button seems to get problems with it making its alpha again back to 1). The only solution i found was to comment out the tweenTarget assigment into UIButtonColor class.  Dunno why the OnInit forces to set the tweenTarget but commenting out the following line removed this issue in my case:

//UIButtonColor.cs
   
  1. protected virtual void OnInit ()
  2.         {
  3.                 mInitDone = true;
  4.                 //if (tweenTarget == null) tweenTarget = gameObject;
  5.                 mWidget = tweenTarget.GetComponent<UIWidget>();

UIToggle should be a component with two Handlers, one for true status and the other for the false state, in this way the procedure to have two behaviorus depending on its values wont require to develop a class which will have to check the UIToggle status and act depending on the choosen value. This addition will reduce developing time allowing to quickly select the required action from the target/s eg: alpha tween a widget accordingly to the toggle status.

Actions Behaviors: When selecting the Method from the selected target in an UIButton (or other) components, there is no way to handle the whole GameObject active state/ to destroy it/ reparenting after an action. Some times i use this behaviours to reduce memory/calls footprint, the solution i found for the "active" and "destroy" operations were to add the following Methods to the UIWidget class (i know it's not the best way in terms of semantic correctness: there should be a GameObject voice in the list instead of three voices in the UIWidget actions list but was the quickest way i found to add to all the widgets) :

  1.  
  2.         /// <summary>
  3.         /// Deactive gameobject.
  4.         /// </summary>
  5.        
  6.         public void DeactiveObject ()
  7.         {
  8.                 this.gameObject.SetActive (false);
  9.         }
  10.  
  11.         /// <summary>
  12.         /// Destroy gameobject.
  13.         /// </summary>
  14.        
  15.         public void DestroyGameObejct ()
  16.         {
  17.                 Destroy (this.gameObject);
  18.         }
  19.  
  20.         /// <summary>
  21.         /// Destroy gameobject including parent.
  22.         /// </summary>
  23.        
  24.         public void DestroyGameObejctAndParent ()
  25.         {
  26.                 Destroy (this.gameObject.transform.parent.gameObject);
  27.         }


Actions Behaviors 2: if i have two Tweens of the same class (like the alpha) added to an object the dropmenu to select the proper one from the selected target of a uibutton onclick handler the interface will show only one  of them and there is no way to know which one is going to use because the gui doesn't show any tip about it (like the params used, or a name).

The quickest solution i found was to create a script which is called by the onclick and uses two public (to allow drag and drop selection form the GUI) UITween variables to hold the two tweens and start them them depending on the event.  Note: the alpha tween in my case weren't specular (1->0 and 0-1) 'cause in that case i use playforward/backward but eg: one 0->x and the other one x->y... Another way was to change the values of from and to of a single alpha tween and start it but in this way it will loose the starting values which requires to store the original values inside a couple of vars.

Due to the fact i used this package only from the last saturday i dunno if i'm missing some NGUI behaviours/flows son if i'm wrong about them sorry, i hope to get some tips about them from more experienced developers!

Best regars.