public OGStyle GetStyle(OGStyleType typ) { OGStyle result = null; switch (typ) { case OGStyleType.Basic: result = basic; break; case OGStyleType.Hover: result = hover; break; case OGStyleType.Active: result = active; break; case OGStyleType.Ticked: result = ticked; break; case OGStyleType.Thumb: result = thumb; break; } return(result); }
public void SetStyle(OGStyleType typ, OGStyle stl) { switch (typ) { case OGStyleType.Basic: basic = stl; break; case OGStyleType.Hover: hover = stl; break; case OGStyleType.Active: active = stl; break; case OGStyleType.Ticked: ticked = stl; break; case OGStyleType.Thumb: thumb = stl; break; } }
private Vector3[] CalcUVBorderLines(Rect controlRect, OGStyle style, Texture atlas) { Vector3[] lines = new Vector3[8]; float width = style.coordinates.width * uvScale; float height = style.coordinates.height * uvScale; float x = controlRect.x + style.coordinates.x * uvScale; float y = controlRect.y + (atlas.height - style.coordinates.y) * uvScale; // Left lines[0] = new Vector3(x, y, 0); lines[1] = lines[0] - new Vector3(0, height, 0); // Right lines[2] = new Vector3(x + width, y, 0); lines[3] = lines[2] - new Vector3(0, height, 0); // Top lines[4] = new Vector3(x, y - height, 0); lines[5] = lines[4] + new Vector3(width, 0, 0); // Bottom lines[6] = new Vector3(x, y, 0); lines[7] = lines[6] + new Vector3(width, 0, 0); return(lines); }
public static void DrawSprite(Rect rect, OGStyle style, float depth, Color tint, OGWidget clipping) { if (style == null) { return; } DrawSprite(rect, style.coordinates, depth, style.color, tint, clipping); }
////////////////// // Sprites ////////////////// // Regular public static void DrawSprite(Rect rect, OGStyle style, float depth, Color tint) { if (style == null) { return; } DrawSprite(rect, style, depth, tint, null); }
public void Refresh(OGSkin skin) { if (!skin) { return; } OGStyle newStyle; if (basic != null) { newStyle = skin.GetStyle(basic.name); if (newStyle != null) { basic = newStyle; } } if (hover != null) { newStyle = skin.GetStyle(hover.name); if (newStyle != null) { hover = newStyle; } } if (active != null) { newStyle = skin.GetStyle(active.name); if (newStyle != null) { active = newStyle; } } if (ticked != null) { newStyle = skin.GetStyle(ticked.name); if (newStyle != null) { ticked = newStyle; } } if (thumb != null) { newStyle = skin.GetStyle(thumb.name); if (newStyle != null) { thumb = newStyle; } } }
private int GetStyleIndex ( OGWidget widget, OGStyle style ) { if ( widget.root && widget.root.skin ) { for ( int i = 0; i < widget.root.skin.styles.Length; i++ ) { if ( widget.root.skin.styles[i].name == style.name ) { return i; } } } return 0; }
private void SortStyles(OGSkin skin, OGStyle focus) { SortStyles(skin); for (int i = 0; i < skin.styles.Length; i++) { if (skin.styles[i] == focus) { currentStyle = i; } } }
public static void DrawTiledSprite(Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY, OGWidget clipping) { for (int x = 0; x < tileX; x++) { for (int y = 0; y < tileY; y++) { Vector2 newScale = new Vector2(rect.width / tileX, rect.height / tileY); Vector2 newPosition = new Vector2(rect.x + x * newScale.x, rect.y + y * newScale.y); DrawSprite(new Rect(newPosition.x, newPosition.y, newScale.x, newScale.y), style, depth, tint, clipping); } } }
private int GetStyleIndex(OGSkin skin, OGStyle style) { if (skin != null && style != null) { for (int i = 0; i < skin.styles.Length; i++) { if (skin.styles[i].name == style.name) { return(i); } } } return(0); }
private int GetStyleIndex(OGWidget widget, OGStyle style) { if (widget.root && widget.root.skin) { for (int i = 0; i < widget.root.skin.styles.Length; i++) { if (widget.root.skin.styles[i].name == style.name) { return(i); } } } return(0); }
private void AddStyle ( string n ) { OGSkin skin = (OGSkin) target; for ( int i = 0; i < skin.styles.Length; i++ ) { if ( n == skin.styles[i].name ) { Debug.LogWarning ( "OpenGUI: There is already a style by name '" + n + "'" ); return; } } List< OGStyle > tempList = new List< OGStyle > ( skin.styles ); OGStyle newStyle = new OGStyle (); newStyle.name = n; tempList.Add ( newStyle ); skin.styles = tempList.ToArray(); SortStyles ( skin, newStyle ); }
private void AddStyle(string n) { OGSkin skin = (OGSkin)target; for (int i = 0; i < skin.styles.Length; i++) { if (n == skin.styles[i].name) { Debug.LogWarning("OpenGUI: There is already a style by name '" + n + "'"); return; } } List <OGStyle> tempList = new List <OGStyle> (skin.styles); OGStyle newStyle = new OGStyle(); newStyle.name = n; tempList.Add(newStyle); skin.styles = tempList.ToArray(); SortStyles(skin, newStyle); }
private void SortStyles ( OGSkin skin, OGStyle focus ) { SortStyles ( skin ); for ( int i = 0; i < skin.styles.Length; i++ ) { if ( skin.styles[i] == focus ) { currentStyle = i; } } }
public static void DrawTiledSlicedSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY, OGWidget clipping ) { Rect uvRect = style.coordinates; OGSlicedSpriteOffset border = style.border; Color color = style.color; // If no border is defined, draw a regular sprite if ( border.left == 0 && border.right == 0 && border.top == 0 && border.bottom == 0 ) { DrawSprite ( rect, style, depth, tint, clipping ); // Draw all corners, panels and the center } else { // Bottom left corner DrawSprite ( new Rect ( rect.x, rect.y, border.left, border.bottom ), new Rect ( uvRect.x, uvRect.y, border.left, border.bottom ), depth, color, tint, clipping ); // Left panel DrawTiledSprite ( new Rect ( rect.x, rect.y + border.bottom, border.left, rect.height - border.bottom - border.top ), new Rect ( uvRect.x, uvRect.y + border.bottom, border.left, uvRect.height - border.top - border.bottom ), depth, color, tint, 1.0f, tileY, clipping ); // Top left corner DrawSprite ( new Rect ( rect.x, rect.y + rect.height - border.top, border.left, border.top ), new Rect ( uvRect.x, uvRect.y + uvRect.height - border.top, border.left, border.top ), depth, color, tint, clipping ); // Top panel DrawTiledSprite ( new Rect ( rect.x + border.left, rect.y + rect.height - border.top, rect.width - border.horizontal, border.top ), new Rect ( uvRect.x + border.left, uvRect.y + uvRect.height - border.top, uvRect.width - border.horizontal, border.top ), depth, color, tint, tileX, 1.0f, clipping ); // Top right corner DrawSprite ( new Rect ( rect.x + rect.width - border.right, rect.y + rect.height - border.top, border.right, border.top ), new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y + uvRect.height - border.top, border.right, border.top ), depth, color, tint, clipping ); // Right panel DrawTiledSprite ( new Rect ( rect.x + rect.width - border.right, rect.y + border.bottom, border.right, rect.height - border.vertical ), new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y + border.bottom, border.right, uvRect.height - border.vertical ), depth, color, tint, 1.0f, tileY, clipping ); // Bottom left corner DrawSprite ( new Rect ( rect.x + rect.width - border.right, rect.y, border.right, border.bottom ), new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y, border.right, border.bottom ), depth, color, tint, clipping ); // Top panel DrawTiledSprite ( new Rect ( rect.x + border.left, rect.y, rect.width - border.horizontal, border.bottom ), new Rect ( uvRect.x + border.left, uvRect.y, uvRect.width - border.horizontal, border.bottom ), depth, color, tint, tileX, 1.0f, clipping ); // Center DrawTiledSprite ( new Rect ( rect.x + border.left, rect.y + border.bottom, rect.width - border.right - border.left, rect.height - border.bottom - border.top ), new Rect ( uvRect.x + border.left, uvRect.y + border.bottom, uvRect.width - border.right - border.left, uvRect.height - border.bottom - border.top ), depth, color, tint, tileX, tileY, clipping ); } }
// Tiled sliced public static void DrawTiledSlicedSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY ) { DrawSlicedSprite ( rect, style, depth, tint, null ); }
public static void DrawTiledSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY, OGWidget clipping ) { for ( int x = 0; x < tileX; x++ ) { for ( int y = 0; y < tileY; y++ ) { Vector2 newScale = new Vector2 ( rect.width / tileX, rect.height / tileY ); Vector2 newPosition = new Vector2 ( rect.x + x * newScale.x, rect.y + y * newScale.y ); DrawSprite ( new Rect ( newPosition.x, newPosition.y, newScale.x, newScale.y ), style, depth, tint, clipping ); } } }
public static void DrawSprite ( Rect rect, OGStyle style, float depth, Color tint, OGWidget clipping ) { if ( style == null ) { return; } DrawSprite ( rect, style.coordinates, depth, style.color, tint, clipping ); }
////////////////// // Sprites ////////////////// // Regular public static void DrawSprite ( Rect rect, OGStyle style, float depth, Color tint ) { if ( style == null ) { return; } DrawSprite ( rect, style, depth, tint, null ); }
// Tiled sliced public static void DrawTiledSlicedSprite(Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY) { DrawSlicedSprite(rect, style, depth, tint, null); }
override public void OnInspectorGUI() { serializedObject.Update(); OGSkin skin = (OGSkin)target; if (skin == null) { EditorGUILayout.LabelField("Skin is null for some reason"); return; } if (skin.styles == null) { EditorGUILayout.LabelField("Skin styles are null for some reason"); return; } if (currentStyle >= skin.styles.Length) { currentStyle = skin.styles.Length - 1; } Object tempObj = null; OGStyle s = null; if (skin.styles.Length > 0) { s = skin.styles[currentStyle]; } // Set defaults if (setDefaultsMode) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Manage defaults", EditorStyles.boldLabel); // Reset GUI.backgroundColor = Color.red; if (GUILayout.Button("Reset", GUILayout.Width(50))) { skin.ResetDefaults(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Set the default widget styles"); GUILayout.Space(10); // Back GUI.backgroundColor = Color.white; if (GUILayout.Button("Back to inspector", GUILayout.Height(30))) { setDefaultsMode = false; } // Auto detect bool autoDetect = false; if (GUILayout.Button("Autodetect")) { autoDetect = true; } GUILayout.Space(10); foreach (OGDefault d in skin.GetAllDefaults()) { EditorGUILayout.LabelField(d.widgetType.ToString(), EditorStyles.boldLabel, GUILayout.Width(100)); EditorGUILayout.BeginVertical(); foreach (OGStyleType styleType in System.Enum.GetValues(typeof(OGStyleType)) as OGStyleType[]) { if (OGSkin.IsStyleUsed(styleType, d.widgetType)) { string stateName = styleType.ToString(); OGStyle style = d.styleSet.GetStyle(styleType); int styleIndex; if (autoDetect) { styleIndex = GuessStyleIndex(skin, d.widgetType, styleType); } else { styleIndex = GetStyleIndex(skin, style); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(stateName, GUILayout.Width(80)); styleIndex = EditorGUILayout.Popup(styleIndex, GetStyles(skin)); EditorGUILayout.EndHorizontal(); d.styleSet.SetStyle(styleType, skin.styles [styleIndex]); } } EditorGUILayout.EndVertical(); GUILayout.Space(20); } // Back GUI.backgroundColor = Color.white; if (GUILayout.Button("Back to inspector", GUILayout.Height(30))) { setDefaultsMode = false; } // Adjust UV } else if (uvMode) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Style", EditorStyles.boldLabel, GUILayout.Width(50)); currentStyle = EditorGUILayout.Popup(currentStyle, GetStyles(false), GUILayout.Width(100)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Edit widget UV coordinates"); EditorGUILayout.Space(); // Atlas Texture uvAtlasTex = skin.atlas.mainTexture; s.coordinates.x = Mathf.Floor(s.coordinates.x); s.coordinates.y = Mathf.Floor(s.coordinates.y); s.coordinates.width = Mathf.Floor(s.coordinates.width); s.coordinates.height = Mathf.Floor(s.coordinates.height); s.coordinates.x = Mathf.Clamp(s.coordinates.x, 0, uvAtlasTex.width - s.coordinates.width); s.coordinates.y = Mathf.Clamp(s.coordinates.y, 0, uvAtlasTex.height - s.coordinates.height); s.coordinates = EditorGUILayout.RectField(s.coordinates); EditorGUILayout.Space(); uvScale = EditorGUILayout.Slider("Zoom", uvScale, 1, 10); EditorGUILayout.Space(); uvScrollPosition = GUILayout.BeginScrollView(uvScrollPosition, GUILayout.Height(Mathf.Clamp(uvAtlasTex.height * uvScale, uvAtlasTex.height, 300) + 20)); Rect uvControlRect = EditorGUILayout.GetControlRect(false, uvAtlasTex.height * uvScale, GUILayout.Width(uvAtlasTex.width * uvScale)); Vector3[] uvBorderLines = CalcUVBorderLines(uvControlRect, s, uvAtlasTex); GUI.DrawTexture(uvControlRect, uvAtlasTex, ScaleMode.ScaleToFit, true); Handles.color = Color.green; Handles.DrawLine(uvBorderLines[0], uvBorderLines[1]); Handles.DrawLine(uvBorderLines[2], uvBorderLines[3]); Handles.DrawLine(uvBorderLines[4], uvBorderLines[5]); Handles.DrawLine(uvBorderLines[6], uvBorderLines[7]); Handles.color = Color.white; GUILayout.EndScrollView(); EditorGUILayout.Space(); // Back GUI.backgroundColor = Color.white; if (GUILayout.Button("Back to inspector", GUILayout.Height(30))) { uvMode = false; } // Edit style } else { // Null check if (skin.styles.Length > 0) { // Style EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Style", EditorStyles.boldLabel, GUILayout.Width(50)); currentStyle = EditorGUILayout.Popup(currentStyle, GetStyles(false), GUILayout.Width(100)); EditorGUILayout.Space(); // ^ Preview if (skin.atlas != null && skin.atlas.mainTexture != null) { GUI.color = tintColor; Rect newCoords = new Rect( s.coordinates.x / skin.atlas.mainTexture.width, s.coordinates.y / skin.atlas.mainTexture.height, s.coordinates.width / skin.atlas.mainTexture.width, s.coordinates.height / skin.atlas.mainTexture.height ); Rect controlRect = EditorGUILayout.GetControlRect(false, s.coordinates.height * 2, GUILayout.Width(s.coordinates.width * 2)); Vector3[] borderLines = CalcBorderLines(controlRect, skin); Texture previewTex = skin.atlas.mainTexture; GUI.DrawTextureWithTexCoords(controlRect, previewTex, newCoords, true); GUI.color = Color.white; Handles.DrawLine(borderLines[0], borderLines[1]); Handles.DrawLine(borderLines[2], borderLines[3]); Handles.DrawLine(borderLines[4], borderLines[5]); Handles.DrawLine(borderLines[6], borderLines[7]); } EditorGUILayout.EndHorizontal(); GUILayout.Space(20); // ^ Name EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Name", GUILayout.Width(100)); s.name = EditorGUILayout.TextField(s.name); EditorGUILayout.EndHorizontal(); // ^ Coordinates EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Coordinates", GUILayout.Width(100)); s.coordinates = EditorGUILayout.RectField(s.coordinates); if (GUILayout.Button("Edit", GUILayout.Width(40), GUILayout.Height(30))) { uvMode = true; } EditorGUILayout.EndHorizontal(); // ^ Border EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Border", GUILayout.Width(100)); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); s.border.top = EditorGUILayout.FloatField(s.border.top, GUILayout.Width(30)); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); s.border.left = EditorGUILayout.FloatField(s.border.left, GUILayout.Width(30)); EditorGUILayout.Space(); s.border.right = EditorGUILayout.FloatField(s.border.right, GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); s.border.bottom = EditorGUILayout.FloatField(s.border.bottom, GUILayout.Width(30)); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); // ^ Color EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Color", GUILayout.Width(100)); s.color = EditorGUILayout.ColorField(s.color); tintColor = s.color; EditorGUILayout.EndHorizontal(); // ^ Text EditorGUILayout.Space(); showText = EditorGUILayout.Foldout(showText, "Text"); if (s.text != null && showText) { // ^^ Font EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Font", GUILayout.Width(100)); if (s.text.fontIndex >= skin.fonts.Length) { s.text.fontIndex = skin.fonts.Length - 1; } else if (s.text.fontIndex < 0) { s.text.fontIndex = 0; } s.text.fontIndex = EditorGUILayout.Popup(s.text.fontIndex, GetFonts(skin)); s.text.font = skin.fonts[s.text.fontIndex]; EditorGUILayout.EndHorizontal(); // ^^ Size EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Size", GUILayout.Width(100)); s.text.fontSize = EditorGUILayout.IntField(s.text.fontSize); EditorGUILayout.EndHorizontal(); // ^^ Colour EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Color", GUILayout.Width(100)); s.text.fontColor = EditorGUILayout.ColorField(s.text.fontColor); EditorGUILayout.EndHorizontal(); // ^^ Alignment EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Alignment", GUILayout.Width(100)); s.text.alignment = (TextAnchor)EditorGUILayout.Popup((int)s.text.alignment, GetAnchors()); EditorGUILayout.EndHorizontal(); // ^^ Word wrap EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Word wrap", GUILayout.Width(100)); s.text.wordWrap = EditorGUILayout.Toggle(s.text.wordWrap); EditorGUILayout.EndHorizontal(); // ^^ Padding EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Padding", GUILayout.Width(100)); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); s.text.padding.top = (int)EditorGUILayout.FloatField(s.text.padding.top, GUILayout.Width(30)); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); s.text.padding.left = (int)EditorGUILayout.FloatField(s.text.padding.left, GUILayout.Width(30)); EditorGUILayout.Space(); s.text.padding.right = (int)EditorGUILayout.FloatField(s.text.padding.right, GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); s.text.padding.bottom = (int)EditorGUILayout.FloatField(s.text.padding.bottom, GUILayout.Width(30)); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); // ^^ Line height EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Line height", GUILayout.Width(100)); s.text.lineHeight = EditorGUILayout.FloatField(s.text.lineHeight); EditorGUILayout.EndHorizontal(); // ^^ Spacing EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Spacing", GUILayout.Width(100)); s.text.spacing = EditorGUILayout.FloatField(s.text.spacing); EditorGUILayout.EndHorizontal(); } GUILayout.Space(20); } // Fonts EditorGUILayout.LabelField("Fonts", EditorStyles.boldLabel); List <OGFont> tmpList; if (skin.fonts.Length < 1) { skin.fonts = new OGFont[1]; } for (int i = 0; i < skin.fonts.Length; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.Width(30)); tempObj = (Object)skin.fonts[i]; tempObj = EditorGUILayout.ObjectField(tempObj, typeof(OGFont), false); skin.fonts[i] = (OGFont)tempObj; GUI.backgroundColor = Color.red; if (GUILayout.Button("x", GUILayout.Width(30), GUILayout.Height(14))) { tmpList = new List <OGFont> (skin.fonts); tmpList.RemoveAt(i); skin.fonts = tmpList.ToArray(); } GUI.backgroundColor = Color.white; EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); GUI.backgroundColor = Color.green; if (GUILayout.Button("+", GUILayout.Width(30), GUILayout.Height(14))) { tmpList = new List <OGFont> (skin.fonts); tmpList.Add(null); skin.fonts = tmpList.ToArray(); } GUI.backgroundColor = Color.white; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); // Font shader EditorGUILayout.LabelField("Font shader", EditorStyles.boldLabel); tempObj = (Object)skin.fontShader; tempObj = EditorGUILayout.ObjectField(tempObj, typeof(Shader), false); skin.fontShader = (Shader)tempObj; EditorGUILayout.Space(); // Atlas EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel); tempObj = (Object)skin.atlas; tempObj = EditorGUILayout.ObjectField(tempObj, typeof(Material), false); skin.atlas = (Material)tempObj; EditorGUILayout.Space(); // Delete mode if (deleteMode) { EditorGUILayout.LabelField("Delete style", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Are you sure?"); // Cancel if (GUILayout.Button("Cancel")) { deleteMode = false; } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete")) { deleteMode = false; RemoveStyle(currentStyle); } GUI.backgroundColor = Color.white; EditorGUILayout.EndHorizontal(); // Add mode } else if (addMode) { EditorGUILayout.LabelField("Add style", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); // Select addStyleName = EditorGUILayout.TextField(addStyleName); // Cancel if (GUILayout.Button("Cancel")) { addMode = false; } GUI.backgroundColor = Color.green; if (GUILayout.Button("Create")) { addMode = false; AddStyle(addStyleName); } GUI.backgroundColor = Color.white; EditorGUILayout.EndHorizontal(); // Else } else { EditorGUILayout.LabelField("Operations", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); // Add Style GUI.backgroundColor = Color.green; if (GUILayout.Button("Add style")) { addStyleName = ""; addMode = true; } // Delete style GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete style")) { deleteMode = true; } EditorGUILayout.EndHorizontal(); // Manage defaults GUI.backgroundColor = Color.white; if (GUILayout.Button("Sort styles")) { SortStyles(skin); } else if (GUILayout.Button("Manage defaults", GUILayout.Height(30))) { setDefaultsMode = true; } } EditorGUILayout.Space(); if (GUI.changed) { SavePrefab(); } } }
private int GetStyleIndex ( OGSkin skin, OGStyle style ) { if ( skin != null && style != null ) { for ( int i = 0; i < skin.styles.Length; i++ ) { if ( skin.styles[i].name == style.name ) { return i; } } } return 0; }
private int CompareNames ( OGStyle a, OGStyle b ) { return a.name.CompareTo ( b.name ); }
public void SetStyle ( OGStyleType typ, OGStyle stl ) { switch ( typ ) { case OGStyleType.Basic: basic = stl; break; case OGStyleType.Hover: hover = stl; break; case OGStyleType.Active: active = stl; break; case OGStyleType.Ticked: ticked = stl; break; case OGStyleType.Thumb: thumb = stl; break; } }
private int CompareNames(OGStyle a, OGStyle b) { return(a.name.CompareTo(b.name)); }
public void Refresh ( OGSkin skin ) { if ( !skin ) { return; } OGStyle newStyle; if ( basic != null ) { newStyle = skin.GetStyle ( basic.name ); if ( newStyle != null ) { basic = newStyle; } } if ( hover != null ) { newStyle = skin.GetStyle ( hover.name ); if ( newStyle != null ) { hover = newStyle; } } if ( active != null ) { newStyle = skin.GetStyle ( active.name ); if ( newStyle != null ) { active = newStyle; } } if ( ticked != null ) { newStyle = skin.GetStyle ( ticked.name ); if ( newStyle != null ) { ticked = newStyle; } } if ( thumb != null ) { newStyle = skin.GetStyle ( thumb.name ); if ( newStyle != null ) { thumb = newStyle; } } }
public static void DrawTiledSlicedSprite(Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY, OGWidget clipping) { Rect uvRect = style.coordinates; OGSlicedSpriteOffset border = style.border; Color color = style.color; // If no border is defined, draw a regular sprite if (border.left == 0 && border.right == 0 && border.top == 0 && border.bottom == 0) { DrawSprite(rect, style, depth, tint, clipping); // Draw all corners, panels and the center } else { // Bottom left corner DrawSprite( new Rect(rect.x, rect.y, border.left, border.bottom), new Rect(uvRect.x, uvRect.y, border.left, border.bottom), depth, color, tint, clipping ); // Left panel DrawTiledSprite( new Rect(rect.x, rect.y + border.bottom, border.left, rect.height - border.bottom - border.top), new Rect(uvRect.x, uvRect.y + border.bottom, border.left, uvRect.height - border.top - border.bottom), depth, color, tint, 1.0f, tileY, clipping ); // Top left corner DrawSprite( new Rect(rect.x, rect.y + rect.height - border.top, border.left, border.top), new Rect(uvRect.x, uvRect.y + uvRect.height - border.top, border.left, border.top), depth, color, tint, clipping ); // Top panel DrawTiledSprite( new Rect(rect.x + border.left, rect.y + rect.height - border.top, rect.width - border.horizontal, border.top), new Rect(uvRect.x + border.left, uvRect.y + uvRect.height - border.top, uvRect.width - border.horizontal, border.top), depth, color, tint, tileX, 1.0f, clipping ); // Top right corner DrawSprite( new Rect(rect.x + rect.width - border.right, rect.y + rect.height - border.top, border.right, border.top), new Rect(uvRect.x + uvRect.width - border.right, uvRect.y + uvRect.height - border.top, border.right, border.top), depth, color, tint, clipping ); // Right panel DrawTiledSprite( new Rect(rect.x + rect.width - border.right, rect.y + border.bottom, border.right, rect.height - border.vertical), new Rect(uvRect.x + uvRect.width - border.right, uvRect.y + border.bottom, border.right, uvRect.height - border.vertical), depth, color, tint, 1.0f, tileY, clipping ); // Bottom left corner DrawSprite( new Rect(rect.x + rect.width - border.right, rect.y, border.right, border.bottom), new Rect(uvRect.x + uvRect.width - border.right, uvRect.y, border.right, border.bottom), depth, color, tint, clipping ); // Top panel DrawTiledSprite( new Rect(rect.x + border.left, rect.y, rect.width - border.horizontal, border.bottom), new Rect(uvRect.x + border.left, uvRect.y, uvRect.width - border.horizontal, border.bottom), depth, color, tint, tileX, 1.0f, clipping ); // Center DrawTiledSprite( new Rect(rect.x + border.left, rect.y + border.bottom, rect.width - border.right - border.left, rect.height - border.bottom - border.top), new Rect(uvRect.x + border.left, uvRect.y + border.bottom, uvRect.width - border.right - border.left, uvRect.height - border.bottom - border.top), depth, color, tint, tileX, tileY, clipping ); } }
override public void OnInspectorGUI() { OGWidget widget = (OGWidget)target; if (!widget || !widget.root) { return; } // Check for hidden widgets if (widget.hidden) { EditorGUILayout.LabelField("This widget is rubbish that somehow didn't get deleted."); // Kill! if (GUILayout.Button("Fix")) { DestroyImmediate(target as GameObject); } } else { // Default inspector DrawDefaultInspector(); // OGCameraWindow, OGLineNode and OGTexture don't need styles if (target.GetType() != typeof(OGLineNode) && target.GetType() != typeof(OGTexture) && target.GetType() != typeof(OGCameraWindow)) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Style", EditorStyles.boldLabel); foreach (OGStyleType styleType in System.Enum.GetValues(typeof(OGStyleType)) as OGStyleType[]) { if (OGSkin.IsStyleUsed(styleType, widget.ToEnum())) { // Styles OGStyle wdStyle = widget.styles.GetStyle(styleType); int wdStyleIndex = GetStyleIndex(widget, wdStyle); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(styleType.ToString()); wdStyleIndex = EditorGUILayout.Popup(wdStyleIndex, GetStyles(widget)); widget.styles.SetStyle(styleType, widget.root.skin.styles [wdStyleIndex]); // ^ Edit if (GUILayout.Button("Edit", GUILayout.Width(40))) { Selection.activeObject = widget.root.skin; OGSkinInspector.SetCurrentStyle(wdStyleIndex); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal(); // Get defaults if (GUILayout.Button("Apply default styles")) { (target as OGWidget).ApplyDefaultStyles(); } // ^ Edit if (GUILayout.Button("Edit", GUILayout.Width(40))) { Selection.activeObject = widget.root.skin; OGSkinInspector.SetDefaultsMode(); } EditorGUILayout.EndHorizontal(); } } }
private Vector3[] CalcUVBorderLines ( Rect controlRect, OGStyle style, Texture atlas ) { Vector3[] lines = new Vector3[8]; float width = style.coordinates.width * uvScale; float height = style.coordinates.height * uvScale; float x = controlRect.x + style.coordinates.x * uvScale; float y = controlRect.y + ( atlas.height - style.coordinates.y ) * uvScale; // Left lines[0] = new Vector3 ( x, y, 0 ); lines[1] = lines[0] - new Vector3 ( 0, height, 0 ); // Right lines[2] = new Vector3 ( x + width, y, 0 ); lines[3] = lines[2] - new Vector3 ( 0, height, 0 ); // Top lines[4] = new Vector3 ( x, y - height, 0 ); lines[5] = lines[4] + new Vector3 ( width, 0, 0 ); // Bottom lines[6] = new Vector3 ( x, y, 0 ); lines[7] = lines[6] + new Vector3 ( width, 0, 0 ); return lines; }