/// <summary> /// Updates all GUI elements from the style if style changes. /// </summary> /// <param name="style">Style to display in the GUI.</param> /// <returns>State representing was anything modified between two last calls to <see cref="Refresh"/>.</returns> public InspectableState Refresh(GUIElementStyle style) { this.style = style; InspectableState oldModifiedState = modifiedState; if (modifiedState.HasFlag(InspectableState.Modified)) { modifiedState = InspectableState.NotModified; } if (style == null) { return(oldModifiedState); } fontField.Value = style.Font; fontSizeField.Value = style.FontSize; horzAlignField.Value = (ulong)style.TextHorzAlign; vertAlignField.Value = (ulong)style.TextVertAlign; imagePositionField.Value = (ulong)style.ImagePosition; wordWrapField.Value = style.WordWrap; normalGUI.Refresh(style.Normal); hoverGUI.Refresh(style.Hover); activeGUI.Refresh(style.Active); focusedGUI.Refresh(style.Focused); normalOnGUI.Refresh(style.NormalOn); hoverOnGUI.Refresh(style.HoverOn); activeOnGUI.Refresh(style.ActiveOn); focusedOnGUI.Refresh(style.FocusedOn); borderGUI.Refresh(style.Border); marginsGUI.Refresh(style.Margins); contentOffsetGUI.Refresh(style.ContentOffset); fixedWidthField.Value = style.FixedWidth; widthField.Value = style.Width; minWidthField.Value = style.MinWidth; maxWidthField.Value = style.MaxWidth; fixedHeightField.Value = style.FixedHeight; heightField.Value = style.Height; minHeightField.Value = style.MinHeight; maxHeightField.Value = style.MaxHeight; widthField.Active = style.FixedWidth; minWidthField.Active = !style.FixedWidth; maxWidthField.Active = !style.FixedWidth; heightField.Active = style.FixedHeight; minHeightField.Active = !style.FixedHeight; maxHeightField.Active = !style.FixedHeight; return(oldModifiedState); }
/// <summary> /// Sets a style for the specified GUI element type. /// </summary> /// <param name="name">Name of the style to add/modify.</param> /// <param name="style">Style object containing style options.</param> public void SetStyle(string name, GUIElementStyle style) { IntPtr stylePtr = IntPtr.Zero; if (style != null) { stylePtr = style.GetCachedPtr(); } Internal_SetStyle(mCachedPtr, name, stylePtr); }
/// <summary> /// Creates a new GUIFieldSelector and registers its GUI elements in the provided layout. /// </summary> /// <param name="layout">Layout into which to add the selector GUI hierarchy.</param> /// <param name="so">Scene object to inspect the fields for.</param> /// <param name="width">Width of the selector area, in pixels.</param> /// <param name="height">Height of the selector area, in pixels.</param> public GUIFieldSelector(GUILayout layout, SceneObject so, int width, int height) { rootSO = so; scrollArea = new GUIScrollArea(); scrollArea.SetWidth(width); scrollArea.SetHeight(height); layout.AddElement(scrollArea); GUISkin skin = EditorBuiltin.GUISkin; GUIElementStyle style = skin.GetStyle(EditorStyles.Expand); foldoutWidth = style.Width; Rebuild(); }
/// <summary> /// Recreates all the GUI elements used by this inspector. /// </summary> private void BuildGUI() { Layout.Clear(); styles.Clear(); GUISkin guiSkin = InspectedObject as GUISkin; if (guiSkin == null) { return; } string[] styleNames = guiSkin.StyleNames; foreach (var styleName in styleNames) { styles[styleName] = guiSkin.GetStyle(styleName); } valuesField = GUIDictionaryField <string, GUIElementStyle, GUIElementStyleEntry> .Create (new LocEdString("Styles"), styles, Layout); valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded"); valuesField.OnExpand += x => Persistent.SetBool("valuesField_Expanded", x); valuesField.OnChanged += x => { if (x != null) { foreach (var KVP in x) { if (guiSkin.HasStyle(KVP.Key)) { GUIElementStyle oldValue = guiSkin.GetStyle(KVP.Key); if (oldValue != KVP.Value) { guiSkin.SetStyle(KVP.Key, KVP.Value); } } else { guiSkin.SetStyle(KVP.Key, KVP.Value); } } string[] oldStyleNames = guiSkin.StyleNames; foreach (var styleName in oldStyleNames) { if (!x.ContainsKey(styleName)) { guiSkin.RemoveStyle(styleName); } } styles = x; } else { foreach (var KVP in styles) { guiSkin.RemoveStyle(KVP.Key); } styles.Clear(); } EditorApplication.SetDirty(guiSkin); }; valuesField.OnValueChanged += x => { guiSkin.SetStyle(x, styles[x]); EditorApplication.SetDirty(guiSkin); }; valuesField.OnValueRemoved += x => { guiSkin.RemoveStyle(x); EditorApplication.SetDirty(guiSkin); }; Layout.AddSpace(10); }
private static extern void Internal_CreateInstance(GUIElementStyle instance);