/// <summary> /// Extracts from colorlovers, the percentages only the pixel-width, so it as to be divied with the totalwidth /// </summary> /// <returns>The from colorlovers.</returns> /// <param name="doc">Document.</param> /// <param name="loadPercentages">If set to <c>true</c> load percentages.</param> public static PaletteData extractFromColorlovers(Document doc, bool loadPercentages) { int colorCount = 0; int percentCount = 0; PaletteData palette = new PaletteData(); /* * IEnumerable<Tag> headerTags = doc.FindAll ("h1"); * foreach (Tag headerTag in headerTags) { * // if (!string.IsNullOrEmpty (headerTag.c)) { * * * //palette.name = headerTag.ToString (); * Debug.Log (headerTag.ToString ().HtmlDecode ()); * //["class"] == "feature-detail-container") { * * // } * } */ IEnumerable <Tag> links = doc.FindAll("a"); foreach (Tag a in links) { if (a ["class"] == "left pointer block") { string style = a ["style"]; //Debug.Log ("style.Split (';') " + style.Split (';').Length); foreach (string styleCss in style.Split(';')) { if (loadPercentages && styleCss.Contains("width")) { string width = styleCss.Split(':') [1]; width = width.Substring(0, width.IndexOf("px")); float widthF = float.Parse(width.Trim()); //Debug.Log ("found % " + widthF + " from " + styleCss); palette.totalWidth += widthF; palette.percentages [percentCount++] = widthF; } else if (styleCss.Contains("background-color")) { string bgColor = styleCss.Split(':') [1]; bgColor = bgColor.Trim().Substring(1); palette.colors [colorCount++] = JSONPersistor.HexToColor(bgColor); } } //Debug.Log (style); } } // Debug.Log (palette.percentages [0]); return(palette); }
public virtual JSONClass getJsonPalette() { JSONClass jClass = new JSONClass(); jClass ["name"] = name; string[] hexArray = JSONPersistor.getHexArrayFromColors(this.colors); for (int i = 0; i < hexArray.Length; i++) { jClass ["colors"] [i] = hexArray [i]; } for (int i = 0; i < this.alphas.Length; i++) { jClass ["alphas"] [i].AsFloat = this.colors [i].a; } for (int i = 0; i < this.percentages.Length; i++) { jClass ["percentages"] [i].AsFloat = this.percentages [i]; } jClass ["totalWidth"].AsFloat = this.totalWidth; //Debug.Log ("name: " + this.name + " " + jClass ["colors"].ToString () + " " + jClass ["percentages"].ToString ()); return(jClass); }
protected virtual PaletteData drawColorsAndPercentages(PaletteData data) { GUILayoutUtility.GetRect(Screen.width, 10); adjustPCTBefore = GUILayout.Toggle(adjustPCTBefore, " adjust percentage to the left"); Rect colorChangerRect = GUILayoutUtility.GetRect(Screen.width, data.colors.Length * colorChangerRowHeight); colorChangerRect.x += colorChangeLeftMargin; colorChangerRect.width -= colorChangeRightMargin; GUILayoutUtility.GetRect(Screen.width, 10); float startY = colorChangerRect.y + 10; for (int i = 0; i < data.colors.Length; i++) { // draw a little preview of the current color Rect colRect = new Rect(colorChangerRect.x, startY, 150, colorChangerRowHeight); Color currentColor = data.colors [i]; Color newColor = EditorGUI.ColorField(colRect, currentColor); string currentHex = JSONPersistor.ColorToHex(currentColor); Rect hexRect = new Rect(colorChangerRect.x + colRect.width + colorChangeMarginBetween, startY, hexFieldWidth, colorChangerRowHeight); string newHex = EditorGUI.TextField(hexRect, currentHex); if (!currentHex.Equals(newHex)) { data.colors [i] = JSONPersistor.HexToColor(newHex); } else if (!currentColor.ToString().Equals(newColor.ToString())) { data.colors [i] = newColor; data.alphas [i] = newColor.a; } float currentPct = data.percentages [i]; float maxPct = 1.0f - (data.percentages.Length - 1) * this.minPct; //Debug.Log ("max % " + maxPct); Rect silderRect = new Rect(colorChangerRect.x + colRect.width + colorChangeMarginBetween + hexRect.width + colorChangeMarginBetween, startY, colorChangerRect.width - colorChangeMarginBetween - colRect.width - colorChangeMarginBetween - hexRect.width, colorChangerRowHeight); float newPct = EditorGUI.Slider(silderRect, currentPct, this.minPct, maxPct); data = adjustPct(data, i, newPct, currentPct, maxPct); startY += colorChangerRowHeight; } return(data); }
public static Color[] getColorsArrayFromHex(string[] hexArray) { Color[] colors = new Color[hexArray.Length]; for (int i = 0; i < hexArray.Length; i++) { colors [i] = JSONPersistor.HexToColor(hexArray [i]); } return(colors); }
public static string[] getHexArrayFromColors(Color[] colors) { string[] hexArray = new string[colors.Length]; for (int i = 0; i < colors.Length; i++) { hexArray [i] = JSONPersistor.ColorToHex(colors [i]); } return(hexArray); }
public void loadPersistentID() { #if UNITY_EDITOR // only do during the Editor because it uses UnityEditor which isn't in a build // when a object isn't saved yet saved in a scene, the Id is == 0 //if (!persistentIDisSet ()) { persistentID = JSONPersistor.GetLocalIdentfier(this); UnityEditor.EditorUtility.SetDirty(this); //Debug.LogWarning ("set id " + persistentID); //} #endif }
public static PaletteData extractFromPLTTS(Document doc, bool loadPercent) { int colorCount = 0; int percentCount = 0; PaletteData palette = new PaletteData(); Tag colorBlock = doc.Find(".palette-colors"); //Debug.Log (colorBlock); foreach (Element colorDiv in colorBlock.Children) { if (!string.IsNullOrEmpty(colorDiv.ToString().Trim())) { // can contain empty Elements! //Tag colorTag = (HtmlSharp.Elements.Tags.Div)colorDiv; Tag colorTag = (Tag)colorDiv; string style = colorTag ["style"]; foreach (string styleCss in style.Split(';')) { if (loadPercent && styleCss.Contains("width")) { string width = styleCss.Split(':') [1]; width = width.Substring(0, width.IndexOf("%")); float widthF = float.Parse(width.Trim()); palette.totalWidth += widthF / 100; palette.percentages [percentCount++] = widthF / 100; } else if (styleCss.Contains("background-color")) { string bgColor = styleCss.Split(':') [1]; bgColor = bgColor.Trim().Substring(1); palette.colors [colorCount++] = JSONPersistor.HexToColor(bgColor); } } //Debug.Log (style); } } if (!loadPercent) { palette.percentages = PaletteData.getDefaultPercentages(); } return(palette); }
/// <summary> /// Init this instance, it's public so it can be called from a InspectorScript /// </summary> public void init() { if (id == -1) { id = JSONPersistor.GetLocalIdentfier(this.gameObject); } fileName = getFileName(); if (loadOnAwake && FileExists()) { //Debug.Log ("file exists: " + fileName); load(); } }
protected virtual void loadButtonTextures(string pathToTextures = null) { string folderPath = ""; if (string.IsNullOrEmpty(pathToTextures)) { folderPath = Application.dataPath + "/ColorPalettes/Editor/"; } else { folderPath = pathToTextures; } plusTex = JSONPersistor.getTextureFromWWW(folderPath + "plus_color.png"); plusTex.hideFlags = HideFlags.HideAndDontSave; minusTex = JSONPersistor.getTextureFromWWW(folderPath + "minus_color.png"); minusTex.hideFlags = HideFlags.HideAndDontSave; }
public virtual void setPalette(JSONClass jClass) { int size = jClass ["colors"].Count; name = jClass ["name"]; string[] hexArray = new string[size]; for (int i = 0; i < size; i++) { hexArray [i] = jClass ["colors"] [i]; } this.colors = JSONPersistor.getColorsArrayFromHex(hexArray); size = jClass ["alphas"].Count; // if the size of the file is different than the standard size -> init() if (this.alphas.Length != size) { this.alphas = new float[size]; } for (int i = 0; i < size; i++) { float alphaValue = jClass ["alphas"] [i].AsFloat; this.alphas [i] = alphaValue; this.colors [i].a = alphaValue; } size = jClass ["percentages"].Count; // if the size of the file is different than the standard size -> init() if (this.percentages.Length != size) { this.percentages = new float[size]; } for (int i = 0; i < size; i++) { this.percentages [i] = jClass ["percentages"] [i].AsFloat; } this.totalWidth = jClass ["totalWidth"].AsFloat; }
/// <summary> /// Gets the JSON key value pair /// </summary> /// <returns>The JSON key value.</returns> /// <param name="name">Name.</param> /// <param name="aValue">A value.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static string getJSONKeyValue <T> (T aValue, string name = "") { JSONBinaryTag tag = JSONPersistor.GetJSONBinaryTag <T> (aValue); Debug.Log("tag: " + tag); if (aValue.GetType().IsPrimitive) { //val.GetType().ToString() if (string.IsNullOrEmpty(name)) { name = "someValue"; } return("\"" + tag + "_" + name + "\"" + separator + "\"" + aValue.ToString() + "\""); /* } else if (tag == JSONBinaryTag.Array) { * * string arrayStr = name + " [ "; * JSONArray arr = (JSONArray)aValue; * * if (arr.Count > 0) { * int i = 0; * foreach (JSONNode node in arr.Childs) { * if (i > 0) { * arrayStr += " , "; * } * arrayStr += node.Value; * i++; * } * * } * arrayStr += " ]"; * * return arrayStr;*/ } else if (tag == JSONBinaryTag.Class) { JSONClass jClass = aValue as JSONClass; return(jClass.SaveToBase64()); //} else if (aValue.GetType ().IsClass) { } return(""); }
protected virtual PaletteData drawColorPalette(PaletteData data, bool showHexValues = false) { // palette height silder //height = EditorGUILayout.Slider ("Height", height, 100, 200); GUILayout.Space(10); //paletteHeight = height; EditorGUILayout.BeginHorizontal(); data.name = EditorGUILayout.TextField("Palette name: ", data.name); EditorGUILayout.EndHorizontal(); GUILayout.Space(10); Rect paletteRect; if (showHexValues) { paletteRect = GUILayoutUtility.GetRect(Screen.width, paletteHeight + paletteTopMargin); } else { paletteRect = GUILayoutUtility.GetRect(Screen.width, paletteHeight); } if (data.colors != null) { // show the palette float start = 20; for (int i = 0; i < data.colors.Length; i++) { Color col = data.colors [i]; float colWidth = data.percentages [i] * (Screen.width - 35); //Debug.Log (i + " starts " + start + " width " + colWidth); float yPos = paletteRect.position.y; if (showHexValues) { yPos = paletteRect.position.y + paletteTopMargin; } Rect colRect = new Rect(start, yPos, colWidth, paletteHeight - paletteBotMargin); EditorGUIUtility.DrawColorSwatch(colRect, col); Rect lableRect = colRect; lableRect.width = 60; lableRect.height = 15; lableRect.y -= paletteTopMargin * 0.5f; if (i % 2 == 0) { lableRect.y -= 15; } if (showHexValues) { string hexString = JSONPersistor.ColorToHex(col); Rect labelHexRect = new Rect(lableRect); labelHexRect.width = hexFieldWidth; string newHex = EditorGUI.TextField(labelHexRect, hexString); if (!newHex.Equals(JSONPersistor.ColorToHex(col))) { data.colors [i] = JSONPersistor.HexToColor(newHex); } } start += colWidth; } } return(data); }
public static Color[] getDefaultColors() { return(JSONPersistor.getColorsArrayFromHex(new string[] { "69D2E7", "A7DBD8", "E0E4CC", "F38630", "FA6900" })); }