public void SetupGUI() { backgroundStyle = new GUIStyle(GUI.skin.box); backgroundStyle.contentOffset = new Vector2(2f, 2f); expandRight = ResourceManager.LoadTexture("Textures/expandRight.png"); itemHeight = GUI.skin.label.CalcHeight(new GUIContent("text"), 100f); selectedLabel = new GUIStyle(GUI.skin.label); selectedLabel.normal.background = RTEditorGUI.ColorToTex(1, new Color(0.4f, 0.4f, 0.4f)); }
/// <summary> /// Loads up a texture tinted with col, and manages it in a memory for later use. /// It's adviced to prepare the texPath using the function before to create a uniform 'path format', because textures are compared through their paths /// </summary> public static Texture2D GetTintedTexture(string texPath, Color col) { string texMod = "Tint:" + col.ToString(); Texture2D tintedTexture = GetTexture(texPath, texMod); if (tintedTexture == null) { // We have to create a tinted version, perhaps even load the default texture if not yet in memory, and store it tintedTexture = LoadTexture(texPath); tintedTexture = RTEditorGUI.Tint(tintedTexture, col); AddTextureToMemory(texPath, tintedTexture, texMod); // Register texture for re-use } return(tintedTexture); }
public static Texture2D GetTintedTexture(string texPath, Color col) { string text = "Tint:" + col.ToString(); Texture2D texture2D = GetTexture(texPath, text); if ((UnityEngine.Object)texture2D == (UnityEngine.Object)null) { texture2D = LoadTexture(texPath); AddTextureToMemory(texPath, texture2D); texture2D = RTEditorGUI.Tint(texture2D, col); AddTextureToMemory(texPath, texture2D, text); } return(texture2D); }
/// <summary> /// Loads up a texture tinted with col, and manages it in a memory for later use. /// It's adviced to prepare the texPath using the function before to create a uniform 'path format', because textures are compared through their paths /// </summary> public static Texture2D GetTintedTexture(Texture2D tex, Color col) { MemoryTexture memTex = FindInMemory(tex); if (memTex != null && !string.IsNullOrEmpty(memTex.path)) { return(GetTintedTexture(memTex.path, col)); } string texMod = "Tint:" + col.ToString(); Texture2D tintedTexture = RTEditorGUI.Tint(tex, col); AddTextureToMemory(tex.name, tintedTexture, texMod); // Register texture for re-use return(tintedTexture); }
private void DrawItem(MenuItem item, Rect groupRect) { if (item.separator) { if (Event.current.type == EventType.Repaint) { RTEditorGUI.Seperator(new Rect(backgroundStyle.contentOffset.x + 1, currentItemHeight + 1, groupRect.width - 2, 1)); } currentItemHeight += 3; } else { Rect labelRect = new Rect(backgroundStyle.contentOffset.x, currentItemHeight, groupRect.width, itemHeight); if (labelRect.Contains(Event.current.mousePosition)) { selectedPath = item.path; } if (selectedPath == null) { Debug.Log("SELECTED PATH == NULL"); return; } bool selected = selectedPath == item.path || selectedPath.Contains(item.path + "/"); GUI.Label(labelRect, item.content, selected? NodeEditorGUI.nodeLabelSelected : NodeEditorGUI.nodeLabel); if (item.group) { GUI.DrawTexture(new Rect(labelRect.x + labelRect.width - 12, labelRect.y + (labelRect.height - 12) / 2, 12, 12), expandRight); if (selected) { item.groupPos = new Rect(groupRect.x + groupRect.width + 4, groupRect.y + currentItemHeight - 2, 0, 0); groupToDraw = item; } } else if (selected && ((Event.current.type == EventType.MouseDown && Event.current.button != 1) || (Event.current.button != 1 && Event.current.type == EventType.MouseUp))) { item.Execute(); close = true; Event.current.Use(); } currentItemHeight += itemHeight; } }
private void DrawItem(MenuItem item, Rect groupRect) { if (item.separator) { if (Event.current.type == EventType.Repaint) { RTEditorGUI.Seperator(new Rect(backgroundStyle.contentOffset.x + 1, currentItemHeight + 1, groupRect.width - 2, 1)); } currentItemHeight += 3; } else { Rect labelRect = new Rect(backgroundStyle.contentOffset.x, currentItemHeight, groupRect.width, itemHeight); bool selected = selectedPath.Contains(item.path); if (labelRect.Contains(Event.current.mousePosition)) { selectedPath = item.path; selected = true; } GUI.Label(labelRect, item.content, selected? selectedLabel : GUI.skin.label); if (item.group) { GUI.DrawTexture(new Rect(labelRect.x + labelRect.width - 12, labelRect.y + (labelRect.height - 12) / 2, 12, 12), expandRight); if (selected) { item.groupPos = new Rect(groupRect.x + groupRect.width + 4, groupRect.y + currentItemHeight - 2, 0, 0); groupToDraw = item; } } else if (selected && (Event.current.type == EventType.MouseDown || (Event.current.button != 1 && Event.current.type == EventType.MouseUp))) { item.Execute(); close = true; Event.current.Use(); } currentItemHeight += itemHeight; } }
private void DrawItem(MenuItem item, Rect groupRect) { if (item.separator) { if (Event.current.type == EventType.Repaint) { Vector2 contentOffset = backgroundStyle.contentOffset; RTEditorGUI.Seperator(new Rect(contentOffset.x + 1f, currentItemHeight + 1f, groupRect.width - 2f, 1f)); } currentItemHeight += 3f; } else { Vector2 contentOffset2 = backgroundStyle.contentOffset; Rect rect = new Rect(contentOffset2.x, currentItemHeight, groupRect.width, itemHeight); if (rect.Contains(Event.current.mousePosition)) { selectedPath = item.path; } bool flag = selectedPath == item.path || selectedPath.Contains(item.path + "/"); GUI.Label(rect, item.content, (!flag) ? GUI.skin.label : selectedLabel); if (item.group) { GUI.DrawTexture(new Rect(rect.x + rect.width - 12f, rect.y + (rect.height - 12f) / 2f, 12f, 12f), expandRight); if (flag) { item.groupPos = new Rect(groupRect.x + groupRect.width + 4f, groupRect.y + currentItemHeight - 2f, 0f, 0f); groupToDraw = item; } } else if (flag && (Event.current.type == EventType.MouseDown || (Event.current.button != 1 && Event.current.type == EventType.MouseUp))) { item.Execute(); close = true; Event.current.Use(); } currentItemHeight += itemHeight; } }