protected virtual void OnEnable() { OnBaseEnable(); m_Toggle = (ToggleBase)serializedObject.targetObject; m_Interactable = serializedObject.FindProperty("m_Interactable"); m_Graphic = serializedObject.FindProperty("m_Graphic"); m_iconData = serializedObject.FindProperty("m_Icon"); m_LabelText = serializedObject.FindProperty("m_Label"); m_GraphicChangesWithToggleState = serializedObject.FindProperty("m_ToggleGraphic"); m_ToggleOnLabel = serializedObject.FindProperty("m_ToggleOnLabel"); m_ToggleOffLabel = serializedObject.FindProperty("m_ToggleOffLabel"); m_ToggleOnIcon = serializedObject.FindProperty("m_ToggleOnIcon"); m_ToggleOffIcon = serializedObject.FindProperty("m_ToggleOffIcon"); m_AnimationDuration = serializedObject.FindProperty("m_AnimationDuration"); m_ChangeGraphicColor = serializedObject.FindProperty("m_ChangeGraphicColor"); m_GraphicOnColor = serializedObject.FindProperty("m_GraphicOnColor"); m_GraphicOffColor = serializedObject.FindProperty("m_GraphicOffColor"); m_GraphicDisabledColor = serializedObject.FindProperty("m_GraphicDisabledColor"); m_ChangeRippleColor = serializedObject.FindProperty("m_ChangeRippleColor"); m_RippleOnColor = serializedObject.FindProperty("m_RippleOnColor"); m_RippleOffColor = serializedObject.FindProperty("m_RippleOffColor"); }
protected override void OnEnable() { OnBaseEnable(); m_Toggle = (ToggleBase)serializedObject.targetObject; m_Interactable = serializedObject.FindProperty("m_Interactable"); m_AnimationDuration = serializedObject.FindProperty("m_AnimationDuration"); m_Group = serializedObject.FindProperty("m_Group"); m_AutoRegisterInParentGroup = serializedObject.FindProperty("m_AutoRegisterInParentGroup"); m_Graphic = serializedObject.FindProperty("m_Graphic"); //m_iconData = serializedObject.FindProperty("m_Icon"); //m_LabelText = serializedObject.FindProperty("m_Label"); m_GraphicChangesWithToggleState = serializedObject.FindProperty("m_ToggleGraphic"); m_ToggleOnLabel = serializedObject.FindProperty("m_ToggleOnLabel"); m_ToggleOffLabel = serializedObject.FindProperty("m_ToggleOffLabel"); m_ToggleOnIcon = serializedObject.FindProperty("m_ToggleOnIcon"); m_ToggleOffIcon = serializedObject.FindProperty("m_ToggleOffIcon"); m_ChangeGraphicColor = serializedObject.FindProperty("m_ChangeGraphicColor"); m_GraphicOnColor = serializedObject.FindProperty("m_GraphicOnColor"); m_GraphicOffColor = serializedObject.FindProperty("m_GraphicOffColor"); m_GraphicDisabledColor = serializedObject.FindProperty("m_GraphicDisabledColor"); m_ChangeRippleColor = serializedObject.FindProperty("m_ChangeRippleColor"); m_RippleOnColor = serializedObject.FindProperty("m_RippleOnColor"); m_RippleOffColor = serializedObject.FindProperty("m_RippleOffColor"); m_OnToggleOn = serializedObject.FindProperty("onToggleOn"); m_OnToggleOff = serializedObject.FindProperty("onToggleOff"); }
public virtual bool IsToggleInGroup(ToggleBase toggle) { if (toggle == null || !_Toggles.Contains(toggle)) { return(false); } return(true); }
public bool UnregisterToggle(ToggleBase toggle) { if (toggle != null && Application.isPlaying && _Toggles.Contains(toggle)) { var toggleIndex = _Toggles.IndexOf(toggle); return(UnregisterToggle(toggleIndex)); } return(false); }
public virtual bool NotifyToggleValueChanged(ToggleBase toggle, bool sendCallback = true) { if (!IsActiveAndEnabledInHierarchy() || !IsToggleInGroup(toggle)) { return(false); } //Only make sense when disabled toggle is the current selected if (!toggle.isOn) { if (toggle == GetCurrentSelectedToggle(false)) { if (m_AllowSwitchOff) { SetSelectedIndexInternal(-1); return(true); } //Invalid State, we must revert this to true /*else * { * toggle.isOn = true; * }*/ } return(false); } else { //Update current index SetSelectedIndexInternal(_Toggles.IndexOf(toggle)); // disable all toggles in the group for (var i = 0; i < _Toggles.Count; i++) { //Update current index if (_Toggles[i] == toggle) { continue; } if (sendCallback) { _Toggles[i].isOn = false; } else { _Toggles[i].SetIsOnWithoutNotify(false); } } } return(true); }
protected KeyValuePair <int, int> GetHierarchyDepth(ToggleBase toggle) { int depth = -1; int sibling = toggle != null?toggle.transform.GetSiblingIndex() : -1; var transform = toggle != null ? toggle.transform : null; while (transform != null) { depth++; transform = transform.parent; } return(new KeyValuePair <int, int>(depth, sibling)); }
public bool RegisterToggle(ToggleBase toggle) { if (toggle != null && Application.isPlaying && !_Toggles.Contains(toggle)) { _Toggles.Add(toggle); toggle.ApplyGroupAllowSwitchOff(); if (m_SortByHierarchyDepth) { SortRegisteredMembersDelayed(); } EnsureValidStateDelayed(); return(true); } return(false); }
public bool SetToggleValue(ToggleBase toggle, bool isOn, bool sendCallback = true) { //Prevent problem when switching off if (toggle == null && isOn && !m_AllowSwitchOff) { toggle = GetCurrentSelectedToggle(false); if (toggle == null) { //Pick first active toggle = ActiveToggles().FirstOrDefault(); //Pick first possible toggle if (toggle == null) { toggle = _Toggles.Find((a) => a != null); } } } //Disable all toggles (no other option if (toggle == null && isOn) { SetAllTogglesOff(sendCallback); return(true); } else { if (!IsToggleInGroup(toggle)) { return(false); } var oldValue = toggle.isOn; if (sendCallback) { toggle.isOn = isOn; } else { toggle.SetIsOnWithoutNotify(isOn); } NotifyToggleValueChanged(toggle, sendCallback); return(true); } }
public bool CanToggleValueChange(ToggleBase toggle, bool newValue) { if (toggle == null) { return(false); } if (!IsActiveAndEnabledInHierarchy() || !IsToggleInGroup(toggle)) { return(true); } //Can't change value if (!newValue && !allowSwitchOff && _Toggles.Count != 0) { var currentSelectedToggle = GetCurrentSelectedToggle(true); return(currentSelectedToggle != toggle); } return(true); }
public int GetToggleIndex(ToggleBase toggle) { return(_Toggles.IndexOf(toggle)); }