A class which encapsulates all that is required to track and manage radio buttons as a group.
Example #1
0
    /// <summary>
    /// Returns a reference to the selected radio button for
    /// the specified group.
    /// </summary>
    /// <param name="id">The ID of the group (either an arbitrary integer ID, or the hashcode of a radio button's parent transform, depending on the settings).</param>
    /// <returns>A reference to the currently selected (true) radio button.  Null if none is set to true.</returns>
    public static IRadioButton GetSelected(int id)
    {
        RadioBtnGroup group = null;

        for (int i = 0; i < groups.Count; ++i)
        {
            if (groups[i].groupID == id)
            {
                group = groups[i];
                break;
            }
        }

        if (group == null)
        {
            return(null);
        }

        for (int i = 0; i < group.buttons.Count; ++i)
        {
            if (((IRadioButton)group.buttons[i]).Value)
            {
                return((IRadioButton)group.buttons[i]);
            }
        }

        return(null);
    }
Example #2
0
    public override void Copy(SpriteRoot s, ControlCopyFlags flags)
    {
        base.Copy(s, flags);
        if (!(s is UIRadioBtn))
        {
            return;
        }
        UIRadioBtn uIRadioBtn = (UIRadioBtn)s;

        if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State)
        {
            this.state          = uIRadioBtn.state;
            this.prevTransition = uIRadioBtn.prevTransition;
            if (Application.isPlaying)
            {
                this.Value = uIRadioBtn.Value;
            }
        }
        if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings)
        {
            this.group        = uIRadioBtn.group;
            this.defaultValue = uIRadioBtn.defaultValue;
        }
        if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation)
        {
            this.scriptWithMethodToInvoke = uIRadioBtn.scriptWithMethodToInvoke;
            this.methodToInvoke           = uIRadioBtn.methodToInvoke;
            this.whenToInvoke             = uIRadioBtn.whenToInvoke;
            this.delay = uIRadioBtn.delay;
        }
        if ((flags & ControlCopyFlags.Sound) == ControlCopyFlags.Sound)
        {
            this.soundToPlay = uIRadioBtn.soundToPlay;
        }
    }
    public static IRadioButton GetSelected(int id)
    {
        RadioBtnGroup radioBtnGroup = null;

        for (int i = 0; i < RadioBtnGroup.groups.Count; i++)
        {
            if (RadioBtnGroup.groups[i].groupID == id)
            {
                radioBtnGroup = RadioBtnGroup.groups[i];
                break;
            }
        }
        if (radioBtnGroup == null)
        {
            return(null);
        }
        for (int j = 0; j < radioBtnGroup.buttons.Count; j++)
        {
            if (((IRadioButton)radioBtnGroup.buttons[j]).Value)
            {
                return(radioBtnGroup.buttons[j]);
            }
        }
        return(null);
    }
Example #4
0
 public override void OnDestroy()
 {
     base.OnDestroy();
     if (this.group == null)
     {
         return;
     }
     this.group.buttons.Remove(this);
     this.group = null;
 }
Example #5
0
    //---------------------------------------------------
    // Misc
    //---------------------------------------------------

    /*
     *      protected override void OnEnable()
     *      {
     *              base.OnEnable();
     *
     #if RADIOBTN_USE_PARENT
     *              SetGroup(transform.parent);
     #else
     *              SetGroup(radioGroup);
     #endif
     *      }
     */


    public override void OnDestroy()
    {
        base.OnDestroy();

        if (group == null)
        {
            return;
        }

        // Remove self from the group
        group.buttons.Remove(this);
        group = null;
    }
Example #6
0
 public void SetGroup(int groupID)
 {
     if (this.group != null)
     {
         this.group.buttons.Remove(this);
         this.group = null;
     }
     this.radioGroup = groupID;
     this.group      = RadioBtnGroup.GetGroup(groupID);
     this.group.buttons.Add(this);
     if (this.btnValue)
     {
         this.PopOtherButtonsInGroup();
     }
 }
    public static RadioBtnGroup GetGroup(int id)
    {
        RadioBtnGroup radioBtnGroup = null;

        for (int i = 0; i < RadioBtnGroup.groups.Count; i++)
        {
            if (RadioBtnGroup.groups[i].groupID == id)
            {
                radioBtnGroup = RadioBtnGroup.groups[i];
                break;
            }
        }
        if (radioBtnGroup == null)
        {
            radioBtnGroup = new RadioBtnGroup(id);
        }
        return(radioBtnGroup);
    }
Example #8
0
    /// <summary>
    /// Returns a reference to the radio button group
    /// specified by "id".
    /// </summary>
    /// <param name="id">The ID of the group (either an arbitrary integer ID, or the hashcode of a radio button's parent transform, depending on the settings).</param>
    /// <returns>Returns a reference to the group with the specified ID.</returns>
    public static RadioBtnGroup GetGroup(int id)
    {
        RadioBtnGroup group = null;

        for (int i = 0; i < groups.Count; ++i)
        {
            if (groups[i].groupID == id)
            {
                group = groups[i];
                break;
            }
        }

        if (group == null)
        {
            group = new RadioBtnGroup(id);
        }

        return(group);
    }
Example #9
0
    /// <summary>
    /// Makes the radio button a part of the specified group
    /// and it will thenceforth be mutually exclusive to all
    /// other radio buttons in the same group.
    /// </summary>
    /// <param name="groupID">The ID of the group to which this radio will be assigned.  Can be an arbitrary integer, or if useParentForGrouping is true, the hashcode of the parent transform.</param>
    public void SetGroup(int groupID)
    {
        // Remove from any existing group first:
        if (group != null)
        {
            group.buttons.Remove(this);
            group = null;
        }

        radioGroup = groupID;

        group = RadioBtnGroup.GetGroup(groupID);

        // Add self to the button group:
        group.buttons.Add(this);

        if (btnValue)
        {
            PopOtherButtonsInGroup();
        }
    }
Example #10
0
    public override void Copy(SpriteRoot s, ControlCopyFlags flags)
    {
        base.Copy(s, flags);

        if (!(s is UIRadioBtn))
        {
            return;
        }

        UIRadioBtn b = (UIRadioBtn)s;

        if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State)
        {
            state          = b.state;
            prevTransition = b.prevTransition;
            if (Application.isPlaying)
            {
                Value = b.Value;
            }
        }

        if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings)
        {
            group        = b.group;
            defaultValue = b.defaultValue;
        }

        if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation)
        {
            scriptWithMethodToInvoke = b.scriptWithMethodToInvoke;
            methodToInvoke           = b.methodToInvoke;
            whenToInvoke             = b.whenToInvoke;
            delay = b.delay;
        }

        if ((flags & ControlCopyFlags.Sound) == ControlCopyFlags.Sound)
        {
            soundToPlay = b.soundToPlay;
        }
    }
Example #11
0
    public override void Copy(IControl c, ControlCopyFlags flags)
    {
        if (!(c is UIRadioBtn3D))
        {
            return;
        }

        base.Copy(c);

        UIRadioBtn3D b = (UIRadioBtn3D)c;

        if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings)
        {
            group        = b.group;
            defaultValue = b.defaultValue;
        }

        if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State)
        {
            prevTransition = b.prevTransition;

            if (Application.isPlaying)
            {
                Value = b.Value;
            }
        }

        if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation)
        {
            scriptWithMethodToInvoke = b.scriptWithMethodToInvoke;
            methodToInvoke           = b.methodToInvoke;
            whenToInvoke             = b.whenToInvoke;
            delay = b.delay;
        }

        if ((flags & ControlCopyFlags.Sound) == ControlCopyFlags.Sound)
        {
            soundToPlay = b.soundToPlay;
        }
    }
Example #12
0
	/// <summary>
	/// Returns a reference to the radio button group
	/// specified by "id".
	/// </summary>
	/// <param name="id">The ID of the group (either an arbitrary integer ID, or the hashcode of a radio button's parent transform, depending on the settings).</param>
	/// <returns>Returns a reference to the group with the specified ID.</returns>
	public static RadioBtnGroup GetGroup(int id)
	{
		RadioBtnGroup group= null;

		for (int i = 0; i < groups.Count; ++i)
		{
			if(groups[i].groupID == id)
			{
				group = groups[i];
				break;
			}
		}

		if (group == null)
			group = new RadioBtnGroup(id);

		return group;
	}
Example #13
0
	/// <summary>
	/// Makes the radio button a part of the specified group
	/// and it will thenceforth be mutually exclusive to all
	/// other radio buttons in the same group.
	/// </summary>
	/// <param name="ID">The ID of the group to which this radio will be assigned.  Can be an arbitrary integer, or if useParentForGrouping is true, the hashcode of the parent transform.</param>
	public void SetGroup(int groupID)
	{
		// Remove from any existing group first:
		if (group != null)
		{
			group.buttons.Remove(this);
			group = null;
		}

		radioGroup = groupID;

		group = RadioBtnGroup.GetGroup(groupID);

		// Add self to the button group:
		group.buttons.Add(this);

		if (btnValue)
			PopOtherButtonsInGroup();
	}
Example #14
0
	//---------------------------------------------------
	// Misc
	//---------------------------------------------------
/*
	protected override void OnEnable()
	{
		base.OnEnable();

#if RADIOBTN_USE_PARENT
		SetGroup(transform.parent);
#else
		SetGroup(radioGroup);
#endif
	}
 */


	public override void OnDestroy()
	{
		base.OnDestroy();

		if (group == null)
			return;

		// Remove self from the group
		group.buttons.Remove(this);
		group = null;
	}
 public static IRadioButton GetSelected(GameObject go)
 {
     return(RadioBtnGroup.GetSelected(go.transform.GetHashCode()));
 }
Example #16
0
	protected override void OnDisable()
	{
		base.OnDisable();

		if (group == null)
			return;

		// Remove self from the group
		group.buttons.Remove(this);
		group = null;
	}
Example #17
0
	public override void Copy(IControl c, ControlCopyFlags flags)
	{
		if (!(c is UIRadioBtn3D))
			return;

		base.Copy(c);

		UIRadioBtn3D b = (UIRadioBtn3D)c;

		if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings)
		{
			group = b.group;
			defaultValue = b.defaultValue;
		}

		if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State)
		{
			prevTransition = b.prevTransition;

			if (Application.isPlaying)
				Value = b.Value;
		}

		if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation)
		{
			scriptWithMethodToInvoke = b.scriptWithMethodToInvoke;
			methodToInvoke = b.methodToInvoke;
			whenToInvoke = b.whenToInvoke;
			delay = b.delay;
		}

		if ((flags & ControlCopyFlags.Sound) == ControlCopyFlags.Sound)
		{
			soundToPlay = b.soundToPlay;
		}
	}
	protected void OnDisable()
	{
		if (group == null)
			return;

		// Remove self from the group
		group.buttons.Remove(this);
		group = null;
	}
Example #19
0
	public void SetGroup(int groupID)
#endif
	{
		// Remove from any existing group first:
		if (group != null)
		{
			group.buttons.Remove(this);
			group = null;
		}

#if RADIOBTN_USE_PARENT
		// This line makes Unity iPhone crash:
		//transform.parent = parent;
#else
		radioGroup = groupID;
#endif


		// Add self to a button group:
		for (int i = 0; i < buttonGroups.Count; ++i)
		{
#if RADIOBTN_USE_PARENT
			if (((RadioBtnGroup)buttonGroups[i]).groupID == transform.parent)
#else
			if(((RadioBtnGroup)buttonGroups[i]).groupID == radioGroup)
#endif
			{
				group = ((RadioBtnGroup)buttonGroups[i]);
				group.buttons.Add(this);
				if (btnValue)
					PopOtherButtonsInGroup();
			}
		}
		// If we didn't find a matching group, add a new one:
		if (group == null)
		{
			group = new RadioBtnGroup();
#if RADIOBTN_USE_PARENT
			group.groupID = transform.parent;
#else
			group.groupID = radioGroup;
#endif
			group.buttons.Add(this);
			buttonGroups.Add(group);
		}
	}
Example #20
0
	public override void Copy(SpriteRoot s, ControlCopyFlags flags)
	{
		base.Copy(s, flags);

		if (!(s is UIRadioBtn))
			return;

		UIRadioBtn b = (UIRadioBtn)s;

		if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State)
		{
			state = b.state;
			prevTransition = b.prevTransition;
			if (Application.isPlaying)
				Value = b.Value;
		}

		if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings)
		{
			group = b.group;
			defaultValue = b.defaultValue;
		}

		if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation)
		{
			scriptWithMethodToInvoke = b.scriptWithMethodToInvoke;
			methodToInvoke = b.methodToInvoke;
			whenToInvoke = b.whenToInvoke;
			delay = b.delay;
		}

		if ((flags & ControlCopyFlags.Sound) == ControlCopyFlags.Sound)
		{
			soundToPlay = b.soundToPlay;
		}
	}