Here are the examples of the csharp api UnityEngine.GUI.BeginScrollView(UnityEngine.Rect, UnityEngine.Vector2, UnityEngine.Rect, bool, bool, UnityEngine.GUIStyle, UnityEngine.GUIStyle) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
23 Examples
19
View Source File : ScrollPanel.cs
License : Apache License 2.0
Project Creator : AantCoder
License : Apache License 2.0
Project Creator : AantCoder
public void Draw()
{
if (DrawInner == null) return;
if (AreaInner.width <= 0)
{
AreaInner = new Rect(0, 0, AreaOuter.width - WidthScrollLine, AreaOuter.height);
}
if (AreaInner.width <= 0) return;
ScrollPosition = GUI.BeginScrollView(
AreaOuter
, ScrollPosition
, AreaInner);
var rectDraw = DrawInner(AreaInner);
GUI.EndScrollView();
if (rectDraw.height > AreaInner.height) AreaInner.height = rectDraw.height;
if (AreaOuter.height > AreaInner.height) AreaInner.height = AreaOuter.height;
}
19
View Source File : TextBox.cs
License : Apache License 2.0
Project Creator : AantCoder
License : Apache License 2.0
Project Creator : AantCoder
public void Drow(Rect chatAreaOuter, bool scrollToDown = false)
{
var chatAreaInner = new Rect(0, 0, chatAreaOuter.width - ListBox<string>.WidthScrollLine, 0);
if (chatAreaInner.width <= 0) return;
//chatAreaInner.height = Text.CalcHeight(ChatText, chatAreaInner.width);
GUI.skin.textField.wordWrap = true;
chatAreaInner.height = GUI.skin.textField.CalcHeight(new GUIContent(Text), chatAreaInner.width);
//if (chatAreaInner.height > chatAreaOuter.height) chatAreaInner.height -= chatAreaOuter.height;
if (scrollToDown)
{
ScrollPosition.y = chatAreaInner.height - chatAreaOuter.height;
}
ScrollPosition = GUI.BeginScrollView(chatAreaOuter, ScrollPosition, chatAreaInner);
GUILayout.BeginArea(chatAreaInner);
var text = GUILayout.TextArea(Text ?? "", "Label");
if (Editable)
{
Text = text;
}
GUILayout.EndArea();
GUI.EndScrollView();
}
19
View Source File : ListBox.cs
License : Apache License 2.0
Project Creator : AantCoder
License : Apache License 2.0
Project Creator : AantCoder
public virtual void Drow()
{
if (DataSource == null) return;
if (LineHeight == 0) LineHeight = TextHeight;
ScrollPosition = GUI.BeginScrollView(
Area
, ScrollPosition
, new Rect(0, 0, Area.width - WidthScrollLine, DataSource.Count * LineHeight));
var rect = new Rect(0, 0, Area.width - WidthScrollLine, LineHeight);
for (int i = 0; i < DataSource.Count; i++)
{
//светлый фон каждой второй строки
if (OddLineHighlight && i % 2 == 1)
{
Widgets.DrawAltRect(rect);
}
//отрисовка строки
DrowLine(i, DataSource[i], rect);
//выделенная строка
if (ShowSelected && i == SelectedIndex)
{
Widgets.DrawHighlightSelected(rect);
//Widgets.DrawHighlight(rect);
}
//подсветка строки под курсором
if (!OddLineHighlight && Mouse.IsOver(rect))
{
Widgets.DrawHighlight(rect);
}
//всплывающая подсказка
if (Tooltip != null)
{
var tt = Tooltip(DataSource[i]);
if (!string.IsNullOrEmpty(tt))
{
TooltipHandler.TipRegion(rect, tt);
}
}
//событие нажатия на строку
if (Widgets.ButtonInvisible(rect))
{
SelectedIndex = i;
if (OnClick != null) OnClick(i, DataSource[i]);
}
rect.y += LineHeight;
}
GUI.EndScrollView();
}
19
View Source File : GUI.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public static Vector2 BeginScrollView(Rect position, Vector2 scrollView, Rect viewRect)
{
return UGUI.BeginScrollView(position, scrollView, viewRect, Style.ScrollView, Style.ScrollView);
}
19
View Source File : GUI.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public static Vector2 BeginScrollView(Rect position, Vector2 scrollView, Rect viewRect, bool alwaysHorizontal, bool alwaysVertical)
{
return UGUI.BeginScrollView(position, scrollView, viewRect, alwaysHorizontal, alwaysVertical, Style.ScrollView, Style.ScrollView);
}
19
View Source File : GUI.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public static Vector2 BeginScrollView(SmartRect position, Vector2 scrollView, Rect viewRect, bool move = false)
{
scrollView = UGUI.BeginScrollView(position.ToRect(), scrollView, viewRect, Style.ScrollView, Style.ScrollView);
if (move)
{
position.MoveY();
}
return scrollView;
}
19
View Source File : GUI.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public static Vector2 BeginScrollView(SmartRect position, Vector2 scrollView, Rect viewRect, bool alwaysHorizontal, bool alwaysVertical, bool move = false)
{
scrollView = UGUI.BeginScrollView(position.ToRect(), scrollView, viewRect, alwaysHorizontal, alwaysVertical, Style.ScrollView, Style.ScrollView);
if (move)
{
position.MoveY();
}
return scrollView;
}
19
View Source File : ListView.cs
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
public void Render(Rect rect, IEnumerable<T> itemList, float elementHeight = 20f, float elementPadding = 1f)
{
var totalElementHeight = elementHeight + elementPadding;
var width = rect.width;
var height = rect.height;
if (!object.ReferenceEquals(itemList, _itemList))
{
_itemList = itemList;
_filteredList = null;
}
GUI.BeginGroup(rect);
// Search Field
var searchFieldRect = new Rect(5f, 5f, width - 25f, elementHeight);
var lastSearchString = _searchString;
GUI.SetNextControlName("Apex_ListView_Search");
_searchString = EditorGUI.TextField(searchFieldRect, _searchString, SharedStyles.BuiltIn.searchFieldStyle);
EditorGUI.FocusTextInControl("Apex_ListView_Search");
var searchCancelRect = new Rect(searchFieldRect.x + searchFieldRect.width, 5f, 10f, elementHeight);
if (GUI.Button(searchCancelRect, GUIContent.none, string.IsNullOrEmpty(_searchString) ? SharedStyles.BuiltIn.searchCancelButtonEmpty : SharedStyles.BuiltIn.searchCancelButton))
{
_searchString = string.Empty;
GUIUtility.keyboardControl = 0;
}
// filter list based on search string
if (_filteredList == null || !string.Equals(lastSearchString, _searchString, StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(_searchString))
{
_filteredList = _itemList as T[];
if (_filteredList == null)
{
_filteredList = _itemList.ToArray();
}
}
else
{
_filteredList = _itemList.Where(t => _searchPredicate(t, _searchString)).ToArray();
}
_selectRangeStart = _selectRangeEnd = -1;
_selectedIndexes.Clear();
}
// Scroll View
var noneItemAdjust = _allowNoneSelect ? 1 : 0;
float listStartY = searchFieldRect.y + searchFieldRect.height + 5f;
var scrollViewRect = new Rect(0f, listStartY, width, height - listStartY);
var innerScrollView = new Rect(0f, 0f, scrollViewRect.width - 20f, (_filteredList.Length + noneItemAdjust) * totalElementHeight);
//Do preselect if applicable
var evt = Event.current;
if (evt != null && evt.type == EventType.Repaint && _selectPredicate != null)
{
_selectedIndexes.AddRange(_filteredList.Select((item, idx) => _selectPredicate(item) ? idx : -1).Where(idx => idx >= 0));
if (_selectedIndexes.Count > 0)
{
_selectRangeStart = _selectRangeEnd = _selectedIndexes.Min();
EnsureInView(_selectRangeStart, totalElementHeight, scrollViewRect.height);
}
_selectPredicate = null;
}
_scrollPos = GUI.BeginScrollView(scrollViewRect, _scrollPos, innerScrollView);
// Element List
int startIdx = Math.Max(Mathf.FloorToInt(_scrollPos.y / totalElementHeight) - noneItemAdjust, 0);
int endIdx = Math.Min(startIdx + Mathf.CeilToInt(Mathf.Min(scrollViewRect.height, innerScrollView.height) / totalElementHeight), _filteredList.Length);
if (_allowNoneSelect && _scrollPos.y < totalElementHeight)
{
var itemRect = new Rect(2f, 0f, innerScrollView.width, elementHeight);
var style = _noneSelected ? SharedStyles.BuiltIn.objectSelectorBoxActive : SharedStyles.BuiltIn.objectSelectorBoxNormal;
GUI.Box(itemRect, "None", style);
}
var currentY = (startIdx + noneItemAdjust) * totalElementHeight;
for (var i = startIdx; i < endIdx; i++)
{
var item = _filteredList[i];
var itemRect = new Rect(2f, currentY, innerScrollView.width, elementHeight);
var style = _selectedIndexes.Contains(i) ? SharedStyles.BuiltIn.objectSelectorBoxActive : SharedStyles.BuiltIn.objectSelectorBoxNormal;
GUI.Box(itemRect, _itemRenderer(item), style);
currentY += totalElementHeight;
}
GUI.EndScrollView();
//Handle mouse clicks and key presses
if (evt.type == EventType.MouseDown && evt.button == MouseButton.left)
{
evt.Use();
float adjustedMouseY = evt.mousePosition.y + (_scrollPos.y - listStartY);
var index = Mathf.FloorToInt(adjustedMouseY / totalElementHeight) - noneItemAdjust;
if (_allowNoneSelect && index < 0)
{
SelectNone();
}
else if (_allowMultiSelect)
{
if (evt.command || evt.control)
{
SingleToggle(index);
}
else if (evt.shift)
{
RangeSelect(index);
}
else
{
SingleSelect(index);
}
}
else
{
SingleSelect(index);
}
//We allow double-click selection under all cirreplacedstances
_singleSelected = (_onSelect != null) && (evt.clickCount == 2) && (_selectedIndexes.Count == 1 || _noneSelected);
if (!_singleSelected)
{
_owner.Repaint();
}
}
else if (evt.type == EventType.MouseUp && evt.button == MouseButton.left)
{
evt.Use();
if (_singleSelected)
{
// double click detected
DoSelect();
}
}
else if (evt.type == EventType.KeyUp)
{
if (evt.keyCode == KeyCode.DownArrow)
{
evt.Use();
if (_selectRangeStart < 0 && _allowNoneSelect && !_noneSelected)
{
SelectNone();
}
else if (_allowMultiSelect && evt.shift)
{
RangeSelect(_selectRangeEnd + 1);
}
else
{
SingleSelect(_selectRangeStart + 1);
}
EnsureInView(_selectRangeEnd, totalElementHeight, scrollViewRect.height);
}
else if (evt.keyCode == KeyCode.UpArrow)
{
evt.Use();
if (_selectRangeStart == 0 && _selectRangeEnd == 0 && _allowNoneSelect)
{
SelectNone();
}
else if (_selectRangeEnd < 0 && !_noneSelected)
{
SingleSelect(_filteredList.Length - 1);
}
else if (_allowMultiSelect && evt.shift)
{
RangeSelect(_selectRangeEnd - 1);
}
else
{
SingleSelect(_selectRangeStart - 1);
}
EnsureInView(_selectRangeStart, totalElementHeight, scrollViewRect.height);
}
else if (evt.keyCode == KeyCode.A && (evt.control || evt.command))
{
evt.Use();
_noneSelected = false;
AddSelected(0, _filteredList.Length - 1);
}
else if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter)
{
evt.Use();
if (_onSelect != null && (_selectedIndexes.Count > 0 || _noneSelected))
{
DoSelect();
}
}
}
GUI.EndGroup();
}
19
View Source File : ModMenuComponent.cs
License : MIT License
Project Creator : Dazegambler
License : MIT License
Project Creator : Dazegambler
void AddonsMenu(int id)
{
if (id == 0)
{
var list = ULTRAKIT.Loader.AddonLoader.addons;
if (GUI.Button(new Rect(5, 5, addonMenuWidth - 10, 50), $"Addons:{list.Count}"))
{
}
active = true;
if (active)
{
if (list.Count > 20)
{
Scroll = GUI.BeginScrollView(new Rect(5, 60, 155, 800), Scroll, _scroll, false, false);
for (int i = 0; i < list.Count; i++)
{
if (GUI.Button(new Rect(5, 60 + (35 * (i)), addonMenuWidth - 10, 30), list.ElementAt(i)?.Data?.ModName ?? "Unnamed Mod"))
{
Selected = list.ElementAt(i);
}
_scroll = new Rect(5, 60, 155, 95 + (35 * i));
if (wind.height > 800)
{
wind.height = 800;
}
else
{
wind.height = 95 + (35 * i);
}
}
GUI.EndScrollView();
}
else
{
for (int i = 0; i < list.Count; i++)
{
if(list.ElementAt(i).Enabled == false)
{
if (GUI.Button(new Rect(5, 60 + (35 * (i)), addonMenuWidth - 10, 30), $"<color=grey>{list.ElementAt(i)?.Data?.ModName ?? "Unnamed Mod "}</color>"))
{
Selected = list.ElementAt(i);
}
}
else
{
if (GUI.Button(new Rect(5, 60 + (35 * (i)), addonMenuWidth - 10, 30), list.ElementAt(i)?.Data?.ModName ?? "Unnamed Mod "))
{
Selected = list.ElementAt(i);
}
}
wind.height = 95 + (35 * i);//95 + (35 * i)
}
}
}
else
{
wind = guirect;
}
}
}
19
View Source File : DependencyWeb.cs
License : GNU Lesser General Public License v3.0
Project Creator : disruptorbeam
License : GNU Lesser General Public License v3.0
Project Creator : disruptorbeam
private void OnGUI() {
if(lastPreplacedDetectedNoWebTestsSoDisplayDebugAsExample && testsAndTheirDependenciesList.Count == 0) {
MapDependencies();
}
GUIStyle refButton = new GUIStyle(GUI.skin.button);
refButton.normal.textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black;
Color defaultBgColor = GUI.backgroundColor;
GUI.backgroundColor = Color.gray;
if(GUI.Button(new Rect(0,0,75, 25), "Refresh", refButton)) {
inspectedNodeWindow = -1;
RenderedNodes = new List<DependencyNode>();
testsAndTheirDependenciesList = new List<KeyValuePair<string, string[]>>();
DependencyWebs = new List<DependencyNode>();
MapDependencies();
}
GUI.backgroundColor = defaultBgColor;
Rect allSize = new Rect(0, 0, lastRenderX + infoBoxMinWidth, maxWindowY + infoBoxMinWidth);
scroll = GUI.BeginScrollView(new Rect(0, 0, lastRenderX, lastRenderY), scroll, new Rect(0, 0, lastRenderX + infoBoxMinWidth, lastRenderY + infoBoxMinWidth), GUIStyle.none, GUIStyle.none);
GUI.Box(allSize, string.Empty);
for(int all = 0; all < DependencyWebs.Count; all++) {
int index = 0;
DependencyNode parentNode = DependencyWebs[all];
if(!RenderedNodes.Where(x => x.TestName == parentNode.TestName).Any()) {
RenderedNodes.Add(parentNode);
index = RenderedNodes.Count - 1;
float width = DetermineRectWidthBasedOnLengthOfString(RenderedNodes[index].TestName);
Rect newRect = originRect;
newRect.width = width;
RenderedNodes[index].rect = GenerateNewNonOverlappingRectPositionForNewNode(newRect);
} else {
index = RenderedNodes.FindIndex(a => a.TestName == parentNode.TestName);
}
//Create new node, or find existing one, and draw lines between this node and the dependency.
List<KeyValuePair<DependencyNodeConnectionType,string>> LinkedNodeTestNames = RenderedNodes[index].Dependencies.ToList();
for(int s = 0; s < LinkedNodeTestNames.Count; s++) {
if(LinkedNodeTestNames[s].Key == DependencyNodeConnectionType.Incoming) {
string testName = LinkedNodeTestNames[s].Value;
DependencyNode thisNode = new DependencyNode();
int indexChild = 0;
List<DependencyNode> match = RenderedNodes.Where(x => x.TestName == testName).ToList();
if(!match.Any()) {
thisNode.TestName = testName;
thisNode.Dependencies = DependencyWebs.Where(x => x.TestName == thisNode.TestName).Select(x => x.Dependencies).Single();
RenderedNodes.Add(thisNode);
indexChild = RenderedNodes.Count - 1;
float width = DetermineRectWidthBasedOnLengthOfString(RenderedNodes[indexChild].TestName);
Rect newRect = RenderedNodes[all].rect;
newRect.width = width;
RenderedNodes[indexChild].rect = GenerateNewNonOverlappingRectPositionForNewNode(newRect);
} else {
indexChild = RenderedNodes.FindIndex(a => a.TestName == testName);
}
Handles.BeginGUI();
Handles.DrawBezier(RenderedNodes[index].rect.center, RenderedNodes[indexChild].rect.center, new Vector2(RenderedNodes[index].rect.xMax + 50f, RenderedNodes[index].rect.center.y), new Vector2(RenderedNodes[indexChild].rect.xMin - 50f, RenderedNodes[indexChild].rect.center.y), Color.cyan, null, 5f);
Handles.EndGUI();
}
}
}
GUIStyle f = new GUIStyle(EditorStyles.foldout);
f.richText = true;
//Render each node window object.
BeginWindows();
for(int i = 0; i < RenderedNodes.Count; i++) {
RenderedNodes[i].rect = GUI.Window(i, RenderedNodes[i].rect, WindowEvents, RenderedNodes[i].TestName);
}
EndWindows();
string nodeDetails = inspectedNodeWindow >= 0 ? GetNodeDetails(RenderedNodes[inspectedNodeWindow]) : GetNodeDetails(new DependencyNode());
float boxHeight = TestMonitorHelpers.DetermineRectHeightBasedOnLinesInNodeDetails(nodeDetails) + 50;
float boxWidth = longestTestNameInInfoBox > infoBoxMinWidth ? longestTestNameInInfoBox : infoBoxMinWidth;
bool overflowX = boxWidth > infoBoxMinWidth;
//Account for size of scroll bar in scrollable space
if(overflowX) {
boxHeight += 40;
}
float scrollViewHeight = boxHeight < position.height ? boxHeight : position.height;
bool overflowY = scrollViewHeight == position.height;
if(overflowY) {
boxWidth += 40;
}
GUI.EndScrollView();
GUIStyle verticalScrollBar = new GUIStyle(GUI.skin.verticalScrollbar);
GUIStyle horizontalScrollBar = overflowX ? new GUIStyle(GUI.skin.horizontalScrollbar) : GUIStyle.none;
infoBoxScroll = GUI.BeginScrollView(new Rect(position.width - infoBoxMinWidth, 0, infoBoxMinWidth, scrollViewHeight), infoBoxScroll, new Rect(new Vector2(position.width - (infoBoxMinWidth - 5), 4), new Vector2(boxWidth, boxHeight)), horizontalScrollBar, verticalScrollBar);
//Display selected node's details in details panel.
GUIStyle infoBox = new GUIStyle(GUI.skin.box);
infoBox.richText = true;
infoBox.normal.background = MakeTextureFromColor(new Color(0.175f, 0.175f, 0.175f, 1f));
infoBox.alignment = TextAnchor.UpperLeft;
GUI.Box(new Rect(new Vector2(position.width - (infoBoxMinWidth - 5), 4), new Vector2(boxWidth, boxHeight)), nodeDetails, infoBox);
lastRenderX = position.width + infoBoxMinWidth;
lastRenderY = position.height;
GUI.EndScrollView();
}
19
View Source File : EditorTrackTree.cs
License : MIT License
Project Creator : huailiang
License : MIT License
Project Creator : huailiang
public void OnGUI(SeqenceState state)
{
if (hierachy == null)
{
BuildTreeHierachy(state);
}
winRect = SeqenceWindow.inst.winArea;
posRect = winRect;
posRect.x = x;
posRect.y = _y;
posRect.height = winRect.height - _y;
posRect.width = winRect.width - x;
viewRect = posRect;
viewRect.height = TracksBtmY - _y;
viewRect.width -= 20;
width = winRect.width;
SyncTreeWidth();
float y = WindowConstants.trackRowYPosition;
Rect clip = new Rect(0, y, winRect.width, winRect.height - y);
GUI.BeginClip(clip);
if (hierachy != null)
for (int i = 0; i < hierachy.Count; i++)
{
hierachy[i].OnGUI(scroll);
}
GUI.EndClip();
bool vshow = viewRect.height > posRect.height;
if (vshow)
{
scroll = GUI.BeginScrollView(posRect, scroll, viewRect, false, vshow);
GUI.EndScrollView();
}
}
19
View Source File : MessageList.cs
License : MIT License
Project Creator : IllusionMods
License : MIT License
Project Creator : IllusionMods
internal void OnGUI(Rect fullPos)
{
DrawOutline(fullPos, 1f);
Rect pos = new Rect(fullPos.x + k_BorderSize, fullPos.y + k_BorderSize, fullPos.width - 2 * k_BorderSize, fullPos.height - 2 * k_BorderSize);
if (m_Dimensions.y == 0 || m_Dimensions.x != pos.width - k_ScrollbarPadding)
{
//recalculate height.
m_Dimensions.x = pos.width - k_ScrollbarPadding;
m_Dimensions.y = 0;
foreach (var message in m_Messages)
{
m_Dimensions.y += m_Style[0].CalcHeight(new GUIContent(message.message), m_Dimensions.x);
}
}
m_ScrollPosition = GUI.BeginScrollView(pos, m_ScrollPosition, new Rect(0, 0, m_Dimensions.x, m_Dimensions.y));
int counter = 0;
float runningHeight = 0.0f;
foreach (var message in m_Messages)
{
int index = counter % 2;
var content = new GUIContent(message.message);
float height = m_Style[index].CalcHeight(content, m_Dimensions.x);
GUI.Box(new Rect(0, runningHeight, m_Dimensions.x, height), content, m_Style[index]);
GUI.DrawTexture(new Rect(0, runningHeight, 32f, 32f), message.icon);
//TODO - cleanup formatting issues and switch to HelpBox
//EditorGUI.HelpBox(new Rect(0, runningHeight, m_dimensions.x, height), message.message, (MessageType)message.severity);
counter++;
runningHeight += height;
}
GUI.EndScrollView();
}
19
View Source File : PIAEditorWindow.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
private void DrawLayers(Rect verticalParent) {
Vector2 offset = new Vector2(10, 20);
// INIT LAYER RECT
float layerRectPositionX = verticalParent.x + offset.x;
float layerRectPositionY = verticalParent.yMax + offset.y;
float layerRectWidth = verticalParent.width-offset.x*2;
float layerRectHeight = 40;
float spaceBetweenLayers = 10;
// SCROLL VIEW STUFF
Rect viewRect = new Rect(layerRectPositionX, layerRectPositionY, layerRectWidth+ offset.x, (layerRectHeight + spaceBetweenLayers) * (PIASession.Instance.ImageData.Layers.Count + 1) + offset.y*2);
Rect sliderRect = new Rect(layerRectPositionX, layerRectPositionY, layerRectWidth+offset.x, leftSide.GetRect().height - verticalParent.height - offset.y);
// caching and changing default gui skins for scroll view
GUIStyle nativeVerticalScrollbarThumb = GUI.skin.verticalScrollbarThumb;
GUI.skin.verticalScrollbarThumb.normal.background = PIATextureDatabase.Instance.GetTexture("empty");
GUIStyle nativeVerticalScrollbarDownButton = GUI.skin.verticalScrollbarDownButton;
GUI.skin.verticalScrollbarDownButton.normal.background = PIATextureDatabase.Instance.GetTexture("empty");
GUIStyle nativeVerticalScrollbarUpButton = GUI.skin.verticalScrollbarUpButton;
GUI.skin.verticalScrollbarUpButton.normal.background = PIATextureDatabase.Instance.GetTexture("empty");
// DRAWING LAYERS
layersSlider = GUI.BeginScrollView(sliderRect, layersSlider, viewRect, false, false, skin.GetStyle("horizontalscrollbar"), skin.GetStyle("verticalscrollbar"));
{
for (int i = 0; i < PIASession.Instance.ImageData.Layers.Count; i++)
{
var item = PIASession.Instance.ImageData.Layers[i];
Rect layerRect = new Rect(layerRectPositionX, layerRectPositionY, layerRectWidth, layerRectHeight);
GUI.DrawTexture(layerRect, blackBarBG);
GUILayout.BeginArea(layerRect);
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
{
// LABEL
GUILayout.BeginVertical();
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
{
GUILayout.Space(15);
GUILayout.Label(item.Name, skin.GetStyle("editorbutton2"));
GUILayout.FlexibleSpace();
}
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
GUILayout.EndVertical();
// EYE & DELETE & TOOLTIP
GUILayout.BeginVertical();
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
{
item.Hidden = GUILayout.Toggle(item.Hidden, GUIContent.none, skin.GetStyle("layereye"), GUILayout.MaxWidth(30), GUILayout.MaxHeight(30));
Rect layerEyeGlobalRect = PIATooltipUtility.ChildToGlobalRect(GUILayoutUtility.GetLastRect(), layerRect, new Rect(-5, 40, 1, 1));
Rect layerEyeTooltipRect = new Rect(0, 0, 150, 22.5f);
PIATooltip layerEyeTooltip = new PIATooltip(layerEyeTooltipRect, "Show layer On / Off");
PIATooltip.SetPositionPreset(ref layerEyeTooltip, layerEyeGlobalRect, PIATooltip.PIATooltipPreset.Down);
PIATooltipUtility.AddTooltip(layerEyeGlobalRect, layerEyeTooltip);
GUILayout.Space(5);
if (i != 0)
{
if (GUILayout.Button(GUIContent.none, skin.GetStyle("deletelayer"), GUILayout.MaxWidth(30), GUILayout.MaxHeight(30)))
{
PIASession.Instance.ImageData.RemoveLayer(i);
return;
}
Rect deleteLayerGlobalRect = PIATooltipUtility.ChildToGlobalRect(GUILayoutUtility.GetLastRect(), layerRect, new Rect(-5, 40, 1, 1));
Rect deleteLayerTooltipRect = new Rect(0, 0, 50, 22.5f);
PIATooltip deleteLayerTooltip = new PIATooltip(deleteLayerTooltipRect, "Delete");
PIATooltip.SetPositionPreset(ref deleteLayerTooltip, deleteLayerGlobalRect, PIATooltip.PIATooltipPreset.Down);
PIATooltipUtility.AddTooltip(deleteLayerGlobalRect, deleteLayerTooltip);
}
GUILayout.Space(5);
}
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
GUILayout.EndArea();
// LAYER SELECTION BUTTON
if (GUI.Button(layerRect, GUIContent.none, skin.GetStyle("bglayerbutton")))
{
PIASession.Instance.ImageData.CurrentLayer = i;
}
layerRectPositionY += layerRectHeight + spaceBetweenLayers;
// SELECTED LAYER OVERLAY
if (i == PIASession.Instance.ImageData.CurrentLayer)
{
GUI.Label(layerRect, GUIContent.none, skin.GetStyle("selectedlayeroverlay"));
}
PIASession.Instance.ImageData.Layers[i] = item;
}
// ADD LAYER
Rect addLayerRect = new Rect(layerRectPositionX, layerRectPositionY, layerRectWidth, layerRectHeight);
GUI.DrawTexture(addLayerRect, blackBarBG);
GUILayout.BeginArea(addLayerRect);
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
{
// ICON
GUILayout.BeginVertical();
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
{
GUILayout.Space(15);
GUILayout.Label("", skin.GetStyle("addlayerlabelicon"), GUILayout.MaxWidth(30), GUILayout.MaxHeight(30));
}
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
GUILayout.EndVertical();
// LABEL
GUILayout.BeginVertical();
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
{
GUILayout.Space(15);
GUILayout.Label("Add layer", skin.GetStyle("editorbutton2"));
GUILayout.FlexibleSpace();
}
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
GUILayout.EndArea();
// ADD LAYER BUTTON
if (GUI.Button(addLayerRect, "", skin.GetStyle("bglayerbutton")))
{
PIASession.Instance.ImageData.AddLayer();
}
}
GUI.EndScrollView();
// resetting scroll view gui skin
GUI.skin.verticalScrollbarThumb = nativeVerticalScrollbarThumb;
GUI.skin.verticalScrollbarDownButton = nativeVerticalScrollbarDownButton;
GUI.skin.verticalScrollbarUpButton = nativeVerticalScrollbarUpButton;
}
19
View Source File : PIAEditorWindow.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
private void DrawFrames(Rect parent)
{
PIAImageData imageData = PIASession.Instance.ImageData;
Vector2 offset = new Vector2(20, 20);
Vector2 bgSize = new Vector2(15, 15);
// FRAME RECT
float frameRectPositionX = offset.x;
float frameRectPositionY = offset.y;
float frameRectWidth = 100;
float frameRectHeight = frameRectWidth;
float spaceBetweenFrames = 25;
// FRAME INDEX RECT
float frameNumberRectWidth = 22;
float frameNumberRectHeight = 22;
// DELETE RECT
float deleteFrameRectWidth = 32;
float deleteFrameRectHeight = 32;
Vector2 deleteFrameRectOffset = new Vector2(2, 2);
// DUPLICATE RECT
float duplicateFrameRectWidth = 32;
float duplicateFrameRectHeight = 32;
Vector2 duplicateFrameRectOffset = new Vector2(2, 2);
// MOVE UP RECT
float moveFrameUpRectWidth = 32;
float moveFrameUpRectHeight = 32;
Vector2 moveFrameUpRectOffset = new Vector2(2, 2);
// MOVE DOWN RECT
float moveFrameDownRectWidth = 32;
float moveFrameDownRectHeight = 32;
Vector2 moveFrameDownRectOffset = new Vector2(2, 2);
// ADD FRAME RECT
float addFrameIconRectWidth = 40;
float addFrameIconRectHeight = 40;
// SCROLL VIEW RECT
Rect viewRect = new Rect(0, 0, parent.width, (frameRectHeight+spaceBetweenFrames) * (imageData.Frames.Count+1)+offset.y);
Rect sliderRect = new Rect(0, 0, parent.width, parent.height-offset.y);
// caching and changing default gui skins for scroll view
GUIStyle nativeVerticalScrollbarThumb = GUI.skin.verticalScrollbarThumb;
GUI.skin.verticalScrollbarThumb.normal.background = PIATextureDatabase.Instance.GetTexture("empty");
GUIStyle nativeVerticalScrollbarDownButton = GUI.skin.verticalScrollbarDownButton;
GUI.skin.verticalScrollbarDownButton.normal.background = PIATextureDatabase.Instance.GetTexture("empty");
GUIStyle nativeVerticalScrollbarUpButton = GUI.skin.verticalScrollbarUpButton;
GUI.skin.verticalScrollbarUpButton.normal.background = PIATextureDatabase.Instance.GetTexture("empty");
// DRAWING FRAMES
framesSlider = GUI.BeginScrollView(sliderRect, framesSlider,viewRect,false,false,skin.GetStyle("horizontalscrollbar"),skin.GetStyle("verticalscrollbar"));
{
for (int i = 0; i < imageData.Frames.Count; i++)
{
var item = imageData.Frames[i];
// refreshing rects
Rect frameRect = new Rect(frameRectPositionX, frameRectPositionY, frameRectWidth, frameRectHeight);
Rect frameBGRect = new Rect(frameRect.x - bgSize.x / 2, frameRect.y - bgSize.y / 2, frameRect.width + bgSize.x,
frameRect.height + bgSize.y);
Rect frameNumberBGRect = new Rect(frameBGRect.xMax, frameBGRect.center.y - frameNumberRectHeight / 2, frameNumberRectWidth, frameNumberRectHeight);
Rect deleteFrameRect = new Rect(frameRect.xMax - deleteFrameRectWidth - deleteFrameRectOffset.x,
frameRect.y + deleteFrameRectOffset.y, deleteFrameRectWidth, deleteFrameRectHeight);
Rect duplicateFrameRect = new Rect(frameRect.xMax - duplicateFrameRectWidth - duplicateFrameRectOffset.x,
frameRect.yMax - duplicateFrameRectOffset.y - duplicateFrameRectHeight, duplicateFrameRectWidth, duplicateFrameRectHeight);
Rect moveFrameUpFrameRect = new Rect(frameRect.x + moveFrameUpRectOffset.x,
frameRect.y + moveFrameUpRectOffset.y , moveFrameUpRectWidth, moveFrameUpRectHeight);
Rect moveFrameDownFrameRect = new Rect(frameRect.x + moveFrameDownRectOffset.x,
frameRect.yMax - moveFrameDownRectOffset.y - moveFrameDownRectHeight, moveFrameDownRectWidth, moveFrameDownRectHeight);
// INDEX NUMBER
GUI.DrawTexture(frameNumberBGRect, blackBarBG);
GUI.Label(frameNumberBGRect, i.ToString(), skin.GetStyle("editorbutton2"));
// BG
GUI.DrawTexture(frameBGRect, blackBarBG);
// FRAME CONTENT
EditorGUI.DrawTextureTransparent(frameRect, imageData.Frames[i].GetFrameTexture());
if (PIAInputArea.IsMouseInsideRect(frameBGRect))
{
if (imageData.Frames.Count > 1)
{
// DELETE
if (GUI.Button(deleteFrameRect, GUIContent.none, skin.GetStyle("deleteframe")))
{
PIASession.Instance.ImageData.RemoveFrame(i);
}
Rect deleteFrameGlobalRect = PIATooltipUtility.ChildToGlobalRect(deleteFrameRect,parent);
Rect deleteFrameTooltipRect = new Rect(0, 0, 50, 22.5f);
PIATooltip deleteFrameTooltip = new PIATooltip(deleteFrameTooltipRect, "Delete");
PIATooltip.SetPositionPreset(ref deleteFrameTooltip, deleteFrameGlobalRect, PIATooltip.PIATooltipPreset.Right);
PIATooltipUtility.AddTooltip(deleteFrameGlobalRect, deleteFrameTooltip);
}
// DUPLICATE
if (GUI.Button(duplicateFrameRect, GUIContent.none, skin.GetStyle("copyframe")))
{
PIAFrame newFrame = PIASession.Instance.ImageData.AddFrame();
newFrame.CopyFrom(item);
}
Rect duplicateFrameGlobalRect = PIATooltipUtility.ChildToGlobalRect(duplicateFrameRect, parent);
Rect duplicateFrameTooltipRect = new Rect(0, 0, 75, 22.5f);
PIATooltip duplicateFrameTooltip = new PIATooltip(duplicateFrameTooltipRect, "Duplicate");
PIATooltip.SetPositionPreset(ref duplicateFrameTooltip, duplicateFrameGlobalRect, PIATooltip.PIATooltipPreset.Up);
PIATooltipUtility.AddTooltip(duplicateFrameGlobalRect, duplicateFrameTooltip);
// MOVE UP
if (i > 0) {
if (GUI.Button(moveFrameUpFrameRect, GUIContent.none, skin.GetStyle("moveframup")))
{
imageData.MoveFrameUp(i);
}
Rect moveFrameUpGlobalRect = PIATooltipUtility.ChildToGlobalRect(moveFrameUpFrameRect, parent);
Rect moveFrameUpTooltipRect = new Rect(0, 0, 75, 22.5f);
PIATooltip moveFrameUpTooltip = new PIATooltip(moveFrameUpTooltipRect, "Move up");
PIATooltip.SetPositionPreset(ref moveFrameUpTooltip, moveFrameUpGlobalRect, PIATooltip.PIATooltipPreset.Left);
PIATooltipUtility.AddTooltip(moveFrameUpGlobalRect, moveFrameUpTooltip);
}
// MOVE DOWN
if (i < imageData.Frames.Count - 1) {
if (GUI.Button(moveFrameDownFrameRect, GUIContent.none, skin.GetStyle("moveframedown")))
{
imageData.MoveFrameDown(i);
}
Rect moveFrameDownGlobalRect = PIATooltipUtility.ChildToGlobalRect(moveFrameDownFrameRect,parent);
Rect moveFrameDownTooltipRect = new Rect(0, 0, 90, 22.5f);
PIATooltip moveFrameDownTooltip = new PIATooltip(moveFrameDownTooltipRect, "Move down");
PIATooltip.SetPositionPreset(ref moveFrameDownTooltip, moveFrameDownGlobalRect, PIATooltip.PIATooltipPreset.Left);
PIATooltipUtility.AddTooltip(moveFrameDownGlobalRect, moveFrameDownTooltip);
}
}
// FRAME SELECTION BG
if (GUI.Button(frameBGRect, GUIContent.none, skin.GetStyle("bglayerbutton")))
{
PIASession.Instance.ImageData.CurrentFrameIndex = i;
}
frameRectPositionY += frameRectHeight + spaceBetweenFrames;
// FRAME SELECTION OVERLAY
if (i == PIASession.Instance.ImageData.CurrentFrameIndex)
{
GUI.Label(frameBGRect, GUIContent.none, skin.GetStyle("selectedframeoverlay"));
}
}
// ADD NEW FRAME
Rect addFrameRect = new Rect(frameRectPositionX, frameRectPositionY, frameRectWidth, frameRectHeight);
Rect addFrameBGRect = new Rect(addFrameRect.x - bgSize.x / 2, addFrameRect.y - bgSize.y / 2, addFrameRect.width + bgSize.x,
addFrameRect.height + bgSize.y);
Rect addFrameBGLabelIcon = new Rect(addFrameRect.center.x - addFrameIconRectWidth / 2, addFrameRect.center.y - addFrameIconRectHeight / 2, addFrameIconRectWidth, addFrameIconRectHeight);
GUI.DrawTexture(addFrameBGRect, blackBarBG);
GUI.Label(addFrameBGLabelIcon, GUIContent.none, skin.GetStyle("addframe"));
if (GUI.Button(addFrameRect, GUIContent.none, skin.GetStyle("bglayerbutton")))
{
PIASession.Instance.ImageData.AddFrame();
}
frameRectPositionY += frameRectHeight + spaceBetweenFrames;
}
GUI.EndScrollView();
// resetting scroll view gui skin
GUI.skin.verticalScrollbarThumb = nativeVerticalScrollbarThumb;
GUI.skin.verticalScrollbarDownButton = nativeVerticalScrollbarDownButton;
GUI.skin.verticalScrollbarUpButton = nativeVerticalScrollbarUpButton;
}
19
View Source File : ComboBox.cs
License : GNU General Public License v3.0
Project Creator : ManlyMarco
License : GNU General Public License v3.0
Project Creator : ManlyMarco
public void Show(Action<int> onItemSelected)
{
if (forceToUnShow)
{
forceToUnShow = false;
isClickedComboButton = false;
}
var done = false;
var controlID = GUIUtility.GetControlID(FocusType.Preplacedive);
Vector2 currentMousePosition = Vector2.zero;
if (Event.current.GetTypeForControl(controlID) == EventType.mouseUp)
{
if (isClickedComboButton)
{
done = true;
currentMousePosition = Event.current.mousePosition;
}
}
if (GUI.Button(Rect, ButtonContent, buttonStyle))
{
if (useControlID == -1)
{
useControlID = controlID;
isClickedComboButton = false;
}
if (useControlID != controlID)
{
forceToUnShow = true;
useControlID = controlID;
}
isClickedComboButton = true;
}
if (isClickedComboButton)
{
GUI.enabled = false;
GUI.color = new Color(1, 1, 1, 2);
var location = GUIUtility.GUIToScreenPoint(new Vector2(Rect.x, Rect.y + listStyle.CalcHeight(listContent[0], 1.0f)));
var size = new Vector2(Rect.width, listStyle.CalcHeight(listContent[0], 1.0f) * listContent.Length);
var innerRect = new Rect(0, 0, size.x, size.y);
var outerRectScreen = new Rect(location.x, location.y, size.x, size.y);
if (outerRectScreen.yMax > _windowYmax)
{
outerRectScreen.height = _windowYmax - outerRectScreen.y;
outerRectScreen.width += 20;
}
if (currentMousePosition != Vector2.zero && outerRectScreen.Contains(GUIUtility.GUIToScreenPoint(currentMousePosition)))
done = false;
CurrentDropdownDrawer = () =>
{
GUI.enabled = true;
var outerRectLocal = GUIUtility.ScreenToGUIRect(outerRectScreen);
GUI.Box(outerRectLocal, GUIContent.none, GUI.skin.box);
_scrollPosition = GUI.BeginScrollView(outerRectLocal, _scrollPosition, innerRect, false, false);
{
const int initialSelectedItem = -1;
var newSelectedItemIndex = GUI.SelectionGrid(innerRect, initialSelectedItem, listContent, 1, listStyle);
if (newSelectedItemIndex != initialSelectedItem)
{
onItemSelected(newSelectedItemIndex);
isClickedComboButton = false;
}
}
GUI.EndScrollView(true);
};
}
if (done)
isClickedComboButton = false;
}
19
View Source File : DeveloperConsole.cs
License : MIT License
Project Creator : mustafayaya
License : MIT License
Project Creator : mustafayaya
void ConsoleWindow(int windowID)
{
printLogs = GUI.Toggle(new Rect(10, 5, 10, 10), printLogs, "", skin.GetStyle("logButton"));
printWarnings = GUI.Toggle(new Rect(25, 5, 10, 10), printWarnings, "", skin.GetStyle("warningButton"));
printErrors = GUI.Toggle(new Rect(40, 5, 10, 10), printErrors, "", skin.GetStyle("errorButton"));
printNetwork = GUI.Toggle(new Rect(55, 5, 10, 10), printNetwork, "", skin.GetStyle("networkButton"));
if (GUI.Button(new Rect(windowRect.width - 25, 7, 15, 5), "-", skin.GetStyle("exitButton")))
{
_active = !_active;
}
if (Event.current.keyCode == KeyCode.UpArrow && Event.current.type == EventType.KeyDown)
{
if (GUI.GetNameOfFocusedControl() == "consoleInputField")
{
InputHistoryHandler();
FocusOnInputField(false);
}
}
#if UNITY_STANDALONE
GUI.SetNextControlName("dragHandle");
GUI.DragWindow(new Rect(0, 0, windowRect.width, 20));//Draw drag handle of window
#endif
int scrollHeight = 0;
GUI.SetNextControlName("outputBox");
GUI.Box(new Rect(20, 20, windowRect.width - 40, windowRect.height - 85), "", skin.box);//Draw console window box
GUI.SetNextControlName("consoleInputField");
Rect inputFieldRect = new Rect(20, windowRect.height - 45, windowRect.width - 160, 25);
Widgets.Instance.DrawCommandHints(inputFieldRect, skin.GetStyle("hint"));
input = GUI.TextField(inputFieldRect, input, inputLimit, skin.textField);
foreach (ConsoleOutput c in consoleOutputs)
{
scrollHeight += c.lines * lineSpacing;
}
scrollPosition = GUI.BeginScrollView(new Rect(20, 20, windowRect.width - 40, windowRect.height - 85), scrollPosition, new Rect(20, 20, windowRect.width - 60, scrollHeight));
if (scrollDownTrigger)
{
scrollPosition = new Vector2(scrollPosition.x, scrollHeight);
scrollDownTrigger = false;
}
GUI.SetNextControlName("textArea");
DrawOutput();
GUI.EndScrollView();
GUI.SetNextControlName("submitButton");
if (GUI.Button(new Rect(windowRect.width - 130, windowRect.height - 45, 80, 25), "Submit", skin.button))
{
if (!String.IsNullOrEmpty(input))
{
SubmitInput(input);
scrollPosition = new Vector2(scrollPosition.x, consoleOutputs.Count * 40);
}
}
if (inputFocusTrigger)
{
FocusOnInputField(false);
}
if (!String.IsNullOrEmpty(input) && Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyUp)
{
if (GUI.GetNameOfFocusedControl() == "consoleInputField" || GUI.GetNameOfFocusedControl() == "")
{
if (inputFocusTrigger)
{
inputFocusTrigger = false;
}
else
{
SubmitInput(input);
}
}
}
GUI.SetNextControlName("clearButton");
if (GUI.Button(new Rect(windowRect.width - 40, windowRect.height - 45, 20, 25), "X", skin.button))
{
consoleOutputs.Clear();
inputHistory.Clear();
scrollPosition = new Vector2(scrollPosition.x, consoleOutputs.Count * 20);
}
if (String.IsNullOrEmpty(input) && Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyUp)
{
GUI.FocusControl("consoleInputField");
}
if (GUI.GetNameOfFocusedControl() == "" && submitFocusTrigger)
{
GUI.FocusControl("consoleInputField");
submitFocusTrigger = false;
}
GUI.Box(new Rect(windowRect.width - 15, windowRect.height - 15, 10, 10), "", skin.GetStyle("corner"));
WindowResizeHandler();
}
19
View Source File : MessageList.cs
License : GNU Lesser General Public License v3.0
Project Creator : pepeizq
License : GNU Lesser General Public License v3.0
Project Creator : pepeizq
internal void OnGUI(Rect fullPos)
{
DrawOutline(fullPos, 1f);
Rect pos = new Rect(fullPos.x + k_BorderSize, fullPos.y + k_BorderSize, fullPos.width - 2 * k_BorderSize, fullPos.height - 2 * k_BorderSize);
if (m_Dimensions.y == 0 || m_Dimensions.x != pos.width - k_ScrollbarPadding)
{
//recalculate height.
m_Dimensions.x = pos.width - k_ScrollbarPadding;
m_Dimensions.y = 0;
foreach (var message in m_Messages)
{
m_Dimensions.y += m_Style[0].CalcHeight(new GUIContent(message.message), m_Dimensions.x);
}
}
m_ScrollPosition = GUI.BeginScrollView(pos, m_ScrollPosition, new Rect(0, 0, m_Dimensions.x, m_Dimensions.y));
int counter = 0;
float runningHeight = 0.0f;
foreach (var message in m_Messages)
{
int index = counter % 2;
var content = new GUIContent(message.message);
float height = m_Style[index].CalcHeight(content, m_Dimensions.x);
GUI.Box(new Rect(0, runningHeight, m_Dimensions.x, height), content, m_Style[index]);
GUI.DrawTexture(new Rect(0, runningHeight, 32f, 32f), message.icon);
//TODO - cleanup formatting issues and switch to HelpBox
//EditorGUI.HelpBox(new Rect(0, runningHeight, m_dimensions.x, height), message.message, (MessageType)message.severity);
counter++;
runningHeight += height;
}
GUI.EndScrollView();
}
19
View Source File : Menu.cs
License : MIT License
Project Creator : ThePotato97
License : MIT License
Project Creator : ThePotato97
private static void spawnItemMenu()
{
if (showItemList)
{
string[] allitems = Constants.allitems;
GUI.Label(new Rect(520f, 225f, 200f, 20f), "Item Spawner:");
scrollViewVector = GUI.BeginScrollView(new Rect(dropDownRect2.x - 100f, dropDownRect2.y + 25f, dropDownRect2.width, dropDownRect2.height), scrollViewVector, new Rect(0f, 0f, dropDownRect2.width, Mathf.Max(dropDownRect2.height, (float)(allitems.Length * 25))));
GUI.Box(new Rect(0f, 0f, dropDownRect2.width, Mathf.Max(dropDownRect2.height, (float)(allitems.Length * 25))), "");
for (int l = 0; l < allitems.Length; l++)
{
if (GUI.Button(new Rect(0f, (float)(l * 25), dropDownRect2.height, 25f), ""))
{
selectedItem = l;
if (PhotonNetwork.InRoom)
{
MyPlayer = Main.GetLocalPlayer();
MelonLogger.Log(allitems[selectedItem].ToString());
PhotonNetwork.Instantiate(allitems[selectedItem], MyPlayer.transform.position, Quaternion.idenreplacedy, 0, null);
}
}
GUI.Label(new Rect(5f, (float)(l * 25), dropDownRect2.height, 25f), allitems[l]);
}
GUI.EndScrollView();
}
}
19
View Source File : BasePopupWindowContent.cs
License : GNU General Public License v3.0
Project Creator : thiagosoara
License : GNU General Public License v3.0
Project Creator : thiagosoara
private void DrawSelectionArea(Rect scrollRect)
{
Rect contentRect = new Rect(0, 0,
scrollRect.width - GUI.skin.verticalScrollbar.fixedWidth,
visibleItems.Count * ROW_HEIGHT);
scroll = GUI.BeginScrollView(scrollRect, scroll, contentRect);
Rect rowRect = new Rect(0, 0, scrollRect.width, ROW_HEIGHT);
for (int i = 0; i < visibleItems.Count; i++)
{
if (scrollToIndex == i &&
(Event.current.type == EventType.Repaint
|| Event.current.type == EventType.Layout))
{
Rect r = new Rect(rowRect);
r.y += scrollOffset;
GUI.ScrollTo(r);
scrollToIndex = -1;
scroll.x = 0;
}
if (rowRect.Contains(Event.current.mousePosition))
{
if (Event.current.type == EventType.MouseMove ||
Event.current.type == EventType.ScrollWheel)
{
//if new item force update so it's snappier
if (hoverIndex != 1)
{
this.editorWindow.Repaint();
}
hoverIndex = i;
}
if (Event.current.type == EventType.MouseDown)
{
//onSelectionMade(list.Entries[i].Index);
SelectByOrigIndex(visibleItems[i].origIndex);
EditorWindow.focusedWindow.Close();
}
}
DrawRow(rowRect, i);
rowRect.y = rowRect.yMax;
}
GUI.EndScrollView();
}
19
View Source File : ConsoleWindow.cs
License : GNU General Public License v3.0
Project Creator : veesusmikelheir
License : GNU General Public License v3.0
Project Creator : veesusmikelheir
private void DrawWindow(int id)
{
int bFontSize = GUI.skin.button.fontSize;
int tfFontSize = GUI.skin.textField.fontSize;
int tFontSize = GUI.skin.toggle.fontSize;
int lFontSize = GUI.skin.label.fontSize;
GUI.skin.button.fontSize = consoleFont.fontSize;
GUI.skin.textField.fontSize = consoleFont.fontSize;
GUI.skin.toggle.fontSize = consoleFont.fontSize;
GUI.skin.label.fontSize = consoleFont.fontSize;
if (cachedAC.Count == 0)
{
autoComplete = false;
}
// LISTENING TO THE KEY EVENTS
if (Event.current.isKey && Event.current.type == EventType.KeyDown)
{
if (Event.current.keyCode == KeyCode.Escape && autoComplete)
{
forceClose = true;
autoComplete = false;
Event.current.Use();
return;
}
else if (Event.current.keyCode == KeyCode.Escape && !autoComplete)
{
SetWindowOff();
Event.current.Use();
return;
}
// SUBMITS THE TEXTFIELD
if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
{
Console.ProcessInput(cmdText.TrimEnd(' '));
cmdText = string.Empty;
oldCmdText = null;
currHistory = -1;
completeIndex = 0;
autoComplete = false;
Event.current.Use();
return;
}
// AUTO COMPLETE TOGGLE
if ((Event.current.modifiers == EventModifiers.Control || Event.current.modifiers == EventModifiers.Command) && Event.current.keyCode == KeyCode.Space)
{
forceClose = false;
if (Regex.Matches(cmdText, "\"").Count % 2 == 0)
autoComplete = true;
justActivated = true;
oldCmdText = null;
Event.current.Use();
return;
}
// TAB AUTO COMPLETE
if (Event.current.keyCode == KeyCode.Tab && Event.current.modifiers == EventModifiers.None && autoComplete)
{
if (!selectComplete.Equals(string.Empty))
{
cmdText = selectComplete;
selectComplete = string.Empty;
moveCursor = true;
autoComplete = false;
}
Event.current.Use();
return;
}
// CYCLES HISTORY UP
if (Event.current.keyCode == KeyCode.UpArrow && !autoComplete && Console.history.Count > 0)
{
if (currHistory == -1)
{
cmdText = Console.history[Console.history.Count - 1];
currHistory = Console.history.Count - 1;
}
else
{
if (currHistory > 0)
{
cmdText = Console.history[currHistory - 1];
currHistory -= 1;
}
}
moveCursor = true;
Event.current.Use();
return;
}
else if (Event.current.keyCode == KeyCode.UpArrow && autoComplete)
{
completeIndex--;
if (completeIndex < 0)
completeIndex = cachedAC.Count - 1;
aCompleteScroll.y = (25 * completeIndex) + 5;
Event.current.Use();
return;
}
// CYCLES HISTORY DOWN
if (Event.current.keyCode == KeyCode.DownArrow && !autoComplete && Console.history.Count > 0)
{
if (currHistory != -1)
{
if (currHistory < (Console.history.Count - 1))
{
cmdText = Console.history[currHistory + 1];
currHistory += 1;
}
else
{
cmdText = string.Empty;
currHistory = -1;
}
}
moveCursor = true;
Event.current.Use();
return;
}
else if (Event.current.keyCode == KeyCode.DownArrow && autoComplete)
{
completeIndex++;
if (completeIndex > cachedAC.Count - 1)
completeIndex = 0;
aCompleteScroll.y = (25 * completeIndex) + 5;
Event.current.Use();
return;
}
// TRIGGER AUTO COMPLETE
if (autoAC && Event.current.keyCode != KeyCode.None && Event.current.keyCode != KeyCode.Space && Event.current.keyCode != KeyCode.Escape && (!cmdText.Equals(oldCmdText) || cmdText.Equals(string.Empty)) && (Event.current.modifiers == EventModifiers.None || Event.current.modifiers == EventModifiers.Shift))
{
if (cmdText.Equals(string.Empty))
forceClose = false;
autoComplete = !forceClose;
}
// FIXES SPACE && BACKSPACE
if (autoAC && (Event.current.keyCode == KeyCode.Space) && Event.current.modifiers == EventModifiers.None)
{
if (Regex.Matches(cmdText, "\"").Count % 2 == 0)
forceClose = false;
if (!forceClose)
autoComplete = true;
}
}
// CONSOLE AREA
GUI.BeginGroup(leftGroup);
GUI.SetNextControlName(cmdName);
cmdText = GUI.TextField(cmdRect, cmdText);
if (cmdText.EndsWith(" ") && justActivated)
{
cmdText = cmdText.TrimEnd(' ');
oldCmdText = null;
justActivated = false;
}
if (!focus)
{
focus = true;
GUI.FocusControl(cmdName);
}
textArea.wordWrap = false;
textArea.clipping = TextClipping.Clip;
textArea.richText = true;
textArea.padding = new RectOffset(5, 5, 5, 5);
textArea.font = consoleFont;
tRect.width = TextSize.x;
tRect.height = TextSize.y;
GUI.BeginGroup(oRect, GUI.skin.textArea);
consoleScroll = GUI.BeginScrollView(sRect, consoleScroll, tRect, false, true);
GUI.Label(tRect, FullContent, textArea);
GUI.EndScrollView();
GUI.EndGroup();
GUI.EndGroup();
// MENU AREA
GUI.BeginGroup(rightGroupA, GUI.skin.textArea);
GUI.skin.button.fontStyle = FontStyle.Bold;
if (GUI.Button(ulRect, openUnityLog))
System.Diagnostics.Process.Start(Console.unityLogFile);
if (GUI.Button(slRect, openSRMLLog))
System.Diagnostics.Process.Start(Console.srmlLogFile);
autoAC = GUI.Toggle(tacRect, autoAC, toggleAutoAC);
if (autoAC != oldAutoAC)
{
if (autoAC)
{
Console.LogSuccess("Auto complete will now open automatically.");
}
else
{
Console.LogSuccess("Auto complete will only open by pressing CTRL+Space or CMD+Space");
}
oldAutoAC = autoAC;
}
GUI.EndGroup();
GUI.BeginGroup(rightGroupB, GUI.skin.textArea);
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.Label(cmRect, commands);
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
caRect.height = (30 * Console.cmdButtons.Count) + 5;
commandScroll = GUI.BeginScrollView(csRect, commandScroll, caRect, false, true);
GUI.BeginGroup(caRect);
int y = 5;
foreach (ConsoleButton button in Console.cmdButtons.Values)
{
btnRect.y = y;
if (GUI.Button(btnRect, button.Text))
Console.ProcessInput(button.Command.TrimEnd(' '), true);
y += 30;
}
GUI.EndGroup();
GUI.EndScrollView();
GUI.skin.button.fontStyle = FontStyle.Normal;
GUI.EndGroup();
// UPDATES THE SCROLL POSITION FOR THE CONSOLE TO SHOW LATEST MESSAGES
if (updateDisplay)
{
fullText = string.Empty;
for (int i = 0; i < Console.lines.Count; i++)
{
fullText += $"{(i == 0 ? string.Empty : "\n")}{Console.lines[i]}";
}
consoleScroll.y = TextSize.y;
updateDisplay = false;
}
// MOVES THE CURSOR AFTER AUTO COMPLETE
if (moveCursor)
{
TextEditor txt = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
txt.MoveCursorToPosition(Vector2.one * 50000);
autoComplete = false;
moveCursor = false;
}
if (cmdText.Equals(string.Empty) && currHistory > -1)
currHistory = -1;
GUI.skin.button.fontSize = bFontSize;
GUI.skin.textField.fontSize = tfFontSize;
GUI.skin.toggle.fontSize = tFontSize;
GUI.skin.label.fontSize = lFontSize;
}
19
View Source File : ConsoleWindow.cs
License : GNU General Public License v3.0
Project Creator : veesusmikelheir
License : GNU General Public License v3.0
Project Creator : veesusmikelheir
private void DrawACWindow(int id)
{
int bFontSize = GUI.skin.button.fontSize;
GUI.skin.button.fontSize = consoleFont.fontSize;
bool spaces = cmdText.Contains(" ");
string command = spaces ? cmdText.Substring(0, cmdText.IndexOf(' ')) : cmdText;
TextEditor txt = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
if (txt.hreplacedelection)
command = string.Empty;
intRect.height = (25 * cachedAC.Count) + 5;
aCompleteScroll = GUI.BeginScrollView(acsRect, aCompleteScroll, intRect, false, true);
GUI.BeginGroup(intRect);
Texture2D bg = GUI.skin.textField.normal.background;
GUI.skin.textField.normal.background = GUI.skin.button.active.background;
GUI.skin.textField.richText = true;
if (!spaces || txt.hreplacedelection)
{
if (!command.Equals(oldCmdText))
{
cachedAC.RemoveAll(s => true); // .Clear() gets broken sometimes when you dynamically load an replacedembly, so do the same another way
foreach (string cmd in Console.commands.Keys)
{
if (cmd.ToLowerInvariant().StartsWith(command.ToLowerInvariant()))
cachedAC.Add(cmd);
}
oldCmdText = command;
}
if (cachedAC.Count > 0)
{
if (completeIndex >= cachedAC.Count)
completeIndex = 0;
selectComplete = cmdText.Substring(0, cmdText.Length - command.Length) + cachedAC[completeIndex];
int y = 5;
for (int i = 0; i < cachedAC.Count; i++)
{
GUI.backgroundColor = Color.white;
if (completeIndex == i)
GUI.backgroundColor = Color.yellow;
cBtnRect.y = y;
if (GUI.Button(cBtnRect, $"{(completeIndex == i ? "►" : string.Empty)}<b><color=#77DDFF>{cachedAC[i].Substring(0, command.Length)}</color></b>{cachedAC[i].Substring(command.Length)}", GUI.skin.textField))
{
cmdText = cmdText.Substring(0, cmdText.Length - command.Length) + cachedAC[i];
GUI.FocusControl(cmdName);
moveCursor = true;
autoComplete = false;
}
y += 25;
}
}
}
else
{
string[] args = Console.StripArgs(cmdText, true);
int count = args.Length;
string lastArg = args[count - 1];
if (Console.commands.ContainsKey(command))
{
List<string> autoC = Console.commands[command].GetAutoComplete(count - 1, lastArg);
autoC?.RemoveAll(s => s.Contains(" "));
if (autoC == null || autoC.Count == 0 || Regex.Matches(cmdText, "\"").Count % 2 != 0)
autoComplete = false;
if (autoComplete)
{
if (!cmdText.Equals(oldCmdText))
{
cachedAC.RemoveAll(s => true); // .Clear() gets broken sometimes when you dynamically load an replacedembly, so do the same another way
foreach (string cmd in autoC)
{
if (cmd.ToLowerInvariant().StartsWith(lastArg.ToLowerInvariant()))
cachedAC.Add(cmd);
}
oldCmdText = cmdText;
}
if (cachedAC.Count > 0)
{
if (completeIndex >= cachedAC.Count)
completeIndex = 0;
selectComplete = cmdText.Substring(0, cmdText.Length - lastArg.Length) + cachedAC[completeIndex];
int y = 5;
for (int i = 0; i < cachedAC.Count; i++)
{
GUI.backgroundColor = Color.white;
if (completeIndex == i)
GUI.backgroundColor = Color.yellow;
cBtnRect.y = y;
if (GUI.Button(cBtnRect, $"{(completeIndex == i ? "►" : string.Empty)}<b><color=#77DDFF>{cachedAC[i].Substring(0, lastArg.Length)}</color></b>{cachedAC[i].Substring(lastArg.Length)}", GUI.skin.textField))
{
cmdText = cmdText.Substring(0, cmdText.Length - lastArg.Length) + cachedAC[i];
GUI.FocusControl(cmdName);
moveCursor = true;
autoComplete = false;
}
y += 25;
}
}
}
}
}
if (cachedAC.Count == 0)
autoComplete = false;
GUI.skin.textField.richText = false;
GUI.skin.textField.normal.background = bg;
GUI.EndGroup();
GUI.EndScrollView();
GUI.skin.button.fontSize = bFontSize;
}
19
View Source File : ConsoleWindow.cs
License : GNU General Public License v3.0
Project Creator : veesusmikelheir
License : GNU General Public License v3.0
Project Creator : veesusmikelheir
private void DrawWindow(int id)
{
Font defFont = GUI.skin.font;
GUI.skin.font = consoleFont;
Rect leftGroup = new Rect(15, 25, windowRect.width - 150, windowRect.height - 30);
Rect rightGroup = new Rect(leftGroup.width + 25, leftGroup.y, 110, leftGroup.height - 5);
// CONSOLE AREA
GUI.BeginGroup(leftGroup);
float cmdLineY = leftGroup.height - 25;
cmdText = GUI.TextField(new Rect(0, cmdLineY, leftGroup.width, 20), cmdText);
textArea.wordWrap = true;
textArea.clipping = TextClipping.Clip;
textArea.richText = true;
textArea.padding = new RectOffset(5, 5, 5, 5);
GUIContent fullContent = new GUIContent(fullText.ToString());
Vector2 textSize = textArea.CalcSize(fullContent);
Rect oRect = new Rect(0, 0, leftGroup.width, cmdLineY - 5);
Rect sRect = new Rect(5, 7, oRect.width - 15, cmdLineY - 20);
Rect tRect = new Rect(0, 0, textSize.x, textSize.y);
GUI.BeginGroup(oRect, GUI.skin.textArea);
consoleScroll = GUI.BeginScrollView(sRect, consoleScroll, tRect, false, true);
GUI.Label(tRect, fullContent, textArea);
GUI.EndScrollView();
GUI.EndGroup();
GUI.EndGroup();
// MENU AREA
GUI.BeginGroup(rightGroup, GUI.skin.textArea);
if (GUI.Button(new Rect(10, 7, 90, 25), openUnityLog))
System.Diagnostics.Process.Start(Console.unityLogFile);
if (GUI.Button(new Rect(10, 37, 90, 25), openSRMLLog))
System.Diagnostics.Process.Start(Console.srmlLogFile);
if (GUI.Button(new Rect(10, 67, 90, 25), runMods))
Console.ProcessInput("mods", true);
if (GUI.Button(new Rect(10, 97, 90, 25), runCommands))
Console.ProcessInput("help", true);
if (GUI.Button(new Rect(10, 127, 90, 25), runReload))
Console.ProcessInput("reload", true);
GUI.EndGroup();
// KEY LISTENING DONE HERE CAUSE UNITY COSUMES MOST KEY INPUTS WHEN A TEXTFIELD IS FOCUSED
if (Event.current.isKey)
{
// SUBMITS THE TEXTFIELD
if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
{
Console.ProcessInput(cmdText);
cmdText = string.Empty;
}
// CLOSES THE WINDOW
if ((Event.current.command || Event.current.control) && Event.current.keyCode == KeyCode.Tab && canPress)
ToggleWindow();
// CYCLES HISTORY UP
if (Event.current.keyCode == KeyCode.UpArrow)
{
if (currHistory == -1)
{
cmdText = Console.history[Console.history.Count - 1];
currHistory = Console.history.Count - 1;
}
else
{
if (currHistory > 0)
{
cmdText = Console.history[currHistory - 1];
currHistory = currHistory - 1;
}
}
}
// CYCLES HISTORY DOWN
if (Event.current.keyCode == KeyCode.DownArrow)
{
if (currHistory != -1)
{
if (currHistory < (Console.history.Count - 1))
{
cmdText = Console.history[currHistory + 1];
currHistory = currHistory + 1;
}
else
{
cmdText = "";
currHistory = -1;
}
}
}
}
// UPDATES THE SCROLL POSITION FOR THE CONSOLE TO SHOW LATEST MESSAGES
if (updateDisplay)
{
consoleScroll.y = textArea.CalcSize(new GUIContent(fullText.ToString())).y;
updateDisplay = false;
}
GUI.skin.font = defFont;
}
19
View Source File : SF_PassSettings.cs
License : MIT License
Project Creator : XINCGer
License : MIT License
Project Creator : XINCGer
public int OnLocalGUI( int yOffset, int in_maxWidth ) {
if(Event.current.type == EventType.Repaint)
currentScrollWidth = Mathf.Lerp(currentScrollWidth, targetScrollWidth, 0.3f);
this.maxWidth = in_maxWidth;
Rect scrollRectPos = new Rect(0f,yOffset,in_maxWidth,Screen.height/EditorGUIUtility.pixelsPerPoint-yOffset-20);
bool useScrollbar = (innerScrollRect.height > scrollRectPos.height);
targetScrollWidth = useScrollbar ? 15 : 0;
int scrollBarWidth = (int)currentScrollWidth;
innerScrollRect.width = in_maxWidth-scrollBarWidth;
guiChanged = false;
int offset = 0;
if(innerScrollRect.height < scrollRectPos.height)
innerScrollRect.height = scrollRectPos.height;
this.maxWidth -= scrollBarWidth;
int scrollPad = scrollBarWidth-15;
GUI.BeginGroup(scrollRectPos);
Rect scrollWrapper = scrollRectPos;
scrollWrapper.x = 0;
scrollWrapper.y = 0; // Since it's grouped
scrollPos = GUI.BeginScrollView(scrollWrapper.PadRight(scrollPad),scrollPos,innerScrollRect,false,true);
{
//offset = SettingsMeta( 0 );
bool showErrors = editor.nodeView.treeStatus.Errors.Count > 0;
if( !showErrors )
catConsole.expanded = false;
EditorGUI.BeginDisabledGroup( !showErrors );
offset = catConsole.Draw( offset );
offset = GUISeparator( offset ); // ----------------------------------------------
EditorGUI.EndDisabledGroup();
offset = catMeta.Draw( offset );
offset = GUISeparator( offset ); // ----------------------------------------------
offset = catProperties.Draw(offset);
offset = GUISeparator( offset ); // ----------------------------------------------
offset = catLighting.Draw(offset);
offset = GUISeparator( offset ); // ----------------------------------------------
offset = catGeometry.Draw( offset );
offset = GUISeparator( offset ); // ----------------------------------------------
offset = catBlending.Draw(offset);
offset = GUISeparator( offset ); // ----------------------------------------------
offset = catExperimental.Draw(offset);
offset = GUISeparator( offset ); // ----------------------------------------------
}
GUI.EndScrollView();
GUI.EndGroup();
this.maxWidth += scrollBarWidth;
if( guiChanged ) {
editor.ps = this;
editor.OnShaderModified(NodeUpdateType.Hard);
}
innerScrollRect.height = offset;
return offset;
}