public static bool Toggle(bool theValue, string theText, Texture2D theImage, eStyleToggl theToggleStyle, params GUILayoutOption[] theLayout) { Init(); GUIContent aGuiContent = null; if(theImage != null) { aGuiContent = new GUIContent(theText, theImage); } else { aGuiContent = new GUIContent(theText); } bool aNewValue = false; if(itsSkinIndex == -1) { aNewValue = GUILayout.Toggle(theValue, aGuiContent, theLayout); } else { aNewValue = GUILayout.Toggle(theValue, aGuiContent, GetStyleToggl(theToggleStyle), theLayout); } if (aNewValue != theValue) { PlaySound(theToggleStyle.ToString()); } return aNewValue; }
/// <summary> /// Set click sound for toggles /// </summary> /// <param name="theTogglStyle"></param> /// <param name="theAudioClip"></param> public static void SetSoundForToggle(eStyleToggl theTogglStyle, AudioClip theAudioClip) { SetSound(theTogglStyle.ToString(),theAudioClip); }
/// <summary> /// Use this method to draw a toggle button /// </summary> /// <remarks> /// Use this method to draw a toggle button. to check if the state of the button has changed check the return value of this method. /// </remarks> /// <param name="theValue">the current state of the toggle button</param> /// <param name="theImage">the image of the toggle button</param> /// <param name="theToggleStyle">the style of the toggle button</param> /// <param name="theLayout">GUILayout options</param> /// <returns>returns true if the close toggle button was clicked</returns> public static bool Toggle(bool theValue, Texture2D theImage, eStyleToggl theToggleStyle, params GUILayoutOption[] theLayout) { Init(); bool aNewValue = false; if(itsSkinIndex == -1) { aNewValue = GUILayout.Toggle(theValue, theImage, theLayout); } else { aNewValue = GUILayout.Toggle(theValue, theImage, GetStyleToggl(theToggleStyle), theLayout); } if (aNewValue != theValue) { PlaySound(theToggleStyle.ToString()); } return aNewValue; }
/// <summary> /// returns the guistyle for the requested toggle type /// </summary> /// <param name="theTogglStyle">the type of requested toggle style</param> /// <returns>returns the requested toggle style. Returns the default toggle style if no custom style was found.</returns> public static GUIStyle GetStyleToggl(eStyleToggl theTogglStyle) { if(itsSkinIndex == -1) return GUI.skin.toggle; Init(); if(theTogglStyle == eStyleToggl.eTogglStreched && itsStyleToggleStreched[itsSkinIndex] != null) { return itsStyleToggleStreched[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglCompact && itsStyleToggleCompact[itsSkinIndex] != null) { return itsStyleToggleCompact[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglSuperCompact && itsStyleToggleSuperCompact[itsSkinIndex] != null) { return itsStyleToggleSuperCompact[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglRadioStreched && itsStyleToggleRadioStreched[itsSkinIndex] != null) { return itsStyleToggleRadioStreched[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglRadioCompact && itsStyleToggleRadioCompact[itsSkinIndex] != null) { return itsStyleToggleRadioCompact[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglRadioSuperCompact && itsStyleToggleRadioSuperCompact[itsSkinIndex] != null) { return itsStyleToggleRadioSuperCompact[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglSwitch && itsStyleToggleSwitch[itsSkinIndex] != null) { return itsStyleToggleSwitch[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglBoolean && itsStyleToggleBoolean[itsSkinIndex] != null) { return itsStyleToggleBoolean[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglArrow && itsStyleToggleArrow[itsSkinIndex] != null) { return itsStyleToggleArrow[itsSkinIndex]; } else if(theTogglStyle == eStyleToggl.eTogglButton && itsStyleToggleButton[itsSkinIndex] != null) { return itsStyleToggleButton[itsSkinIndex]; } if(itsStyleToggle[itsSkinIndex] != null) { return itsStyleToggle[itsSkinIndex]; } else { return GUI.skin.toggle; } }