public override bool DrawHeader(Rect rect, GUIContent label) { bool boldDefaultFont = EditorGUIUtility.GetBoldDefaultFont(); SerializedProperty iterator = this.m_Object.GetIterator(); bool boldDefaultFont2 = false; if (this.m_Object.targetObjects.Length == 1) { bool flag = iterator.Next(true); while (flag) { if (iterator.isInstantiatedPrefab && iterator.prefabOverride) { boldDefaultFont2 = true; break; } flag = iterator.Next(false); } } EditorGUIUtility.SetBoldDefaultFont(boldDefaultFont2); bool result = GUI.Toggle(rect, base.foldout, label, ParticleSystemStyles.Get().moduleHeaderStyle); EditorGUIUtility.SetBoldDefaultFont(boldDefaultFont); return(result); }
public override bool DrawHeader(Rect rect, GUIContent label) { var wasBold = EditorGUIUtility.GetBoldDefaultFont(); SerializedProperty itr = m_Object.GetIterator(); bool useBold = false; if (m_Object.targetObjects.Length == 1) { bool validItr = itr.Next(true); while (validItr) { if (itr.isInstantiatedPrefab && itr.prefabOverride) { useBold = true; break; } validItr = itr.Next(false); } } EditorGUIUtility.SetBoldDefaultFont(useBold); var toggleState = GUI.Toggle(rect, foldout, label, ParticleSystemStyles.Get().moduleHeaderStyle); EditorGUIUtility.SetBoldDefaultFont(wasBold); return(toggleState); }
internal static void UpdateSkinCache(int skinIndex) { if (GUIUtility.s_SkinMode == 0) return; if (EditorStyles.s_CachedStyles[skinIndex] == null) { EditorStyles.s_CachedStyles[skinIndex] = new EditorStyles(); EditorStyles.s_CachedStyles[skinIndex].InitSharedStyles(); } EditorStyles.s_Current = EditorStyles.s_CachedStyles[skinIndex]; EditorGUIUtility.s_FontIsBold = -1; EditorGUIUtility.SetBoldDefaultFont(false); }
internal static void UpdateSkinCache(int skinIndex) { // Don't cache the Game GUISkin styles if (GUIUtility.s_SkinMode == 0) { return; } if (s_CachedStyles[skinIndex] == null) { s_CachedStyles[skinIndex] = new EditorStyles(); s_CachedStyles[skinIndex].InitSharedStyles(); } s_Current = s_CachedStyles[skinIndex]; EditorGUIUtility.s_FontIsBold = -1; EditorGUIUtility.SetBoldDefaultFont(false); }
internal static void ResetGUIState() { GUI.skin = null; Color white = Color.white; GUI.contentColor = white; GUI.backgroundColor = white; GUI.color = ((!EditorApplication.isPlayingOrWillChangePlaymode) ? Color.white : HostView.kPlayModeDarken); GUI.enabled = true; GUI.changed = false; EditorGUI.indentLevel = 0; EditorGUI.ClearStacks(); EditorGUIUtility.fieldWidth = 0f; EditorGUIUtility.labelWidth = 0f; EditorGUIUtility.SetBoldDefaultFont(false); EditorGUIUtility.UnlockContextWidth(); EditorGUIUtility.hierarchyMode = false; EditorGUIUtility.wideMode = false; ScriptAttributeUtility.propertyHandlerCache = null; }
public override void OnGUI(string searchContext) { using (new SettingsWindow.GUIScope()) { foreach (var group in m_Switches) { group.foldout = EditorGUILayout.Foldout(group.foldout, String.IsNullOrEmpty(group.name) ? "General" : group.name, group.HasAnyChangedValues ? Styles.boldFoldout : EditorStyles.foldout); if (group.foldout) { foreach (var diagnosticSwitch in group.switches) { DisplaySwitch(diagnosticSwitch); EditorGUILayout.Space(EditorGUI.kControlVerticalSpacing); EditorGUIUtility.SetBoldDefaultFont(false); } } EditorGUILayout.Space(EditorGUI.kControlVerticalSpacing.value * 1.2f); } } }
internal static void BeginProperty(Rect totalRect, MaterialProperty prop, MaterialSerializedProperty serializedProp, Object[] targets, float startY = -1) { if (targets == null || IsRegistered(prop, serializedProp)) { s_PropertyStack.Add(new PropertyData() { targets = null }); return; } PropertyData data = new PropertyData() { property = prop, serializedProperty = serializedProp, targets = targets, startY = startY, position = totalRect, wasBoldDefaultFont = EditorGUIUtility.GetBoldDefaultFont() }; data.Init(); s_PropertyStack.Add(data); if (data.isOverriden) { EditorGUIUtility.SetBoldDefaultFont(true); } if (data.isLockedByAncestor) { EditorGUI.BeginDisabledGroup(true); } EditorGUI.showMixedValue = data.hasMixedValue; }
private void DisplaySwitch(DiagnosticSwitch diagnosticSwitch) { var labelText = new GUIContent(diagnosticSwitch.name, diagnosticSwitch.description); var rowRect = GUILayoutUtility.GetRect(0, EditorGUI.kSingleLineHeight, GUILayout.ExpandWidth(true)); rowRect.xMax -= GUISkin.current.verticalScrollbar.fixedWidth + 5; var iconScaleFactor = EditorGUI.kSingleLineHeight / Styles.smallWarningIcon.height; var warningRect = new Rect(rowRect.x, rowRect.y, Styles.smallWarningIcon.width * iconScaleFactor, Styles.smallWarningIcon.height * iconScaleFactor); rowRect.x += warningRect.width + 2; if (diagnosticSwitch.needsRestart && Event.current.type == EventType.Repaint) { GUI.DrawTexture(warningRect, Styles.smallWarningIcon); } var resetButtonSize = EditorStyles.miniButton.CalcSize(GUIContent.Temp("Reset")); var resetButtonRect = new Rect(rowRect.xMax - resetButtonSize.x, rowRect.y, resetButtonSize.x, resetButtonSize.y); rowRect.xMax -= resetButtonSize.x + 2; if (!diagnosticSwitch.isSetToDefault) { if (GUI.Button(resetButtonRect, "Reset", EditorStyles.miniButton)) { diagnosticSwitch.persistentValue = diagnosticSwitch.defaultValue; DiagnosticSwitchesConsoleMessage.Instance.Update(); } } else { // Reserve an ID for the 'reset' button so that if the user begins typing in a text-valued switch, the // button showing up doesn't cause the focus to change GUIUtility.GetControlID("Button".GetHashCode(), FocusType.Passive, resetButtonRect); } EditorGUIUtility.SetBoldDefaultFont(!diagnosticSwitch.persistentValue.Equals(diagnosticSwitch.defaultValue)); EditorGUI.BeginChangeCheck(); if (diagnosticSwitch.value is bool) { diagnosticSwitch.persistentValue = EditorGUI.Toggle(rowRect, labelText, (bool)diagnosticSwitch.persistentValue); } else if (diagnosticSwitch.enumInfo != null) { if (diagnosticSwitch.enumInfo.isFlags) { // MaskField's "Everything" entry will set the value to 0xffffffff, but that might mean that it has set bits that // are not actually valid in the enum. Correct for it by masking the value against the bit patterns that are actually valid. int validMask = 0; foreach (int value in diagnosticSwitch.enumInfo.values) { validMask |= value; } // Also, many enums will provide a 'Nothing' entry at the bottom. If so we need to chop it off, because MaskField can't cope with there being two 'Nothing' entries. string[] names = diagnosticSwitch.enumInfo.names; int[] values = diagnosticSwitch.enumInfo.values; if (diagnosticSwitch.enumInfo.values[0] == 0) { names = new string[names.Length - 1]; values = new int[values.Length - 1]; Array.Copy(diagnosticSwitch.enumInfo.names, 1, names, 0, names.Length); Array.Copy(diagnosticSwitch.enumInfo.values, 1, values, 0, values.Length); } diagnosticSwitch.persistentValue = EditorGUI.MaskFieldInternal(rowRect, labelText, (int)diagnosticSwitch.persistentValue, names, values, EditorStyles.popup) & validMask; } else { var guiNames = new GUIContent[diagnosticSwitch.enumInfo.names.Length]; for (int i = 0; i < diagnosticSwitch.enumInfo.names.Length; ++i) { guiNames[i] = new GUIContent(diagnosticSwitch.enumInfo.names[i], diagnosticSwitch.enumInfo.annotations[i]); } diagnosticSwitch.persistentValue = EditorGUI.IntPopup(rowRect, labelText, (int)diagnosticSwitch.persistentValue, guiNames, diagnosticSwitch.enumInfo.values); } } else if (diagnosticSwitch.value is UInt32) { UInt32 minValue = (UInt32)diagnosticSwitch.minValue; UInt32 maxValue = (UInt32)diagnosticSwitch.maxValue; if ((maxValue - minValue <= kMaxRangeForSlider) && (maxValue - minValue > 0) && (minValue < int.MaxValue && maxValue < int.MaxValue)) { diagnosticSwitch.persistentValue = (UInt32)EditorGUI.IntSlider(rowRect, labelText, (int)(UInt32)diagnosticSwitch.persistentValue, (int)minValue, (int)maxValue); } else { diagnosticSwitch.persistentValue = (UInt32)EditorGUI.IntField(rowRect, labelText, (int)(UInt32)diagnosticSwitch.persistentValue); } } else if (diagnosticSwitch.value is int) { int minValue = (int)diagnosticSwitch.minValue; int maxValue = (int)diagnosticSwitch.maxValue; if ((maxValue - minValue <= kMaxRangeForSlider) && (maxValue - minValue > 0) && (minValue < int.MaxValue && maxValue < int.MaxValue)) { diagnosticSwitch.persistentValue = EditorGUI.IntSlider(rowRect, labelText, (int)diagnosticSwitch.persistentValue, minValue, maxValue); } else { diagnosticSwitch.persistentValue = EditorGUI.IntField(rowRect, labelText, (int)diagnosticSwitch.persistentValue); } } else if (diagnosticSwitch.value is string) { diagnosticSwitch.persistentValue = EditorGUI.TextField(rowRect, labelText, (string)diagnosticSwitch.persistentValue); } else if (diagnosticSwitch.value is float) { diagnosticSwitch.persistentValue = EditorGUI.FloatField(rowRect, labelText, (float)diagnosticSwitch.persistentValue); } else { var redStyle = new GUIStyle(); redStyle.normal.textColor = Color.red; EditorGUI.LabelField(rowRect, labelText, EditorGUIUtility.TrTextContent("Unsupported type: " + diagnosticSwitch.value.GetType().Name), redStyle); } if (EditorGUI.EndChangeCheck()) { DiagnosticSwitchesConsoleMessage.Instance.Update(); } }
internal static void EndProperty() { if (s_PropertyStack.Count == 0) { Debug.LogError("MaterialProperty stack is empty"); return; } var data = s_PropertyStack[s_PropertyStack.Count - 1]; if (data.targets == null) { s_PropertyStack.RemoveAt(s_PropertyStack.Count - 1); return; } Rect position = data.position; if (data.startY != -1) { position = GUILayoutUtility.GetLastRect(); position.yMin = data.startY; position.x = 1; position.width = EditorGUIUtility.labelWidth; } bool mouseOnLock = false; if (position != Rect.zero) { // Display override rect if (data.isOverriden) { EditorGUI.DrawMarginLineForRect(position, Styles.overrideLineColor); } Rect lockRegion = position; lockRegion.width = 14; lockRegion.height = 14; lockRegion.x = 11; lockRegion.y += (position.height - lockRegion.height) * 0.5f; mouseOnLock = lockRegion.Contains(Event.current.mousePosition); // Display lock icon Rect lockRect = position; lockRect.width = 32; lockRect.height = Mathf.Max(lockRect.height, 20.0f); lockRect.x = 8; lockRect.y += (position.height - lockRect.height) * 0.5f; if (data.isLockedByAncestor) { // Make sure we draw the lock only once bool isLastLockInStack = true; for (int i = 0; i < s_PropertyStack.Count - 1; i++) { if (s_PropertyStack[i].isLockedByAncestor) { isLastLockInStack = false; break; } } if (isLastLockInStack) { GUI.Label(lockRect, Styles.lockedByAncestorContent, Styles.centered); } } else if (data.isLockedInChildren) { GUI.Label(lockRect, Styles.lockInChildrenContent, Styles.centered); } else if (GUI.enabled) { GUIView.current?.MarkHotRegion(GUIClip.UnclipToWindow(lockRegion)); if (mouseOnLock) { EditorGUI.BeginDisabledGroup(true); GUI.Label(lockRect, Styles.lockInChildrenContent, Styles.centered); EditorGUI.EndDisabledGroup(); } } } // Restore state EditorGUI.showMixedValue = false; EditorGUIUtility.SetBoldDefaultFont(data.wasBoldDefaultFont); if (data.isLockedByAncestor) { EditorGUI.EndDisabledGroup(); } // Context menu if (Event.current.rawType == EventType.ContextClick && (position.Contains(Event.current.mousePosition) || mouseOnLock)) { PropertyData.DoPropertyContextMenu(mouseOnLock, data.targets); } else if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && mouseOnLock) { PropertyData.DoLockAction(data.targets); } s_PropertyStack.RemoveAt(s_PropertyStack.Count - 1); }