コード例 #1
0
 public void OnItemClick(JMRUIPrimaryRadioButton currentRadioButton)
 {
     if (prevRadioButton != currentRadioButton)
     {
         if (prevRadioButton != null)
         {
             prevRadioButton.IsOn = false;
         }
         currentRadioButton.IsOn = true;
     }
     else
     {
         if (allowSwitchOff)
         {
             currentRadioButton.IsOn = !currentRadioButton.IsOn;
         }
     }
     prevRadioButton = currentRadioButton;
 }
コード例 #2
0
        protected override void OnEnable()
        {
            base.OnEnable();
            radioButtons.Clear();
            JMRUIPrimaryRadioButton tempRadioButton = null;
            bool anyRadioButtonOn = false;
            int  i = 0;

            foreach (RectTransform item in content)
            {
                JMRUIPrimaryRadioButton radioButton = item.GetComponent <JMRUIPrimaryRadioButton>();
                if (radioButton)
                {
                    if (i == 0)
                    {
                        tempRadioButton = radioButton;
                    }
                    if (radioButton.IsOn && !anyRadioButtonOn)
                    {
                        anyRadioButtonOn = true;
                        tempRadioButton  = radioButton;
                    }
                    else if (anyRadioButtonOn)
                    {
                        radioButton.IsOn = false;
                    }
                    radioButton.parentClickHandler = OnItemClick;
                    radioButtons.Add(radioButton);
                    i++;
                }
            }

            if (tempRadioButton != null)
            {
                if (!anyRadioButtonOn && !allowSwitchOff)
                {
                    tempRadioButton.IsOn = true;
                }
                prevRadioButton = tempRadioButton;
            }
        }