public static RectOffset GetMargin(RectTransform rect, RectOffset defaultValue) { if (rect == null) return new RectOffset(0, 0, 0, 0); RectOffset currentMargin = defaultValue; LayoutElementExtended[] list = rect.GetComponents<LayoutElementExtended>(); for (int i = 0; i < list.Length; i++) { LayoutElementExtended layoutElementExtended = list[i]; if (layoutElementExtended.enabled) { RectOffset elementMargin = layoutElementExtended.margin; currentMargin.top += elementMargin.top; currentMargin.bottom += elementMargin.bottom; currentMargin.left += elementMargin.left; currentMargin.right += elementMargin.right; } } return currentMargin; }
private static Rect INTERNAL_CALL_Remove(RectOffset self, ref Rect rect){}
public override void OnInspectorGUI() { EditorGUILayout.Space(); ResetVisibleCurves(); using (new EditorGUI.DisabledGroupScope(serializedObject.isEditingMultipleObjects)) { int curveEditingId; SerializedProperty currentCurveRawProp = null; // Top toolbar using (new GUILayout.HorizontalScope(EditorStyles.toolbar)) { curveEditingId = DoCurveSelectionPopup(m_SelectedCurve.intValue); curveEditingId = Mathf.Clamp(curveEditingId, 0, 7); EditorGUILayout.Space(); switch (curveEditingId) { case 0: CurveOverrideToggle(m_Master.overrideState); SetCurveVisible(m_RawMaster, m_Master.overrideState); currentCurveRawProp = m_RawMaster; break; case 1: CurveOverrideToggle(m_Red.overrideState); SetCurveVisible(m_RawRed, m_Red.overrideState); currentCurveRawProp = m_RawRed; break; case 2: CurveOverrideToggle(m_Green.overrideState); SetCurveVisible(m_RawGreen, m_Green.overrideState); currentCurveRawProp = m_RawGreen; break; case 3: CurveOverrideToggle(m_Blue.overrideState); SetCurveVisible(m_RawBlue, m_Blue.overrideState); currentCurveRawProp = m_RawBlue; break; case 4: CurveOverrideToggle(m_HueVsHue.overrideState); SetCurveVisible(m_RawHueVsHue, m_HueVsHue.overrideState); currentCurveRawProp = m_RawHueVsHue; break; case 5: CurveOverrideToggle(m_HueVsSat.overrideState); SetCurveVisible(m_RawHueVsSat, m_HueVsSat.overrideState); currentCurveRawProp = m_RawHueVsSat; break; case 6: CurveOverrideToggle(m_SatVsSat.overrideState); SetCurveVisible(m_RawSatVsSat, m_SatVsSat.overrideState); currentCurveRawProp = m_RawSatVsSat; break; case 7: CurveOverrideToggle(m_LumVsSat.overrideState); SetCurveVisible(m_RawLumVsSat, m_LumVsSat.overrideState); currentCurveRawProp = m_RawLumVsSat; break; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset", EditorStyles.toolbarButton)) { MarkTextureCurveAsDirty(curveEditingId); switch (curveEditingId) { case 0: m_RawMaster.animationCurveValue = AnimationCurve.Linear(0f, 0f, 1f, 1f); break; case 1: m_RawRed.animationCurveValue = AnimationCurve.Linear(0f, 0f, 1f, 1f); break; case 2: m_RawGreen.animationCurveValue = AnimationCurve.Linear(0f, 0f, 1f, 1f); break; case 3: m_RawBlue.animationCurveValue = AnimationCurve.Linear(0f, 0f, 1f, 1f); break; case 4: m_RawHueVsHue.animationCurveValue = new AnimationCurve(); break; case 5: m_RawHueVsSat.animationCurveValue = new AnimationCurve(); break; case 6: m_RawSatVsSat.animationCurveValue = new AnimationCurve(); break; case 7: m_RawLumVsSat.animationCurveValue = new AnimationCurve(); break; } } m_SelectedCurve.intValue = curveEditingId; } // Curve area var rect = GUILayoutUtility.GetAspectRect(2f); var innerRect = new RectOffset(10, 10, 10, 10).Remove(rect); if (Event.current.type == EventType.Repaint) { // Background EditorGUI.DrawRect(rect, new Color(0.15f, 0.15f, 0.15f, 1f)); if (curveEditingId == 4 || curveEditingId == 5) { DrawBackgroundTexture(innerRect, 0); } else if (curveEditingId == 6 || curveEditingId == 7) { DrawBackgroundTexture(innerRect, 1); } // Bounds Handles.color = Color.white * (GUI.enabled ? 1f : 0.5f); Handles.DrawSolidRectangleWithOutline(innerRect, Color.clear, new Color(0.8f, 0.8f, 0.8f, 0.5f)); // Grid setup Handles.color = new Color(1f, 1f, 1f, 0.05f); int hLines = (int)Mathf.Sqrt(innerRect.width); int vLines = (int)(hLines / (innerRect.width / innerRect.height)); // Vertical grid int gridOffset = Mathf.FloorToInt(innerRect.width / hLines); int gridPadding = ((int)(innerRect.width) % hLines) / 2; for (int i = 1; i < hLines; i++) { var offset = i * Vector2.right * gridOffset; offset.x += gridPadding; Handles.DrawLine(innerRect.position + offset, new Vector2(innerRect.x, innerRect.yMax - 1) + offset); } // Horizontal grid gridOffset = Mathf.FloorToInt(innerRect.height / vLines); gridPadding = ((int)(innerRect.height) % vLines) / 2; for (int i = 1; i < vLines; i++) { var offset = i * Vector2.up * gridOffset; offset.y += gridPadding; Handles.DrawLine(innerRect.position + offset, new Vector2(innerRect.xMax - 1, innerRect.y) + offset); } } // Curve editor using (new GUI.ClipScope(innerRect)) { if (m_CurveEditor.OnGUI(new Rect(0, 0, innerRect.width - 1, innerRect.height - 1))) { Repaint(); GUI.changed = true; MarkTextureCurveAsDirty(m_SelectedCurve.intValue); } } if (Event.current.type == EventType.Repaint) { // Borders Handles.color = Color.black; Handles.DrawLine(new Vector2(rect.x, rect.y - 18f), new Vector2(rect.xMax, rect.y - 18f)); Handles.DrawLine(new Vector2(rect.x, rect.y - 19f), new Vector2(rect.x, rect.yMax)); Handles.DrawLine(new Vector2(rect.x, rect.yMax), new Vector2(rect.xMax, rect.yMax)); Handles.DrawLine(new Vector2(rect.xMax, rect.yMax), new Vector2(rect.xMax, rect.y - 18f)); bool editable = m_CurveEditor.GetCurveState(currentCurveRawProp).editable; string editableString = editable ? string.Empty : "(Not Overriding)\n"; // Selection info var selection = m_CurveEditor.GetSelection(); var infoRect = innerRect; infoRect.x += 5f; infoRect.width = 100f; infoRect.height = 30f; if (s_PreLabel == null) { s_PreLabel = new GUIStyle("ShurikenLabel"); } if (selection.curve != null && selection.keyframeIndex > -1) { var key = selection.keyframe.Value; GUI.Label(infoRect, $"{key.time:F3}\n{key.value:F3}", s_PreLabel); } else { GUI.Label(infoRect, editableString, s_PreLabel); } } } }
private void CreateGameObjects() { const float BLEND_HORIZON_C0 = 0.259f; const float BLEND_HORIZON_C1 = 0.342f; const float BLEND_VERT_C0 = 0.966f; const float BLEND_VERT_C1 = 0.94f; const float BLEND_LEVEL_GUIDE_C0 = 0.984f; const float BLEND_LEVEL_GUIDE_C1 = 0.996f; float viewportSizeX = Screen.width * 0.5f; float viewportSizeY = Screen.height * 0.5f; { GameObject o = new GameObject("KerbalFlightIndicators-CustomCamera"); Camera cam = o.AddComponent <Camera>(); cam.orthographic = true; cam.clearFlags = CameraClearFlags.Nothing; cam.orthographicSize = viewportSizeY; cam.aspect = viewportSizeX / viewportSizeY; cam.cullingMask = (1 << KFI_LAYER); cam.depth = drawInFrontOfCockpit ? 10 : 1; cam.farClipPlane = 2.0f; cam.nearClipPlane = 0.5f; cam.allowHDR = false; o.transform.localPosition = new Vector3(0.5f, 0.5f, 0.0f); o.transform.localRotation = Quaternion.identity; CameraScript cs = cameraScript = o.AddComponent <CameraScript>(); } { Shader shd = Shader.Find("KSP/Alpha/Unlit Transparent"); GameObject o = markerParentObject = new GameObject("KerbalFlightIndicators-MarkerParent"); markerEnabling = cameraScript.markerEnabling = new bool[(int)Markers.COUNT]; markerScripts = cameraScript.markerScripts = new MarkerScript[(int)Markers.COUNT]; for (int i = 0; i < (int)Markers.COUNT; ++i) { Material mat = new Material(shd); mat.mainTexture = marker_atlas; Rect uv = atlas_uv[i]; RectOffset px = atlas_px[i]; mat.mainTextureScale = new Vector2(uv.width, uv.height); mat.mainTextureOffset = new Vector2(uv.xMin, uv.yMin); o = GameObject.CreatePrimitive(PrimitiveType.Quad); o.name = "KerbalFlightIndicators-" + System.Enum.GetName(typeof(Markers), i); Component[] colliders = o.GetComponents <Collider>(); foreach (var c in colliders) { Component.DestroyImmediate(c); // DON'T WANT OUR GUI ELEMENTS COLLIDING WITH STUFF! } MeshRenderer mr = o.GetComponent <MeshRenderer>(); mr.material = mat; o.layer = KFI_LAYER; float zlevel = 1.0f; MarkerScript ms = markerScripts[i] = o.AddComponent <MarkerScript>(); if (i == (int)Markers.Heading || i == (int)Markers.LevelGuide || i == (int)Markers.Reverse) { ms.baseColor = attitudeColor; } else if (i == (int)Markers.Prograde || i == (int)Markers.Retrograde) { ms.baseColor = progradeColor; zlevel = 1.1f; } else { ms.baseColor = horizonColor; zlevel = 1.2f; } if (i == (int)Markers.Horizon) { ms.SetBlendConstants(BLEND_HORIZON_C0, BLEND_HORIZON_C1); } else if (i == (int)Markers.Vertical) { ms.SetBlendConstants(BLEND_VERT_C0, BLEND_VERT_C1); } else if (i == (int)Markers.LevelGuide) { ms.SetBlendConstants(BLEND_LEVEL_GUIDE_C0, BLEND_LEVEL_GUIDE_C1); } o.transform.parent = markerParentObject.transform; o.transform.localPosition = new Vector3(0.0f, 0.0f, zlevel); o.transform.localRotation = Quaternion.identity; o.transform.localScale = new Vector3((px.right - px.left) * displayScaleFactor, (px.bottom - px.top) * displayScaleFactor, 1.0f); markerEnabling[i] = true; } } OnGuiVisibilityChange(); }
private void DrawContentItem() { IReadOnlyList <TempListElementUI> elementList = ElementList; int dataCount = m_simulatedDataCount; // TODO @Hiko use a general calculation bool test = m_content.anchorMin != Vector2.up || m_content.anchorMax != Vector2.up || m_content.pivot != Vector2.up; if (test) { m_content.anchorMin = Vector2.up; m_content.anchorMax = Vector2.up; m_content.pivot = Vector2.up; } Vector3 dragContentAnchorPostion = m_content.anchoredPosition; Vector3 contentMove = dragContentAnchorPostion - SomeUtils.GetOffsetLocalPosition(m_content, SomeUtils.UIOffsetType.TopLeft); Vector2 itemSize = m_gridLayoutGroup.CellSize, spacing = m_gridLayoutGroup.Spacing; RectOffset padding = null; if (null != m_gridLayoutGroup) { padding = m_gridLayoutGroup.RectPadding; } // TODO need to know the moving direction, then adjust it to prevent wrong draw float xMove = contentMove.x < 0 ? (-contentMove.x - padding.horizontal) : 0; xMove = Mathf.Clamp(xMove, 0.0f, Mathf.Abs(xMove)); float yMove = contentMove.y > 0 ? (contentMove.y - padding.vertical) : 0; yMove = Mathf.Clamp(yMove, 0.0f, Mathf.Abs(yMove)); // the column index of the top left item int tempColumnIndex = Mathf.FloorToInt((xMove + spacing.x) / (itemSize.x + spacing.x)); if (xMove % (itemSize.x + spacing.x) - itemSize.x > spacing.x) { tempColumnIndex = Mathf.Clamp(tempColumnIndex - 1, 0, tempColumnIndex); } // the row index of the top left item int tempRowIndex = Mathf.FloorToInt((yMove + spacing.y) / (itemSize.y + spacing.y)); if (yMove % (itemSize.y + spacing.y) - itemSize.y > spacing.y) { tempRowIndex = Mathf.Clamp(tempRowIndex - 1, 0, tempRowIndex); } Vector2Int rowTopLeftItemIndex = new Vector2Int(tempRowIndex, tempColumnIndex); int rowDataCount = 0, columnDataCount = 0; if (BoundlessGridLayoutData.Constraint.FixedColumnCount == m_gridLayoutGroup.constraint) { rowDataCount = m_gridLayoutGroup.constraintCount; columnDataCount = Mathf.CeilToInt((float)dataCount / rowDataCount); } else { columnDataCount = m_gridLayoutGroup.constraintCount; rowDataCount = Mathf.CeilToInt((float)dataCount / columnDataCount); } // x -> element amount on horizontal axis // y -> element amount on vertical axis Vector2Int contentRowColumnSize = new Vector2Int(rowDataCount, columnDataCount); // deal with content from left to right (simple case) int dataIndex = 0, uiItemIndex = 0; Vector3 rowTopLeftPosition = new Vector3(padding.left, -padding.top, 0.0f), itemTopLeftPosition = Vector3.zero; for (int columnIndex = 0; columnIndex < m_viewItemCountInColumn; columnIndex++) { if (columnIndex + rowTopLeftItemIndex.x == columnDataCount) { break; } rowTopLeftPosition = new Vector3(padding.left, -padding.top, 0.0f) + Vector3.down * (columnIndex + rowTopLeftItemIndex.x) * (itemSize.y + spacing.y); for (int rowIndex = 0; rowIndex < m_viewItemCountInRow; rowIndex++) { if (rowIndex + rowTopLeftItemIndex.y == rowDataCount) { break; } Vector2Int elementIndex = new Vector2Int(rowIndex + rowTopLeftItemIndex.y, columnIndex + rowTopLeftItemIndex.x); dataIndex = CaculateDataIndex(elementIndex, contentRowColumnSize, GridLayoutData.startAxis, GridLayoutData.startCorner); itemTopLeftPosition = rowTopLeftPosition + Vector3.right * (rowIndex + rowTopLeftItemIndex.y) * (itemSize.x + spacing.x); // TODO @Hiko avoid overdraw if (uiItemIndex > 0 && elementList[uiItemIndex - 1].ElementIndex == dataIndex) { continue; // over draw case } if (dataIndex > -1 && dataIndex < dataCount) { elementList[uiItemIndex].ElementRectTransform.localPosition = itemTopLeftPosition; elementList[uiItemIndex].SetIndex(dataIndex); elementList[uiItemIndex].Show(); uiItemIndex++; } } } while (uiItemIndex < elementList.Count) { elementList[uiItemIndex].SetIndex(-1); elementList[uiItemIndex].Hide(); elementList[uiItemIndex].ElementRectTransform.position = Vector3.zero; uiItemIndex++; } NotifyOnContentItemFinishDrawing(); }
/// <summary> /// Creates a new relative layout. This class is not a layout group as it does not /// remain attached to the parent post execution. /// </summary> /// <param name="parent">The object to lay out.</param> public RelativeLayout(GameObject parent) { OverallMargin = null; Parent = parent ?? throw new ArgumentNullException("parent"); locConstraints = new Dictionary <GameObject, RelativeLayoutParams>(32); }
public static GUIStyleMarginScope StyleMargin(GUIStyle style, RectOffset margin) { return(new GUIStyleMarginScope(style, margin)); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type != EventType.Repaint) { return; } var importer = (VideoClipImporter)target; RectOffset previewPadding = new RectOffset(-5, -5, -5, -5); r = previewPadding.Add(r); // Prepare rects for columns r.height = EditorGUIUtility.singleLineHeight; Rect labelRect = r; Rect valueRect = r; labelRect.width = kLabelWidth; valueRect.xMin += kLabelWidth; valueRect.width = kValueWidth; ShowProperty(ref labelRect, ref valueRect, "Original Size", EditorUtility.FormatBytes((long)importer.sourceFileSize)); ShowProperty(ref labelRect, ref valueRect, "Imported Size", EditorUtility.FormatBytes((long)importer.outputFileSize)); var frameCount = importer.frameCount; var frameRate = importer.frameRate; var duration = frameRate > 0 ? TimeSpan.FromSeconds(frameCount / frameRate).ToString() : new TimeSpan(0).ToString(); // TimeSpan uses 7 digits for fractional seconds. Limit this to 3 digits. if (duration.IndexOf('.') != -1) { duration = duration.Substring(0, duration.Length - 4); } ShowProperty(ref labelRect, ref valueRect, "Duration", duration); ShowProperty(ref labelRect, ref valueRect, "Frames", frameCount.ToString()); ShowProperty(ref labelRect, ref valueRect, "FPS", frameRate.ToString("F2")); var originalWidth = importer.GetResizeWidth(VideoResizeMode.OriginalSize); var originalHeight = importer.GetResizeHeight(VideoResizeMode.OriginalSize); ShowProperty(ref labelRect, ref valueRect, "Pixels", originalWidth + "x" + originalHeight); ShowProperty(ref labelRect, ref valueRect, "PAR", importer.pixelAspectRatioNumerator + ":" + importer.pixelAspectRatioDenominator); ShowProperty(ref labelRect, ref valueRect, "Alpha", importer.sourceHasAlpha ? "Yes" : "No"); var audioTrackCount = importer.sourceAudioTrackCount; ShowProperty(ref labelRect, ref valueRect, "Audio", audioTrackCount == 0 ? "none" : audioTrackCount == 1 ? GetAudioTrackDescription(importer, 0) : ""); if (audioTrackCount <= 1) { return; } labelRect.xMin += kIndentWidth; labelRect.width -= kIndentWidth; for (ushort i = 0; i < audioTrackCount; ++i) { ShowProperty(ref labelRect, ref valueRect, "Track #" + (i + 1), GetAudioTrackDescription(importer, i)); } }
private void AddPanelControls() { UILabel uiLabel1 = Utils.GetPrivate <UILabel>((object)this._publicTransportVehicleWorldInfoPanel, "m_Type"); int num1 = 132; uiLabel1.anchor = (UIAnchorStyle)num1; UIPanel parent = (UIPanel)uiLabel1.parent; RectOffset rectOffset = new RectOffset(0, 10, 0, 0); parent.autoLayoutPadding = rectOffset; double num2 = 25.0; parent.height = (float)num2; int num3 = 1; parent.useCenter = num3 != 0; UIButton button1 = UIHelper.CreateButton((UIComponent)parent); button1.name = "EditType"; button1.autoSize = true; button1.anchor = UIAnchorStyle.Left | UIAnchorStyle.Right | UIAnchorStyle.CenterVertical; button1.textPadding = new RectOffset(10, 10, 4, 2); button1.text = Localization.Get("VEHICLE_PANEL_EDIT_TYPE"); button1.tooltip = string.Format(Localization.Get("VEHICLE_PANEL_EDIT_TYPE_TOOLTIP")); button1.textScale = 0.75f; button1.eventClick += new MouseEventHandler(this.OnEditTypeClick); button1.isVisible = !ImprovedPublicTransportMod.Settings.HideVehicleEditor; this._editType = button1; UILabel uiLabel2 = Utils.GetPrivate <UILabel>((object)this._publicTransportVehicleWorldInfoPanel, "m_Passengers"); UIPanel uiPanel1 = this._publicTransportVehicleWorldInfoPanel.component.Find <UIPanel>("Panel"); UIPanel uiPanel2 = uiPanel1.AddUIComponent <UIPanel>(); uiPanel2.autoLayout = true; uiPanel2.autoLayoutDirection = LayoutDirection.Horizontal; uiPanel2.autoLayoutPadding = new RectOffset(0, 0, 0, 0); uiPanel2.height = uiLabel2.parent.height; uiPanel2.width = uiLabel2.parent.width; uiPanel2.zOrder = 4; this._passengerPanel = uiPanel2; UILabel uiLabel3 = uiPanel2.AddUIComponent <UILabel>(); uiLabel3.name = "LastStopExchange"; uiLabel3.font = uiLabel2.font; uiLabel3.textColor = uiLabel2.textColor; uiLabel3.textScale = uiLabel2.textScale; uiLabel3.processMarkup = true; this._lastStopExchange = uiLabel3; UIPanel uiPanel3 = uiPanel1.AddUIComponent <UIPanel>(); uiPanel3.name = "PassengerStats"; uiPanel3.anchor = UIAnchorStyle.Top | UIAnchorStyle.Left | UIAnchorStyle.Right; uiPanel3.autoLayout = true; uiPanel3.autoLayoutDirection = LayoutDirection.Vertical; uiPanel3.autoLayoutPadding = new RectOffset(0, 0, 0, 0); uiPanel3.autoLayoutStart = LayoutStart.TopLeft; uiPanel3.size = new Vector2(349f, 60f); uiPanel3.zOrder = 5; this._statsPanel = uiPanel3; UILabel label1; UILabel label2; UILabel label3; UILabel label4; PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel3, out label1, out label2, out label3, out label4, true); label2.text = Localization.Get("CURRENT_WEEK"); label3.text = Localization.Get("LAST_WEEK"); label4.text = Localization.Get("AVERAGE"); label4.tooltip = string.Format(Localization.Get("AVERAGE_TOOLTIP"), (object)ImprovedPublicTransportMod.Settings.StatisticWeeks); PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel3, out label1, out this._passengersCurrentWeek, out this._passengersLastWeek, out this._passengersAverage, false); label1.text = Localization.Get("VEHICLE_PANEL_PASSENGERS"); PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel3, out label1, out this._earningsCurrentWeek, out this._earningsLastWeek, out this._earningsAverage, false); label1.text = Localization.Get("VEHICLE_PANEL_EARNINGS"); label1.tooltip = Localization.Get("VEHICLE_PANEL_EARNINGS_TOOLTIP"); UIPanel uiPanel4 = uiPanel1.AddUIComponent <UIPanel>(); uiPanel4.name = "Buttons"; uiPanel4.anchor = UIAnchorStyle.Top | UIAnchorStyle.Left | UIAnchorStyle.Right; uiPanel4.autoLayout = true; uiPanel4.autoLayoutDirection = LayoutDirection.Horizontal; uiPanel4.autoLayoutPadding = new RectOffset(0, 5, 0, 0); uiPanel4.autoLayoutStart = LayoutStart.TopLeft; uiPanel4.size = new Vector2(345f, 32f); this._buttonPanel = uiPanel4; UIButton button2 = UIHelper.CreateButton((UIComponent)uiPanel4); button2.name = "PreviousVehicle"; button2.textPadding = new RectOffset(10, 10, 4, 0); button2.text = Localization.Get("VEHICLE_PANEL_PREVIOUS"); button2.tooltip = Localization.Get("VEHICLE_PANEL_PREVIOUS_TOOLTIP"); button2.textScale = 0.75f; button2.size = new Vector2(110f, 32f); button2.wordWrap = true; button2.eventClick += new MouseEventHandler(this.OnChangeVehicleClick); UIButton button3 = UIHelper.CreateButton((UIComponent)uiPanel4); button3.name = "RemoveVehicle"; button3.textPadding = new RectOffset(10, 10, 4, 0); button3.text = Localization.Get("VEHICLE_PANEL_REMOVE_VEHICLE"); button3.textScale = 0.75f; button3.size = new Vector2(100f, 32f); button3.wordWrap = true; button3.hoveredTextColor = (Color32)Color.red; button3.focusedTextColor = (Color32)Color.red; button3.pressedTextColor = (Color32)Color.red; button3.eventClick += new MouseEventHandler(this.OnRemoveVehicleClick); UIButton button4 = UIHelper.CreateButton((UIComponent)uiPanel4); button4.name = "NextVehicle"; button4.textPadding = new RectOffset(10, 10, 4, 0); button4.text = Localization.Get("VEHICLE_PANEL_NEXT"); button4.tooltip = Localization.Get("VEHICLE_PANEL_NEXT_TOOLTIP"); button4.textScale = 0.75f; button4.size = new Vector2(110f, 32f); button4.wordWrap = true; button4.eventClick += new MouseEventHandler(this.OnChangeVehicleClick); }
public VRCEUiVerticalScrollView(string name, Vector2 position, Vector2 size, float spacing, RectOffset padding = null, Transform parent = null) { // Create game objects GameObject goControl = new GameObject(name); GameObject goContentControl = new GameObject("Content"); // Get positions Position = goControl.GetOrAddComponent <RectTransform>(); ContentPosition = goContentControl.GetOrAddComponent <RectTransform>(); // Create control properties ScrollRectObject = goControl.AddComponent <ScrollRect>(); SizeFitterObject = goContentControl.AddComponent <ContentSizeFitter>(); LayoutGroupObject = goContentControl.AddComponent <VerticalLayoutGroup>(); MaskObject = goControl.AddComponent <Mask>(); ImageObject = goControl.AddComponent <Image>(); // Set UI properties Control = goControl.transform; ContentControl = goContentControl.transform; // Set required parts if (parent != null) { Control.SetParent(parent); } // Setup ScrollView Control.localScale = Vector3.one; Control.localRotation = Quaternion.identity; Control.localPosition = Vector3.zero; Position.localPosition = new Vector3(position.x, position.y, 0f); Position.sizeDelta = size; ScrollRectObject.vertical = true; ScrollRectObject.horizontal = false; // Setup mask MaskObject.showMaskGraphic = false; Texture2D texture = new Texture2D(2, 2); Color color = new Color(0f, 0f, 0f, 1f); texture.SetPixels(new Color[] { color, color, color, color }); texture.Apply(); ImageObject.sprite = Sprite.Create(texture, new Rect(0f, 0f, 2f, 2f), new Vector2(0f, 0f)); // Setup Content ContentControl.SetParent(Control); ContentControl.localScale = Vector3.one; ContentControl.localRotation = Quaternion.identity; ContentControl.localPosition = Vector3.zero; ContentPosition.localPosition = new Vector3(0f, 0f, 0f); ContentPosition.anchorMin = new Vector2(0.5f, 1f); ContentPosition.anchorMax = new Vector2(0.5f, 1f); ContentPosition.pivot = new Vector2(0.5f, 1f); ContentPosition.sizeDelta = new Vector2(size.x, spacing); SizeFitterObject.verticalFit = ContentSizeFitter.FitMode.PreferredSize; LayoutGroupObject.spacing = spacing; LayoutGroupObject.childAlignment = TextAnchor.UpperCenter; LayoutGroupObject.childForceExpandHeight = false; LayoutGroupObject.childForceExpandWidth = false; LayoutGroupObject.childControlHeight = true; LayoutGroupObject.childControlWidth = true; if (padding != null) { LayoutGroupObject.padding = padding; } ScrollRectObject.content = ContentPosition; ScrollRectObject.viewport = Position; // Finish Success = true; }
private void SetupUI() { _cookedColor = new Color(0.1f, 0.9f, 0.0f, 1f); _assetGOLabel = new GUIContent("Linked Asset", "The HDA containing TOP networks to link with."); _assetStatusLabel = new GUIContent("Asset Work Items Status:"); _resetContent = new GUIContent("Reset", "Reset the state and generated items. Updates from linked HDA."); _refreshContent = new GUIContent("Refresh", "Refresh the state and UI."); _autocookContent = new GUIContent("Autocook", "Automatically cook the output node when the linked asset is cooked."); _useHEngineDataContent = new GUIContent("Use HEngine Data", "Whether to use henginedata parm values for displaying and loading node resuls."); _topNetworkChooseLabel = new GUIContent("TOP Network"); _topNetworkNoneLabel = new GUIContent("TOP Network: None"); _topNodeChooseLabel = new GUIContent("TOP Node"); _topNodeNoneLabel = new GUIContent("TOP Node: None"); _topNodeStatusLabel = new GUIContent("TOP Node Work Items Status:"); _buttonDirtyContent = new GUIContent("Dirty Node", "Remove current TOP node's work items."); _buttonCookContent = new GUIContent("Cook Node", "Generates and cooks current TOP node's work items."); _autoloadContent = new GUIContent("Autoload Results", "Automatically load into Unity the generated geometry from work item results."); _showHideResultsContent = new GUIContent("Show Results", "Show or Hide Results."); _buttonDirtyAllContent = new GUIContent("Dirty All", "Removes all work items."); _buttonCookAllContent = new GUIContent("Cook Output", "Generates and cooks all work items."); _buttonCancelCookContent = new GUIContent("Cancel Cook", "Cancel PDG cook."); _buttonPauseCookContent = new GUIContent("Pause Cook", "Pause PDG cook."); _backgroundStyle = new GUIStyle(GUI.skin.box); RectOffset br = _backgroundStyle.margin; br.top = 10; br.bottom = 6; br.left = 4; br.right = 4; _backgroundStyle.margin = br; br = _backgroundStyle.padding; br.top = 8; br.bottom = 8; br.left = 8; br.right = 8; _backgroundStyle.padding = br; _boxStyleTitle = new GUIStyle(GUI.skin.box); float c = 0.35f; _boxStyleTitle.normal.background = HEU_GeneralUtility.MakeTexture(1, 1, new Color(c, c, c, 1f)); _boxStyleTitle.normal.textColor = Color.black; _boxStyleTitle.fontStyle = FontStyle.Bold; _boxStyleTitle.alignment = TextAnchor.MiddleCenter; _boxStyleTitle.fontSize = 10; _boxStyleValue = new GUIStyle(GUI.skin.box); c = 0.7f; _boxStyleValue.normal.background = HEU_GeneralUtility.MakeTexture(1, 1, new Color(c, c, c, 1f)); _boxStyleValue.normal.textColor = Color.black; _boxStyleValue.fontStyle = FontStyle.Bold; _boxStyleValue.fontSize = 14; _boxStyleStatus = new GUIStyle(GUI.skin.box); c = 0.3f; _boxStyleStatus.normal.background = HEU_GeneralUtility.MakeTexture(1, 1, new Color(c, c, c, 1f)); _boxStyleStatus.normal.textColor = Color.black; _boxStyleStatus.fontStyle = FontStyle.Bold; _boxStyleStatus.alignment = TextAnchor.MiddleCenter; _boxStyleStatus.fontSize = 14; _boxStyleStatus.stretchWidth = true; }
private void SetupPanel() { this.name = "PublicTransportStopWorldInfoPanel"; this.isVisible = false; this.canFocus = true; this.isInteractive = true; this.anchor = UIAnchorStyle.None; this.pivot = UIPivotPoint.BottomLeft; this.width = 380f; this.height = 280f; this.backgroundSprite = "InfoBubbleVehicle"; UIPanel uiPanel1 = this.AddUIComponent <UIPanel>(); string str1 = "Caption"; uiPanel1.name = str1; double width = (double)this.width; uiPanel1.width = (float)width; double num1 = 40.0; uiPanel1.height = (float)num1; Vector3 vector3_1 = new Vector3(0.0f, 0.0f); uiPanel1.relativePosition = vector3_1; UISprite uiSprite1 = uiPanel1.AddUIComponent <UISprite>(); uiSprite1.name = "VehicleType"; uiSprite1.size = new Vector2(32f, 22f); uiSprite1.relativePosition = new Vector3(8f, 9f, 0.0f); this.m_VehicleType = uiSprite1; UITextField uiTextField = uiPanel1.AddUIComponent <UITextField>(); uiTextField.name = "StopName"; uiTextField.font = UIUtils.Font; uiTextField.height = 25f; uiTextField.width = 200f; uiTextField.maxLength = 32; uiTextField.builtinKeyNavigation = true; uiTextField.submitOnFocusLost = true; uiTextField.focusedBgSprite = "TextFieldPanel"; uiTextField.hoveredBgSprite = "TextFieldPanelHovered"; uiTextField.padding = new RectOffset(0, 0, 4, 0); uiTextField.selectionSprite = "EmptySprite"; uiTextField.verticalAlignment = UIVerticalAlignment.Middle; uiTextField.position = new Vector3((float)((double)this.width / 2.0 - (double)uiTextField.width / 2.0), (float)((double)uiTextField.height / 2.0 - 20.0)); uiTextField.eventTextSubmitted += new PropertyChangedEventHandler <string>(this.OnRename); this.m_StopName = uiTextField; DropDown dropDown = DropDown.Create((UIComponent)uiPanel1); dropDown.name = "SuggestedNames"; dropDown.size = new Vector2(30f, 25f); dropDown.ListWidth = 200f; dropDown.DropDownPanelAlignParent = (UIComponent)this; dropDown.Font = UIUtils.Font; dropDown.position = new Vector3((float)((double)this.width / 2.0 + (double)uiTextField.width / 2.0), (float)((double)dropDown.height / 2.0 - 20.0)); dropDown.tooltip = Localization.Get("STOP_PANEL_SUGGESTED_NAMES_TOOLTIP"); dropDown.ShowPanel = false; dropDown.eventSelectedItemChanged += new PropertyChangedEventHandler <ushort>(this.OnSelectedItemChanged); this.m_SuggestedNames = dropDown; UIButton uiButton1 = uiPanel1.AddUIComponent <UIButton>(); uiButton1.name = "ReuseName"; uiButton1.tooltip = Localization.Get("STOP_PANEL_REUSE_NAME_TOOLTIP"); uiButton1.size = new Vector2(30f, 30f); uiButton1.normalBgSprite = "IconPolicyRecycling"; uiButton1.hoveredBgSprite = "IconPolicyRecyclingHovered"; uiButton1.pressedBgSprite = "IconPolicyRecyclingPressed"; uiButton1.relativePosition = new Vector3((float)((double)this.width - 32.0 - (double)uiButton1.width - 2.0), 6f); uiButton1.eventClick += new MouseEventHandler(this.OnReuseNameButtonClick); UIButton uiButton2 = uiPanel1.AddUIComponent <UIButton>(); uiButton2.name = "Close"; uiButton2.size = new Vector2(32f, 32f); uiButton2.normalBgSprite = "buttonclose"; uiButton2.hoveredBgSprite = "buttonclosehover"; uiButton2.pressedBgSprite = "buttonclosepressed"; uiButton2.relativePosition = new Vector3((float)((double)this.width - (double)uiButton2.width - 2.0), 2f); uiButton2.eventClick += new MouseEventHandler(this.OnCloseButtonClick); UIPanel uiPanel2 = this.AddUIComponent <UIPanel>(); string str2 = "Container"; uiPanel2.name = str2; double num2 = 365.0; uiPanel2.width = (float)num2; double num3 = 197.0; uiPanel2.height = (float)num3; int num4 = 1; uiPanel2.autoLayout = num4 != 0; int num5 = 1; uiPanel2.autoLayoutDirection = (LayoutDirection)num5; RectOffset rectOffset1 = new RectOffset(10, 10, 5, 0); uiPanel2.autoLayoutPadding = rectOffset1; int num6 = 0; uiPanel2.autoLayoutStart = (LayoutStart)num6; Vector3 vector3_2 = new Vector3(6f, 46f); uiPanel2.relativePosition = vector3_2; UIPanel uiPanel3 = uiPanel2.AddUIComponent <UIPanel>(); string str3 = "PassengerCountPanel"; uiPanel3.name = str3; int num7 = 13; uiPanel3.anchor = (UIAnchorStyle)num7; int num8 = 1; uiPanel3.autoLayout = num8 != 0; int num9 = 0; uiPanel3.autoLayoutDirection = (LayoutDirection)num9; RectOffset rectOffset2 = new RectOffset(0, 5, 0, 0); uiPanel3.autoLayoutPadding = rectOffset2; int num10 = 0; uiPanel3.autoLayoutStart = (LayoutStart)num10; Vector2 vector2_1 = new Vector2(345f, 14f); uiPanel3.size = vector2_1; UILabel uiLabel1 = uiPanel3.AddUIComponent <UILabel>(); uiLabel1.name = "PassengerCount"; uiLabel1.font = UIUtils.Font; uiLabel1.autoSize = true; uiLabel1.height = 15f; uiLabel1.textScale = 13f / 16f; uiLabel1.textColor = new Color32((byte)185, (byte)221, (byte)254, byte.MaxValue); this.m_PassengerCount = uiLabel1; UIPanel uiPanel4 = uiPanel2.AddUIComponent <UIPanel>(); string str4 = "BoredCountdownPanel"; uiPanel4.name = str4; int num11 = 13; uiPanel4.anchor = (UIAnchorStyle)num11; int num12 = 1; uiPanel4.autoLayout = num12 != 0; int num13 = 0; uiPanel4.autoLayoutDirection = (LayoutDirection)num13; RectOffset rectOffset3 = new RectOffset(0, 5, 0, 0); uiPanel4.autoLayoutPadding = rectOffset3; int num14 = 0; uiPanel4.autoLayoutStart = (LayoutStart)num14; Vector2 vector2_2 = new Vector2(345f, 14f); uiPanel4.size = vector2_2; UILabel uiLabel2 = uiPanel4.AddUIComponent <UILabel>(); uiLabel2.name = "BoredCountdown"; uiLabel2.tooltip = Localization.Get("STOP_PANEL_BORED_TIMER_TOOLTIP"); uiLabel2.font = UIUtils.Font; uiLabel2.autoSize = true; uiLabel2.height = 15f; uiLabel2.textScale = 13f / 16f; uiLabel2.textColor = new Color32((byte)185, (byte)221, (byte)254, byte.MaxValue); uiLabel2.processMarkup = true; this.m_BoredCountdown = uiLabel2; UIPanel uiPanel5 = uiPanel2.AddUIComponent <UIPanel>(); string str5 = "PassengerStats"; uiPanel5.name = str5; int num15 = 13; uiPanel5.anchor = (UIAnchorStyle)num15; int num16 = 1; uiPanel5.autoLayout = num16 != 0; int num17 = 1; uiPanel5.autoLayoutDirection = (LayoutDirection)num17; RectOffset rectOffset4 = new RectOffset(0, 0, 0, 0); uiPanel5.autoLayoutPadding = rectOffset4; int num18 = 0; uiPanel5.autoLayoutStart = (LayoutStart)num18; Vector2 vector2_3 = new Vector2(349f, 75f); uiPanel5.size = vector2_3; UILabel uiLabel3; UILabel uiLabel4; UILabel uiLabel5; UILabel uiLabel6; int num19 = 1; PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel5, out uiLabel3, out uiLabel4, out uiLabel5, out uiLabel6, num19 != 0); uiLabel4.text = Localization.Get("CURRENT_WEEK"); uiLabel5.text = Localization.Get("LAST_WEEK"); uiLabel6.text = Localization.Get("AVERAGE"); uiLabel6.tooltip = string.Format(Localization.Get("AVERAGE_TOOLTIP"), (object)OptionsWrapper <Settings> .Options.StatisticWeeks); int num20 = 0; PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel5, out uiLabel3, out this.m_passengersInCurrent, out this.m_passengersInLast, out this.m_passengersInAverage, num20 != 0); uiLabel3.text = Localization.Get("STOP_PANEL_PASSENGERS_IN"); uiLabel3.tooltip = Localization.Get("STOP_PANEL_PASSENGERS_IN_TOOLTIP"); int num21 = 0; PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel5, out uiLabel3, out this.m_passengersOutCurrent, out this.m_passengersOutLast, out this.m_passengersOutAverage, num21 != 0); uiLabel3.text = Localization.Get("STOP_PANEL_PASSENGERS_OUT"); uiLabel3.tooltip = Localization.Get("STOP_PANEL_PASSENGERS_OUT_TOOLTIP"); int num22 = 0; PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel5, out uiLabel3, out this.m_passengersTotalCurrent, out this.m_passengersTotalLast, out this.m_passengersTotalAverage, num22 != 0); uiLabel3.text = Localization.Get("STOP_PANEL_PASSENGERS_TOTAL"); uiLabel3.tooltip = Localization.Get("STOP_PANEL_PASSENGERS_TOTAL_TOOLTIP"); UIPanel uiPanel6 = uiPanel2.AddUIComponent <UIPanel>(); string str6 = "Unbunching"; uiPanel6.name = str6; int num23 = 13; uiPanel6.anchor = (UIAnchorStyle)num23; int num24 = 1; uiPanel6.autoLayout = num24 != 0; int num25 = 0; uiPanel6.autoLayoutDirection = (LayoutDirection)num25; RectOffset rectOffset5 = new RectOffset(0, 5, 0, 0); uiPanel6.autoLayoutPadding = rectOffset5; int num26 = 0; uiPanel6.autoLayoutStart = (LayoutStart)num26; Vector2 vector2_4 = new Vector2(345f, 25f); uiPanel6.size = vector2_4; int num27 = 1; uiPanel6.useCenter = num27 != 0; UICheckBox uiCheckBox = uiPanel6.AddUIComponent <UICheckBox>(); uiCheckBox.anchor = UIAnchorStyle.Left | UIAnchorStyle.CenterVertical; uiCheckBox.clipChildren = true; uiCheckBox.tooltip = Localization.Get("STOP_PANEL_UNBUNCHING_TOOLTIP") + System.Environment.NewLine + Localization.Get("EXPLANATION_UNBUNCHING"); uiCheckBox.eventClicked += new MouseEventHandler(this.OnUnbunchingClick); UISprite uiSprite2 = uiCheckBox.AddUIComponent <UISprite>(); uiSprite2.spriteName = "check-unchecked"; uiSprite2.size = new Vector2(16f, 16f); uiSprite2.relativePosition = Vector3.zero; uiCheckBox.checkedBoxObject = (UIComponent)uiSprite2.AddUIComponent <UISprite>(); ((UISprite)uiCheckBox.checkedBoxObject).spriteName = "check-checked"; uiCheckBox.checkedBoxObject.size = new Vector2(16f, 16f); uiCheckBox.checkedBoxObject.relativePosition = Vector3.zero; uiCheckBox.label = uiCheckBox.AddUIComponent <UILabel>(); uiCheckBox.label.font = UIUtils.Font; uiCheckBox.label.textColor = new Color32((byte)185, (byte)221, (byte)254, byte.MaxValue); uiCheckBox.label.disabledTextColor = (Color32)Color.black; uiCheckBox.label.textScale = 13f / 16f; uiCheckBox.label.text = (int)OptionsWrapper <Settings> .Options.IntervalAggressionFactor == 0 ? Localization.Get("UNBUNCHING_DISABLED") : Localization.Get("UNBUNCHING_ENABLED"); uiCheckBox.label.relativePosition = new Vector3(22f, 2f); uiCheckBox.size = new Vector2(uiCheckBox.label.width + 22f, 16f); this.m_unbunching = uiCheckBox; UIPanel uiPanel7 = uiPanel2.AddUIComponent <UIPanel>(); string str7 = "Line"; uiPanel7.name = str7; int num28 = 13; uiPanel7.anchor = (UIAnchorStyle)num28; Vector2 vector2_5 = new Vector2(345f, 25f); uiPanel7.size = vector2_5; int num29 = 1; uiPanel7.autoLayout = num29 != 0; int num30 = 0; uiPanel7.autoLayoutDirection = (LayoutDirection)num30; RectOffset rectOffset6 = new RectOffset(0, 10, 0, 0); uiPanel7.autoLayoutPadding = rectOffset6; int num31 = 0; uiPanel7.autoLayoutStart = (LayoutStart)num31; int num32 = 1; uiPanel7.useCenter = num32 != 0; UILabel uiLabel7 = uiPanel7.AddUIComponent <UILabel>(); uiLabel7.name = "Line"; uiLabel7.anchor = UIAnchorStyle.Left | UIAnchorStyle.CenterVertical; uiLabel7.font = UIUtils.Font; uiLabel7.autoSize = true; uiLabel7.height = 25f; uiLabel7.textScale = 13f / 16f; uiLabel7.textColor = new Color32((byte)185, (byte)221, (byte)254, byte.MaxValue); uiLabel7.verticalAlignment = UIVerticalAlignment.Middle; uiLabel7.relativePosition = new Vector3(0.0f, 5f); this.m_Line = uiLabel7; UIButton button1 = UIUtils.CreateButton((UIComponent)uiPanel7); button1.name = "ModifyLine"; button1.autoSize = true; button1.textPadding = new RectOffset(10, 10, 4, 2); button1.anchor = UIAnchorStyle.Left | UIAnchorStyle.CenterVertical; button1.localeID = "VEHICLE_MODIFYLINE"; button1.textScale = 0.75f; button1.eventClick += new MouseEventHandler(this.OnModifyLineClick); UIPanel uiPanel8 = uiPanel2.AddUIComponent <UIPanel>(); string str8 = "Buttons"; uiPanel8.name = str8; int num33 = 13; uiPanel8.anchor = (UIAnchorStyle)num33; int num34 = 1; uiPanel8.autoLayout = num34 != 0; int num35 = 0; uiPanel8.autoLayoutDirection = (LayoutDirection)num35; RectOffset rectOffset7 = new RectOffset(0, 5, 0, 0); uiPanel8.autoLayoutPadding = rectOffset7; int num36 = 0; uiPanel8.autoLayoutStart = (LayoutStart)num36; Vector2 vector2_6 = new Vector2(345f, 32f); uiPanel8.size = vector2_6; UIButton button2 = UIUtils.CreateButton((UIComponent)uiPanel8); button2.name = "PreviousStop"; button2.textPadding = new RectOffset(10, 10, 4, 0); button2.text = Localization.Get("STOP_PANEL_PREVIOUS"); button2.tooltip = Localization.Get("STOP_PANEL_PREVIOUS_TOOLTIP"); button2.textScale = 0.75f; button2.size = new Vector2(110f, 32f); button2.wordWrap = true; button2.eventClick += new MouseEventHandler(this.OnPreviousStopClick); UIButton button3 = UIUtils.CreateButton((UIComponent)uiPanel8); button3.name = "DeleteStop"; button3.textPadding = new RectOffset(10, 10, 4, 0); button3.text = Localization.Get("STOP_PANEL_DELETE_STOP"); button3.tooltip = Localization.Get("STOP_PANEL_DELETE_STOP_TOOLTIP"); button3.isEnabled = false; button3.textScale = 0.75f; button3.size = new Vector2(110f, 32f); button3.wordWrap = true; button3.hoveredTextColor = (Color32)Color.red; button3.focusedTextColor = (Color32)Color.red; button3.pressedTextColor = (Color32)Color.red; button3.eventClick += new MouseEventHandler(this.OnDeleteStopClick); this.m_DeleteStop = button3; UIButton button4 = UIUtils.CreateButton((UIComponent)uiPanel8); button4.name = "NextStop"; button4.textPadding = new RectOffset(10, 10, 4, 0); button4.text = Localization.Get("STOP_PANEL_NEXT"); button4.tooltip = Localization.Get("STOP_PANEL_NEXT_TOOLTIP"); button4.textScale = 0.75f; button4.size = new Vector2(110f, 32f); button4.wordWrap = true; button4.eventClick += new MouseEventHandler(this.OnNextStopClick); }
//public void LoadProjectIcon() { // var ico = AssetDatabaseUtils.LoadAssetAtGUID<Texture2D>( E.i.iconOpenCSProject ); // IconCS = ico ?? EditorIcon.icons_processed_dll_script_icon_asset; //} public Styles() { IconButtonSize = 30; if (UnitySymbol.UNITY_2019_3_OR_NEWER) { IconButtonSize = 32; } //LoadProjectIcon(); ButtonLeft = new GUIStyle("ButtonLeft"); var r = new RectOffset(6, 6, 0, 0); ButtonLeft.padding = r; ButtonMid = new GUIStyle("ButtonMid"); ButtonMid.padding = r; ButtonRight = new GUIStyle("ButtonRight"); ButtonRight.padding = r; if (UnitySymbol.UNITY_2019_3_OR_NEWER) { Button = new GUIStyle("AppCommand"); Button.margin = new RectOffset(3, 3, 2, 2); Button.imagePosition = ImagePosition.ImageLeft; Button.fixedWidth = 0; //Button.padding = new RectOffset( 4, 4, 3+3, 3 + 3 ); } else { Button = new GUIStyle("button"); Button.fixedHeight = 18; } //Button.padding = r; Button.padding = new RectOffset(4, 4, 3, 3); Button.alignment = TextAnchor.MiddleCenter; if (UnitySymbol.UNITY_2019_3_OR_NEWER) { var AppCommand = (GUIStyle)"AppCommand"; Button2 = new GUIStyle("button"); Button2.margin = new RectOffset(3, 3, 2, 2); Button2.imagePosition = ImagePosition.ImageLeft; Button2.fixedHeight = AppCommand.fixedHeight; //Button2.stretchWidth = true; Button2.padding = new RectOffset(4, 4, 3, 3); //Button2.active.textColor = Color.black; //Button2.onActive.textColor = Color.black; //Button2.onFocused.textColor = Color.black; //Button2.focused.textColor = Color.black; } else { Button2 = new GUIStyle("button"); Button2.fixedHeight = 18; Button2.padding = EditorStyles.label.padding; } //Button2.margin = EditorStyles.label.margin; DropDown = new GUIStyle("DropDown"); //Button.padding = new RectOffset( 6, 6, 1, 1 ); DropDown.alignment = TextAnchor.MiddleCenter; //Button.lineHeight = ButtonRight.lineHeight; DropDown2 = new GUIStyle("DropDown"); DropDown2.padding = new RectOffset(DropDown2.padding.left, DropDown2.padding.right, 0, 0); DropDown2.alignment = TextAnchor.MiddleCenter; if (UnitySymbol.UNITY_2019_3_OR_NEWER) { DropDownButton = new GUIStyle("DropDown"); //DropDownButton.padding = new RectOffset( DropDownButton.padding.left, DropDownButton.padding.right, 0, 0 ); } else { DropDownButton = new GUIStyle("DropDownButton"); DropDownButton.padding = new RectOffset(6, DropDownButton.padding.right, 2, 2); DropDownButton.fixedHeight = 18; } toggle = new GUIStyle(EditorStyles.toggle); if (UnitySymbol.UNITY_2019_3_OR_NEWER) { toggle.margin.top = 5; } if (UnitySymbol.UNITY_2021_1_OR_NEWER) { Button.fixedHeight = 20; Button.padding = new RectOffset(0, 0, 0, 0); DropDown.fixedHeight = 20; DropDown.padding = new RectOffset(0, 0, 2, 2); DropDownButton.fixedHeight = 20; DropDownButton.padding = new RectOffset(DropDownButton.padding.left, DropDownButton.padding.right, 2, 2); DropDown2.fixedHeight = 20; Button2.fixedHeight = 20; } }
public INodeStyleSchema WithHeaderPadding(RectOffset padding) { HeaderPadding = padding; return(this); }
//private IEnumerator CoInit() //{ // yield return null; // _inited = true; // _scrollRect = transform.GetComponentInParent<ScrollRect>(); // _isVertical = _scrollRect.vertical; // //初始化_viewSpace // RectTransform viewRectTrans = _scrollRect.viewport ? _scrollRect.viewport : (RectTransform)_scrollRect.transform; // _viewSize = _isVertical ? viewRectTrans.rect.height : viewRectTrans.rect.width; // _scrollRect.onValueChanged.AddListener(OnScroll); // InitItemSpace(); // InitShowItem(); //} /// <summary> /// 初始化渲染item的大小 /// </summary> /// <param name="item"></param> 进行渲染的item public void InitItemSpace(params RectTransform[] renderItems) { if (renderItems != null && renderItems.Length != 0) { _renderItems = renderItems; } _layoutGroup = GetComponent <LayoutGroup>(); if (_layoutGroup != null) { _initPadding = _layoutGroup.padding; //计算itemSpace if (_layoutGroup is HorizontalOrVerticalLayoutGroup) { _constraintCount = 1; HorizontalOrVerticalLayoutGroup hvLayout = (HorizontalOrVerticalLayoutGroup)_layoutGroup; _space = hvLayout.spacing; if (_isVertical) { if (hvLayout.childControlHeight)//item拥有自己的layoutElement { LayoutElement element = _renderItems[0].GetComponent <LayoutElement>(); _itemSize = element.preferredHeight + hvLayout.spacing; } else { _itemSize = _renderItems[0].rect.height + hvLayout.spacing; } } else { if (hvLayout.childControlWidth)//item拥有自己的layoutElement { LayoutElement element = _renderItems[0].GetComponent <LayoutElement>(); _itemSize = element.preferredWidth + hvLayout.spacing; } else { _itemSize = _renderItems[0].rect.width + hvLayout.spacing; } } } else if (_layoutGroup is GridLayoutGroup) { GridLayoutGroup gridLayout = (GridLayoutGroup)_layoutGroup; _constraintCount = gridLayout.constraintCount; if (_isVertical) { _space = gridLayout.spacing.y; _itemSize = gridLayout.cellSize.y + _space; } else { _space = gridLayout.spacing.x; _itemSize = gridLayout.cellSize.x + _space; } } } else { Debug.LogErrorFormat("<WrapContent> {0}:缺少Layout!", name); } }
protected override bool DrawSidePanelContent(bool hasChanged) { var outputSequenceLength = m_SerializedObject.FindProperty("outputSequenceLength"); var syncFrame = m_SerializedObject.FindProperty("syncFrame"); EditorGUI.BeginChangeCheck(); int sync = syncFrame.intValue; int newSync = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Input Sync Frame|The frame from input sequence that will be used at start and end of the output sequence."), sync, 0 + outputSequenceLength.intValue, InputSequence.length - outputSequenceLength.intValue); if (newSync != sync) { newSync = Mathf.Clamp(newSync, 0 + outputSequenceLength.intValue, InputSequence.length - outputSequenceLength.intValue); syncFrame.intValue = newSync; } int length = outputSequenceLength.intValue; int newlength = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Output Sequence Length|How many frames will be in the output sequence?"), length, 2, (InputSequence.length / 2) + 1); if (newlength != length) { newlength = Mathf.Min(newlength, Mathf.Max(1, (InputSequence.length / 2))); outputSequenceLength.intValue = newlength; syncFrame.intValue = Mathf.Clamp(syncFrame.intValue, 0 + outputSequenceLength.intValue, InputSequence.length - outputSequenceLength.intValue); } float seqRatio = -1.0f; if (m_ProcessorStack.imageSequencer.previewCanvas.sequence.processor == this) { seqRatio = (m_ProcessorStack.imageSequencer.previewCanvas.numFrames > 1)? (float)m_ProcessorStack.imageSequencer.previewCanvas.currentFrameIndex / (m_ProcessorStack.imageSequencer.previewCanvas.numFrames - 1) : 0.0f; } // Draw Preview GUILayout.Label(VFXToolboxGUIUtility.Get("Mix Curve")); Rect preview_rect; using (new GUILayout.HorizontalScope()) { preview_rect = GUILayoutUtility.GetRect(200, 80); } EditorGUI.DrawRect(preview_rect, new Color(0.0f, 0.0f, 0.0f, 0.25f)); Rect gradient_rect = new RectOffset(40, 16, 0, 16).Remove(preview_rect); float width = gradient_rect.width; float height = gradient_rect.height; Color topTrackColor = new Color(1.0f, 0.8f, 0.25f); Color bottomTrackColor = new Color(0.25f, 0.8f, 1.0f); using (new GUI.ClipScope(preview_rect)) { GUI.color = topTrackColor; Handles.color = topTrackColor; GUI.Label(new Rect(0, 0, 32, 16), "In:", VFXToolboxStyles.miniLabel); Handles.DrawLine(new Vector3(72, 8), new Vector3(width + 40 - 32, 8)); GUI.color = bottomTrackColor; Handles.color = bottomTrackColor; GUI.Label(new Rect(0, height - 16, 32, 16), "In:", VFXToolboxStyles.miniLabel); Handles.DrawLine(new Vector3(72, height - 8), new Vector3(width + 40 - 32, height - 8)); GUI.color = Color.white; Handles.color = Color.white; GUI.Label(new Rect(0, height, 32, 16), "Out:", VFXToolboxStyles.miniLabel); GUI.Label(new Rect(40, height, 32, 16), "1", VFXToolboxStyles.miniLabel); GUI.Label(new Rect(width + 40 - 32, height, 32, 16), length.ToString(), VFXToolboxStyles.miniLabelRight); Handles.DrawLine(new Vector3(72, height + 8), new Vector3(width + 40 - 32, height + 8)); } AnimationCurve curve = m_SerializedObject.FindProperty("curve").animationCurveValue; using (new GUI.ClipScope(gradient_rect)) { int seqLen = OutputSequence.length; int syncF = syncFrame.intValue; float w = Mathf.Ceil((float)width / seqLen); for (int i = 0; i < seqLen; i++) { float t = (float)i / seqLen; Color blended = Color.Lerp(bottomTrackColor, topTrackColor, curve.Evaluate(t)); EditorGUI.DrawRect(new Rect(i * w, 18, w, height - 36), blended); } GUI.color = topTrackColor; GUI.Label(new Rect(0, 0, 32, 16), (syncF - seqLen + 1).ToString(), VFXToolboxStyles.miniLabel); GUI.Label(new Rect(width - 32, 0, 32, 16), (syncF).ToString(), VFXToolboxStyles.miniLabelRight); GUI.color = bottomTrackColor; GUI.Label(new Rect(0, height - 16, 32, 16), (syncF + 1).ToString(), VFXToolboxStyles.miniLabel); GUI.Label(new Rect(width - 32, height - 16, 32, 16), (syncF + seqLen).ToString(), VFXToolboxStyles.miniLabelRight); GUI.color = Color.white; } // If previewing current sequence : draw trackbar if (seqRatio >= 0.0f) { Handles.color = Color.white; Handles.DrawLine(new Vector3(gradient_rect.xMin + seqRatio * gradient_rect.width, preview_rect.yMin), new Vector3(gradient_rect.xMin + seqRatio * gradient_rect.width, preview_rect.yMax)); } // Curve Drawer if (m_CurveDrawer.OnGUILayout()) { hasChanged = true; } if (EditorGUI.EndChangeCheck()) { hasChanged = true; } if (curve.keys.Length < 2 || curve.keys[0].value > 0.0f || curve.keys[curve.keys.Length - 1].value < 1.0f) { EditorGUILayout.HelpBox("Warning : Mix Curve must have first key's value equal 0 and last key's value equal 1 to achieve looping", MessageType.Warning); } return(hasChanged); }
/// <summary> /// Sets the offsets of the UI component from its anchors. Positive for each value /// denotes towards the component center, and negative away from the component center. /// </summary> /// <param name="uiElement">The UI element to modify.</param> /// <param name="border">The offset of each corner from the anchors.</param> /// <returns>The UI element, for call chaining.</returns> public static GameObject SetAnchorOffsets(GameObject uiElement, RectOffset border) { return(SetAnchorOffsets(uiElement, border.left, border.right, border.top, border. bottom)); }
public static RectOffset Scale(this RectOffset r, float scale) { return(new RectOffset(Mathf.RoundToInt(r.left * scale), Mathf.RoundToInt(r.right * scale), Mathf.RoundToInt(r.top * scale), Mathf.RoundToInt(r.bottom * scale))); }
public static GUIStyleMarginScope StyleMargin(GUIStyle style, RectOffset margin, RectOffset padding, RectOffset overflow) { return(new GUIStyleMarginScope(style, margin, padding, overflow)); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type != EventType.Repaint) { return; } if (m_Styles == null) { m_Styles = new Styles(); } GameObject go = target as GameObject; RectTransform rect = go.transform as RectTransform; if (rect == null) { return; } // Apply padding RectOffset previewPadding = new RectOffset(-5, -5, -5, -5); r = previewPadding.Add(r); // Prepare rects for columns r.height = EditorGUIUtility.singleLineHeight; Rect labelRect = r; Rect valueRect = r; Rect sourceRect = r; labelRect.width = kLabelWidth; valueRect.xMin += kLabelWidth; valueRect.width = kValueWidth; sourceRect.xMin += kLabelWidth + kValueWidth; // Headers GUI.Label(labelRect, "Property", m_Styles.headerStyle); GUI.Label(valueRect, "Value", m_Styles.headerStyle); GUI.Label(sourceRect, "Source", m_Styles.headerStyle); labelRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; valueRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; sourceRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // Prepare reusable variable for out argument ILayoutElement source = null; // Show properties ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Min Width", LayoutUtility.GetLayoutProperty(rect, e => e.minWidth, 0, out source).ToString(), source); ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Min Height", LayoutUtility.GetLayoutProperty(rect, e => e.minHeight, 0, out source).ToString(), source); ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Preferred Width", LayoutUtility.GetLayoutProperty(rect, e => e.preferredWidth, 0, out source).ToString(), source); ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Preferred Height", LayoutUtility.GetLayoutProperty(rect, e => e.preferredHeight, 0, out source).ToString(), source); float flexible = 0; flexible = LayoutUtility.GetLayoutProperty(rect, e => e.flexibleWidth, 0, out source); ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Flexible Width", flexible > 0 ? ("enabled (" + flexible.ToString() + ")") : "disabled", source); flexible = LayoutUtility.GetLayoutProperty(rect, e => e.flexibleHeight, 0, out source); ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Flexible Height", flexible > 0 ? ("enabled (" + flexible.ToString() + ")") : "disabled", source); if (!rect.GetComponent <LayoutElement>()) { Rect noteRect = new Rect(labelRect.x, labelRect.y + 10, r.width, EditorGUIUtility.singleLineHeight); GUI.Label(noteRect, "Add a LayoutElement to override values.", m_Styles.labelStyle); } }
protected void DrawInspectedRect(Rect instructionRect) { var totalRect = GUILayoutUtility.GetRect(0, 100); var reserveTopFieldHeight = Mathf.CeilToInt(EditorGUI.kSingleLineHeight * 2 + EditorGUI.kControlVerticalSpacing); var reserveBottomFieldHeight = Mathf.CeilToInt(EditorGUI.kSingleLineHeight); var reserveFieldWidth = 100; var fieldsArea = new RectOffset(50, reserveFieldWidth, reserveTopFieldHeight, reserveBottomFieldHeight); var visualRect = fieldsArea.Remove(totalRect); float aspectRatio = instructionRect.width / instructionRect.height; var aspectedRect = new Rect(); var dummy = new Rect(); GUI.CalculateScaledTextureRects(visualRect, ScaleMode.ScaleToFit, aspectRatio, ref aspectedRect, ref dummy); visualRect = aspectedRect; visualRect.width = Mathf.Max(80, visualRect.width); visualRect.height = Mathf.Max(EditorGUI.kSingleLineHeight + 10, visualRect.height); var startPointFieldRect = new Rect(); startPointFieldRect.height = EditorGUI.kSingleLineHeight; startPointFieldRect.width = fieldsArea.left * 2; startPointFieldRect.y = visualRect.y - fieldsArea.top; startPointFieldRect.x = visualRect.x - startPointFieldRect.width / 2f; var endPointFieldRect = new Rect { height = EditorGUI.kSingleLineHeight, width = fieldsArea.right * 2, y = visualRect.yMax }; endPointFieldRect.x = visualRect.xMax - endPointFieldRect.width / 2f; var widthMarkersArea = new Rect { x = visualRect.x, y = startPointFieldRect.yMax + EditorGUI.kControlVerticalSpacing, width = visualRect.width, height = EditorGUI.kSingleLineHeight }; var widthFieldRect = widthMarkersArea; widthFieldRect.width = widthMarkersArea.width / 3; widthFieldRect.x = widthMarkersArea.x + (widthMarkersArea.width - widthFieldRect.width) / 2f; var heightMarkerArea = visualRect; heightMarkerArea.x = visualRect.xMax; heightMarkerArea.width = EditorGUI.kSingleLineHeight; var heightFieldRect = heightMarkerArea; heightFieldRect.height = EditorGUI.kSingleLineHeight; heightFieldRect.width = fieldsArea.right; heightFieldRect.y = heightFieldRect.y + (heightMarkerArea.height - heightFieldRect.height) / 2f; //Draw TopLeft point GUI.Label(startPointFieldRect, string.Format("({0},{1})", instructionRect.x, instructionRect.y), Styles.centeredLabel); Handles.color = new Color(1, 1, 1, 0.5f); //Draw Width markers and value var startP = new Vector3(widthMarkersArea.x, widthFieldRect.y); var endP = new Vector3(widthMarkersArea.x, widthFieldRect.yMax); Handles.DrawLine(startP, endP); startP.x = endP.x = widthMarkersArea.xMax; Handles.DrawLine(startP, endP); startP.x = widthMarkersArea.x; startP.y = endP.y = Mathf.Lerp(startP.y, endP.y, .5f); endP.x = widthFieldRect.x; Handles.DrawLine(startP, endP); startP.x = widthFieldRect.xMax; endP.x = widthMarkersArea.xMax; Handles.DrawLine(startP, endP); GUI.Label(widthFieldRect, instructionRect.width.ToString(), Styles.centeredLabel); //Draw Height markers and value startP = new Vector3(heightMarkerArea.x, heightMarkerArea.y); endP = new Vector3(heightMarkerArea.xMax, heightMarkerArea.y); Handles.DrawLine(startP, endP); startP.y = endP.y = heightMarkerArea.yMax; Handles.DrawLine(startP, endP); startP.x = endP.x = Mathf.Lerp(startP.x, endP.x, .5f); startP.y = heightMarkerArea.y; endP.y = heightFieldRect.y; Handles.DrawLine(startP, endP); startP.y = heightFieldRect.yMax; endP.y = heightMarkerArea.yMax; Handles.DrawLine(startP, endP); GUI.Label(heightFieldRect, instructionRect.height.ToString()); GUI.Label(endPointFieldRect, string.Format("({0},{1})", instructionRect.xMax, instructionRect.yMax), Styles.centeredLabel); //Draws the rect GUI.Box(visualRect, GUIContent.none); }
/// <summary> /// Adds a line to the list. /// </summary> /// <param name="leftContent">Left content.</param> /// <param name="rightContent">Right content.</param> /// <param name="padding">Row padding.</param> /// <param name="customStyle">Custom style name.</param> public void AddLine(string leftContent, string rightContent, RectOffset padding, string customStyle) { // Add the line to the list this.lineList.Add(new Line(leftContent, rightContent, true, padding, LineStyle.Custom, customStyle)); }
private void InitializeGUIStyles() { this.guiStyles = new GUIStyles(); this.guiStyles.Icon = GUIStyle.none; this.guiStyles.OriginalNameLabelUnModified = EditorStyles.label; this.guiStyles.OriginalNameLabelUnModified.richText = true; this.guiStyles.OriginalNameLabelWhenModified = EditorStyles.boldLabel; this.guiStyles.OriginalNameLabelWhenModified.richText = true; this.guiStyles.NewNameLabelUnModified = EditorStyles.label; this.guiStyles.NewNameLabelUnModified.richText = true; this.guiStyles.NewNameLabelModified = EditorStyles.boldLabel; this.guiStyles.NewNameLabelModified.richText = true; this.guiStyles.FinalNameLabelUnModified = EditorStyles.label; this.guiStyles.FinalNameLabelUnModified.richText = true; this.guiStyles.FinalNameLabelWhenModified = EditorStyles.boldLabel; this.guiStyles.FinalNameLabelWhenModified.richText = true; this.guiStyles.DropPrompt = new GUIStyle(EditorStyles.label); this.guiStyles.DropPrompt.alignment = TextAnchor.MiddleCenter; this.guiStyles.DropPromptRepeat = new GUIStyle(EditorStyles.label); this.guiStyles.DropPromptRepeat.alignment = TextAnchor.MiddleCenter; this.guiStyles.DropPromptHint = EditorStyles.centeredGreyMiniLabel; this.guiStyles.RenameSuccessPrompt = new GUIStyle(EditorStyles.label); this.guiStyles.RenameSuccessPrompt.alignment = TextAnchor.MiddleCenter; this.guiStyles.RenameSuccessPrompt.richText = true; this.guiStyles.RenameSuccessPrompt.fontSize = 16; var previewHeaderStyle = new GUIStyle(EditorStyles.toolbar); var previewHeaderMargin = new RectOffset(); previewHeaderMargin = previewHeaderStyle.margin; previewHeaderMargin.left = 1; previewHeaderMargin.right = 1; previewHeaderStyle.margin = previewHeaderMargin; this.guiStyles.PreviewHeader = previewHeaderStyle; if (EditorGUIUtility.isProSkin) { string styleName = string.Empty; #if UNITY_5 styleName = "AnimationCurveEditorBackground"; #else styleName = "CurveEditorBackground"; #endif this.guiStyles.PreviewScroll = new GUIStyle(styleName); this.guiStyles.PreviewRowBackgroundEven = new Color(0.3f, 0.3f, 0.3f, 0.2f); this.guiStyles.InsertionTextColor = new Color32(6, 214, 160, 255); this.guiStyles.DeletionTextColor = new Color32(239, 71, 111, 255); } else { this.guiStyles.PreviewScroll = EditorStyles.textArea; this.guiStyles.PreviewRowBackgroundEven = new Color(0.6f, 0.6f, 0.6f, 0.2f); this.guiStyles.InsertionTextColor = new Color32(0, 140, 104, 255); this.guiStyles.DeletionTextColor = new Color32(189, 47, 79, 255); } this.guiStyles.PreviewRowBackgroundOdd = Color.clear; var copyrightStyle = new GUIStyle(EditorStyles.miniLabel); copyrightStyle.alignment = TextAnchor.MiddleRight; this.guiStyles.CopyrightLabel = copyrightStyle; }
/// <summary> /// Adds a line to the list. /// </summary> /// <param name="leftContent">Left content.</param> /// <param name="rightContent">Right content.</param> /// <param name="padding">Row padding.</param> public void AddLine(string leftContent, string rightContent, RectOffset padding) { this.lineList.Add(new Line(leftContent, rightContent, true, padding, LineStyle.Default, "")); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type != EventType.Repaint) { return; } if (m_Info == null || m_Info.Count == 0) { return; } if (m_Styles == null) { m_Styles = new Styles(); } // Get required label size for the names of the information values we're going to show // There are two columns, one with label for the name of the info and the next for the value Vector2 maxNameLabelSize = new Vector2(140, 16); Vector2 maxValueLabelSize = GetMaxNameLabelSize(); //Apply padding RectOffset previewPadding = new RectOffset(-5, -5, -5, -5); r = previewPadding.Add(r); //Centering float initialX = r.x + 10; float initialY = r.y + 10; Rect labelRect = new Rect(initialX, initialY, maxNameLabelSize.x, maxNameLabelSize.y); Rect idLabelRect = new Rect(maxNameLabelSize.x, initialY, maxValueLabelSize.x, maxValueLabelSize.y); foreach (var info in m_Info) { GUI.Label(labelRect, info.name, m_Styles.labelStyle); GUI.Label(idLabelRect, info.value, m_Styles.componentName); labelRect.y += labelRect.height; labelRect.x = initialX; idLabelRect.y += idLabelRect.height; } // Show behaviours list in a different way than the name/value pairs above float lastY = labelRect.y; if (m_Behaviours != null && m_Behaviours.Count > 0) { Vector2 maxBehaviourLabelSize = GetMaxBehaviourLabelSize(); Rect behaviourRect = new Rect(initialX, labelRect.y + 10, maxBehaviourLabelSize.x, maxBehaviourLabelSize.y); GUI.Label(behaviourRect, TextUtility.TextContent("Network Behaviours"), m_Styles.labelStyle); behaviourRect.x += 20; // indent names behaviourRect.y += behaviourRect.height; foreach (var info in m_Behaviours) { if (info.behaviour == null) { // could be the case in the editor after existing play mode. continue; } if (info.behaviour.enabled) { GUI.Label(behaviourRect, info.name, m_Styles.componentName); } else { GUI.Label(behaviourRect, info.name, m_Styles.disabledName); } behaviourRect.y += behaviourRect.height; lastY = behaviourRect.y; } if (m_Identity.observers != null && m_Identity.observers.Count > 0) { Rect observerRect = new Rect(initialX, lastY + 10, 200, 20); GUI.Label(observerRect, TextUtility.TextContent("Network observers"), m_Styles.labelStyle); observerRect.x += 20; // indent names observerRect.y += observerRect.height; foreach (var info in m_Identity.observers) { GUI.Label(observerRect, info.address + ":" + info.connectionId, m_Styles.componentName); observerRect.y += observerRect.height; lastY = observerRect.y; } } if (m_Identity.clientAuthorityOwner != null) { Rect ownerRect = new Rect(initialX, lastY + 10, 400, 20); GUI.Label(ownerRect, TextUtility.TextContent("Client Authority: " + m_Identity.clientAuthorityOwner), m_Styles.labelStyle); } } }
/// <summary> /// Adds a single column line to the list. /// </summary> /// <param name="content">Content.</param> /// <param name="padding">Row padding.</param> public void AddLine(string content, RectOffset padding) { this.lineList.Add(new Line(content, string.Empty, true, padding, LineStyle.Default, "")); }
void ListArea(Rect rect, PresetLibrary lib, object newPresetObject) { if (lib == null) { return; } Event evt = Event.current; if (m_PresetLibraryFileLocation == PresetFileLocation.ProjectFolder && evt.type == EventType.Repaint) { m_IsOpenForEdit = AssetDatabase.IsOpenForEdit(pathWithExtension, StatusQueryOptions.UseCachedIfPossible); } else if (m_PresetLibraryFileLocation == PresetFileLocation.PreferencesFolder) { m_IsOpenForEdit = true; } if (!m_IsOpenForEdit) { Rect versionControlRect = new Rect(rect.x, rect.yMax - versionControlAreaHeight, rect.width, versionControlAreaHeight); VersionControlArea(versionControlRect); rect.height -= versionControlAreaHeight; } // To ensure we setup grid to visible rect we need to run once to check if scrollbar is taking up screen estate. // To optimize the first width is based on the last frame and we therefore most likely will only run once. for (int i = 0; i < 2; i++) { gridWidth = m_ShowedScrollBarLastFrame ? rect.width - 17 : rect.width; SetupGrid(gridWidth, lib.Count()); bool isShowingScrollBar = m_Grid.height > rect.height; if (isShowingScrollBar == m_ShowedScrollBarLastFrame) { break; } else { m_ShowedScrollBarLastFrame = isShowingScrollBar; } } // Draw horizontal lines for scrollview content to clip against if ((m_ShowedScrollBarLastFrame || alwaysShowScrollAreaHorizontalLines) && Event.current.type == EventType.Repaint) { Rect scrollEdgeRect = new RectOffset(1, 1, 1, 1).Add(rect); scrollEdgeRect.height = 1; EditorGUI.DrawRect(scrollEdgeRect, new Color(0, 0, 0, 0.3f)); scrollEdgeRect.y += rect.height + 1; EditorGUI.DrawRect(scrollEdgeRect, new Color(0, 0, 0, 0.3f)); } Rect contentRect = new Rect(0, 0, 1, m_Grid.height); m_State.m_ScrollPosition = GUI.BeginScrollView(rect, m_State.m_ScrollPosition, contentRect); { int startIndex, endIndex; float yOffset = 0f; int maxIndex = m_ShowAddNewPresetItem ? lib.Count() : lib.Count() - 1; bool isGridVisible = m_Grid.IsVisibleInScrollView(rect.height, m_State.m_ScrollPosition.y, yOffset, maxIndex, out startIndex, out endIndex); bool drawDragInsertionMarker = false; if (isGridVisible) { // Handle renaming overlay before item handling because its needs mouse input first to end renaming if clicked outside if (GetRenameOverlay().IsRenaming() && !GetRenameOverlay().isWaitingForDelay) { if (!m_State.m_RenameOverlay.OnGUI()) { EndRename(); evt.Use(); } Repaint(); } for (int i = startIndex; i <= endIndex; ++i) { int itemControlID = i + 1000000; Rect itemRect = m_Grid.CalcRect(i, yOffset); Rect previewRect = itemRect; Rect labelRect = itemRect; switch (m_State.itemViewMode) { case PresetLibraryEditorState.ItemViewMode.List: previewRect.width = m_State.m_PreviewHeight * m_PreviewAspect; labelRect.x += previewRect.width + 8f; labelRect.width -= previewRect.width + 10f; labelRect.height = kGridLabelHeight; labelRect.y = itemRect.yMin + (itemRect.height - kGridLabelHeight) * 0.5f; break; case PresetLibraryEditorState.ItemViewMode.Grid: // only preview is shown: no label break; } // Add new preset button if (m_ShowAddNewPresetItem && i == lib.Count()) { CreateNewPresetButton(previewRect, newPresetObject, lib, m_IsOpenForEdit); continue; } // Rename overlay bool isRenamingThisItem = IsRenaming(i); if (isRenamingThisItem) { Rect renameRect = labelRect; renameRect.y -= 1f; renameRect.x -= 1f; // adjustment to fit perfectly m_State.m_RenameOverlay.editFieldRect = renameRect; } // Handle event switch (evt.type) { case EventType.Repaint: if (m_State.m_HoverIndex == i) { if (itemRect.Contains(evt.mousePosition)) { // TODO: We need a better hover effect so disabling for now... //if (!GetRenameOverlay().IsRenaming ()) // DrawHoverEffect (itemRect, false); } else { m_State.m_HoverIndex = -1; } } if (m_DragState.draggingIndex == i || GUIUtility.hotControl == itemControlID) { DrawHoverEffect(itemRect, false); } lib.Draw(previewRect, i); if (!isRenamingThisItem && drawLabels) { GUI.Label(labelRect, GUIContent.Temp(lib.GetName(i))); } if (m_DragState.dragUponIndex == i && m_DragState.draggingIndex != m_DragState.dragUponIndex) { drawDragInsertionMarker = true; } // We delete presets on alt-click if (GUIUtility.hotControl == 0 && Event.current.alt && m_IsOpenForEdit) { EditorGUIUtility.AddCursorRect(itemRect, MouseCursor.ArrowMinus); } break; case EventType.MouseDown: if (evt.button == 0 && itemRect.Contains(evt.mousePosition)) { GUIUtility.hotControl = itemControlID; if (evt.clickCount == 1) { m_ItemClickedCallback(evt.clickCount, lib.GetPreset(i)); evt.Use(); } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == itemControlID && m_IsOpenForEdit) { DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlID); if (delay.CanStartDrag()) { // Start drag DragAndDrop.PrepareStartDrag(); DragAndDrop.SetGenericData("DraggingPreset", i); DragAndDrop.StartDrag(""); m_DragState.draggingIndex = i; m_DragState.dragUponIndex = i; GUIUtility.hotControl = 0; } evt.Use(); } break; case EventType.DragUpdated: case EventType.DragPerform: { Rect dragRect = GetDragRect(itemRect); if (dragRect.Contains(evt.mousePosition)) { m_DragState.dragUponIndex = i; m_DragState.dragUponRect = itemRect; if (m_State.itemViewMode == PresetLibraryEditorState.ItemViewMode.List) { m_DragState.insertAfterIndex = ((evt.mousePosition.y - dragRect.y) / dragRect.height) > 0.5f; } else { m_DragState.insertAfterIndex = ((evt.mousePosition.x - dragRect.x) / dragRect.width) > 0.5f; } bool perform = evt.type == EventType.DragPerform; if (perform) { if (m_DragState.draggingIndex >= 0) { MovePreset(m_DragState.draggingIndex, m_DragState.dragUponIndex, m_DragState.insertAfterIndex); DragAndDrop.AcceptDrag(); } ClearDragState(); } DragAndDrop.visualMode = DragAndDropVisualMode.Move; evt.Use(); } } break; case EventType.DragExited: if (m_DragState.IsDragging()) { ClearDragState(); evt.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == itemControlID) { GUIUtility.hotControl = 0; if (evt.button == 0 && itemRect.Contains(evt.mousePosition)) { if (Event.current.alt && m_IsOpenForEdit) { DeletePreset(i); evt.Use(); } } } break; case EventType.ContextClick: if (itemRect.Contains(evt.mousePosition)) { PresetContextMenu.Show(m_IsOpenForEdit, i, newPresetObject, this); evt.Use(); } break; case EventType.MouseMove: if (itemRect.Contains(evt.mousePosition)) { if (m_State.m_HoverIndex != i) { m_State.m_HoverIndex = i; Repaint(); } } else if (m_State.m_HoverIndex == i) { m_State.m_HoverIndex = -1; Repaint(); } break; } } // end foreach item // Draw above all items if (drawDragInsertionMarker) { DrawDragInsertionMarker(); } } } GUI.EndScrollView(); }
/// <summary> /// Adds a single column line to the list. /// </summary> /// <param name="content">Content.</param> /// <param name="padding">Row padding.</param> public void AddLine(string content, RectOffset padding, string customStyle) { this.lineList.Add(new Line(content, string.Empty, true, padding, LineStyle.Custom, customStyle)); }
public static UIButton CreateBlueButton(UIComponent parent, string text, float textScale, UIHorizontalAlignment textHorizontalAlignment, UIVerticalAlignment textVerticalAlignment, RectOffset textPadding, Vector2 size, Vector3 relativePosition) { UIButton _button = parent.AddUIComponent <UIButton>(); _button.normalBgSprite = "ButtonMenu"; _button.focusedBgSprite = "ButtonMenuFocused"; _button.hoveredBgSprite = "ButtonMenuHovered"; _button.pressedBgSprite = "ButtonMenuPressed"; _button.disabledBgSprite = "ButtonMenuDisabled"; _button.text = text; _button.textScale = textScale; _button.textPadding = textPadding; _button.textHorizontalAlignment = textHorizontalAlignment; _button.textVerticalAlignment = textVerticalAlignment; _button.textColor = new Color32(255, 255, 255, 255); _button.disabledTextColor = new Color32(255, 255, 255, 128); _button.wordWrap = true; _button.playAudioEvents = true; _button.size = size; _button.relativePosition = relativePosition; return(_button); }
protected RectOffset wScale(RectOffset v) { return(new RectOffset(wScale(v.left), wScale(v.right), wScale(v.top), wScale(v.bottom))); }
public AutoStyleMargin(GUIStyle style, RectOffset margin, RectOffset padding) : this(style, margin, padding, style.overflow) { }
public static string Serialize(this RectOffset current, string separator = "-") { return(current.top + separator + current.right + separator + current.bottom + separator + current.left); }