Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Jinfaa on January 10, 2013, 11:08:25 PM

Title: Replacement button selected from the list
Post by: Jinfaa on January 10, 2013, 11:08:25 PM
Hello! Please tell me how you can do the following ...
It is necessary that when you press "1" and then click on the character's were replaced by the "1" character?

While there is a suggestion to add the script UIButtonMessage to each of the four buttons. And when you remember the position, then click on a character and is already replacing a button. But I think the code will gramozdkim. Please help, thank you!

  1.         #region выбранный слот для замены
  2.         void one(){
  3.                
  4.         }
  5.        
  6.         void two(){
  7.                
  8.         }
  9.        
  10.         void three(){
  11.                
  12.         }
  13.        
  14.         void four(){
  15.                
  16.         }
  17.         #endregion
  18.        
  19.         #region кнопки в бараках (ТАБЫ)
  20.         void BuildsClick()
  21.         {
  22.                 SelectBarrack(selectedTab=1);
  23.         }
  24.        
  25.         void UnitsClick()
  26.         {
  27.                 SelectBarrack(selectedTab=0);
  28.         }
  29.        
  30.         void SpecClick()
  31.         {
  32.                 SelectBarrack(selectedTab=2);
  33.         }
  34.        
  35.         void SelectBarrack(int tab)
  36.         {
  37.                 ClearPanel();
  38.  
  39.                 int depth = NGUITools.CalculateNextDepth(_parent);
  40.                 int x = 0;
  41.                 foreach(var i in allSkills.getListSlots(tab))
  42.                 {
  43.                         var go = NGUITools.AddChild(original);
  44.                         go.name=i+"_"+tab;
  45.                         var UIbut = go.AddComponent<UIButton>();
  46.                         UIbut.enabled=true;
  47.                         var g = go.AddComponent<UIButtonMessage>();
  48.                         g.target=gameObject;
  49.                         //g.functionName="Builds";
  50.                        
  51.                 UISlicedSprite unit = NGUITools.AddWidget<UISlicedSprite>(go);
  52.                 unit.name = "Icon";
  53.                 unit.depth = depth;
  54.                         unit.pivot = UIWidget.Pivot.Right;
  55.                     unit.atlas = _atlasIcons;
  56.                     unit.spriteName = i;
  57.                                                
  58.                         // меняем позицию кнопки
  59.                 unit.transform.localScale = localsca;
  60.                 unit.MakePixelPerfect();
  61.                        
  62.                         //выводим ценник
  63.                         UILabel prc = NGUITools.AddWidget<UILabel>(go);
  64.             prc.text = allSkills.getSlotWithPrice(i,tab).ToString();
  65.                         prc.font=_font;
  66.             prc.MakePixelPerfect();
  67.                         prc.transform.localPosition = new Vector3(-45f + 3f*x,-50,0);
  68.  
  69.                         go.transform.localPosition=new Vector3(-77f + (80f+3f)*x, 0, -1f);
  70.                        
  71.                         //назначаем таг для удаления дальнейшего
  72.                         go.tag=tag;
  73.                         NGUITools.AddWidgetCollider(go);
  74.                         go.AddComponent<UIDragPanelContents>();// добавляем возможность передвигать
  75.                         x++;
  76.                 }
  77.         }
  78.         #endregion
Title: Re: Replacement button selected from the list
Post by: ArenMook on January 11, 2013, 01:34:20 PM
Attach a script to "1" that will set the current tab selection (static public CustomClass current;) or something to that extent.

Attach a different script to your icons that will use this static value to do something. For example: CustomClass.current.GetComponent<UISprite>().spriteName = "YourNewSprite".