//to be called from OnGui public static int DrawGuiItemsGroup(ref List <GuiItem> guiItems) { for (int i = 0; i < guiItems.Count; i++) { if (!guiItems[i].Enabled) { continue; } switch (guiItems[i].Type) { case GuiItemType.NORMALBUTTON: case GuiItemType.TOGGLEBUTTON: case GuiItemType.TAB: if (GUI.Button(guiItems[i].Rect, guiItems[i].Name, SNStyles.GetGuiItemStyle(guiItems[i]))) { return(i); } break; case GuiItemType.LABEL: GUI.Label(guiItems[i].Rect, guiItems[i].Name, SNStyles.GetGuiItemStyle(guiItems[i])); break; case GuiItemType.TEXTFIELD: GUI.TextField(guiItems[i].Rect, guiItems[i].Name, SNStyles.GetGuiItemStyle(guiItems[i])); break; } } return(-1); }
public static int CreateScrollView(Rect scrollRect, ref Vector2 scrollPos, ref List <GuiItem> scrollItems, string label, string listName, int maxShowItems = 0) { Vector2 labelSize = SNStyles.GetGuiItemStyle(GuiItemType.LABEL).CalcSize(new GUIContent(label)); if (maxShowItems > 0) { scrollRect.height = maxShowItems * (scrollItems[0].Rect.height + 2); } else { scrollRect.height = scrollRect.height - labelSize.y + 10; } GUI.Label(new Rect(scrollRect.x, scrollRect.y + 5, labelSize.x, labelSize.y), label, SNStyles.GetGuiItemStyle(GuiItemType.LABEL, textAnchor: TextAnchor.MiddleLeft)); GUI.Label(new Rect(scrollRect.x + labelSize.x + 5, scrollRect.y + 5, scrollRect.width - labelSize.x, labelSize.y), listName, SNStyles.GetGuiItemStyle(GuiItemType.LABEL, GuiColor.Green, textAnchor: TextAnchor.MiddleLeft)); scrollPos = GUI.BeginScrollView(new Rect(scrollRect.x, scrollRect.y + labelSize.y + 10, scrollRect.width, scrollRect.height), scrollPos, new Rect(scrollItems[0].Rect.x, scrollItems[0].Rect.y, scrollItems[0].Rect.width, scrollItems.Count * (scrollItems[0].Rect.height + 2))); int result = SNGUI.DrawGuiItemsGroup(ref scrollItems); GUI.EndScrollView(); return(result); }
public static void CreateHorizontalSlider(Rect rect, ref float sliderValue, float leftValue, float rightValue, string label, Event <object> onSliderValueChangedEvent) { Vector2 labelSize = SNStyles.GetGuiItemStyle(GuiItemType.LABEL).CalcSize(new GUIContent(label)); GUI.Label(new Rect(rect.x, rect.y + 5, labelSize.x, labelSize.y), label, SNStyles.GetGuiItemStyle(GuiItemType.LABEL, textAnchor: TextAnchor.MiddleLeft)); GUI.Label(new Rect(rect.x + labelSize.x + 5, rect.y + 5, rect.width - labelSize.x, labelSize.y), string.Format("{0:#.##}", sliderValue), SNStyles.GetGuiItemStyle(GuiItemType.LABEL, GuiColor.Green, textAnchor: TextAnchor.MiddleLeft)); object value = GUI.HorizontalSlider(new Rect(rect.x, rect.y + labelSize.y + 5, rect.width, 10), sliderValue, leftValue, rightValue); if ((float)value != sliderValue) { lock (value) { onSliderValueChangedEvent.Trigger(value); } } }
public static void CreateDropdown(Rect rect, ref bool showList, ref int listEntry, GUIContent[] listContent) { int dropDownListHash = "DropDownList".GetHashCode(); int controlID = GUIUtility.GetControlID(dropDownListHash, FocusType.Passive); bool done = false; Rect listRect = new Rect(rect.x, rect.y + rect.height, rect.width, /*Styles.GetGUIStyle(null, Button.BUTTONTYPE.NORMAL_CENTER).CalcHeight(listContent[0], 1.0f)*/ rect.height * listContent.Length); if (Event.current.GetTypeForControl(controlID) == EventType.MouseDown) { if (rect.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = controlID; showList = !showList; } } if (Event.current.GetTypeForControl(controlID) == EventType.MouseUp && showList) { if (listRect.Contains(Event.current.mousePosition)) { done = true; } } GUI.Button(rect, listContent[listEntry]); if (showList) { GUI.Box(listRect, ""); listEntry = GUI.SelectionGrid(listRect, listEntry, listContent, 1, SNStyles.GetGuiItemStyle(GuiItemType.NORMALBUTTON)); } if (done) { showList = false; } }