internal static void ControlHighlightGUI(GUIView self) { if ((Object)Highlighter.s_View == (Object)null || (Object)self.window != (Object)Highlighter.s_View.window || (!Highlighter.activeVisible || Highlighter.searching)) { return; } if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "HandleControlHighlight") { if (!self.screenPosition.Overlaps(Highlighter.s_RepaintRegion)) { return; } self.Repaint(); } else { if (Event.current.type != EventType.Repaint) { return; } Rect position = Highlighter.highlightStyle.padding.Add(GUIUtility.ScreenToGUIRect(Highlighter.activeRect)); float num1 = (float)(((double)Mathf.Cos((float)((double)Highlighter.s_HighlightElapsedTime * 3.14159274101257 * 2.0 * 0.449999988079071)) + 1.0) * 0.5); float num2 = Mathf.Min(1f, (float)(0.00999999977648258 + (double)Highlighter.s_HighlightElapsedTime / 0.330000013113022)); float num3 = num2 + Mathf.Sin(num2 * 3.141593f) * 0.5f; Vector2 scale = (Vector2.one + new Vector2((float)(((double)position.width + 5.0) / (double)position.width - 1.0), (float)(((double)position.height + 5.0) / (double)position.height - 1.0)) * num1) * num3; Matrix4x4 matrix = GUI.matrix; Color color = GUI.color; GUI.color = new Color(1f, 1f, 1f, (float)(0.800000011920929 - 0.300000011920929 * (double)num1)); GUIUtility.ScaleAroundPivot(scale, position.center); Highlighter.highlightStyle.Draw(position, false, false, false, false); GUI.color = color; GUI.matrix = matrix; } }
/** * GUIまわりの記述. */ public void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } // サーバとの接続が終わってなければ何もしない if (!MonobitNetwork.isConnect) { return; } // まだルーム未入室の場合 else if (!MonobitNetwork.inRoom) { OnGUI_OutOfRoom(); } // ルーム入室中の場合 else { OnGUI_InRoom(); } }
private void OnGUI() { if (m_Info != null && m_DebugGui) { GUI.depth = -1000; GUI.matrix = Matrix4x4.TRS(new Vector3((float)m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(1.5f, 1.5f, 1f)); GUILayout.BeginVertical("box", GUILayout.MaxWidth(180f)); GUILayout.Label(Path.GetFileName(m_VideoPath)); GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + "x" + m_Info.GetVideoHeight() + "@" + m_Info.GetVideoFrameRate().ToString("F2")); GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s"); GUILayout.Label("Rate: " + m_Info.GetVideoDisplayRate().ToString("F2") + "Hz"); if (TextureProducer != null && TextureProducer.GetTexture() != null) { GUILayout.BeginHorizontal(); Rect rect = GUILayoutUtility.GetRect(32f, 32f); GUILayout.Space(8f); Rect rect2 = GUILayoutUtility.GetRect(32f, 32f); Matrix4x4 matrix = GUI.matrix; if (TextureProducer.RequiresVerticalFlip()) { GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + rect.height / 2f)); } GUI.DrawTexture(rect, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, alphaBlend: false); GUI.DrawTexture(rect2, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, alphaBlend: true); GUI.matrix = matrix; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } }
void OnGUI() { #if !FONDI_BUILD_RELEASE var scale = new Vector2( (float)Screen.width / _refWidth, (float)Screen.width / _refWidth); GUIUtility.ScaleAroundPivot(scale, Vector2.zero); if (!_enableGui) { return; } // Space for safe area. GUILayout.Space(30); GUI.skin.label.fontSize = 9; GUI.skin.toggle.fontSize = 9; GUILayout.BeginHorizontal(); var rowIndex = 0; foreach (var entries in _entries) // raw { GUILayout.BeginVertical(); if (rowIndex++ == 1) // middle row { _foldAll = GUILayout.Toggle(_foldAll, "Fold All"); } foreach (DictionaryEntry kv in entries) { var v = (Tuple)kv.Value; GUILayout.BeginVertical("box"); v.Enabled = GUILayout.Toggle(v.Enabled, v.Name); if (v.Enabled && !_foldAll) { try { v.OnGui(); } catch (Exception e) { Debug.LogException(e); } } GUILayout.EndVertical(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); #endif }
/// <summary> /// This method draws the current error message and automatically pops new error messages /// from the queue if the life time of the current error is over /// </summary> public void Draw() { int smallerScreenDimension = Screen.width < Screen.height ? Screen.width : Screen.height; float deviceDependentScale = smallerScreenDimension / 480f; Vector2 screenCenter = new Vector2(Screen.width / 2f, Screen.height / 2f); GUIUtility.ScaleAroundPivot(new Vector2(deviceDependentScale, deviceDependentScale), screenCenter); GUILayout.BeginArea(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 120, 300, 240)); GUI.Box(new Rect(0, 0, 300, 50), mCurrentError.Title, mErrorTitleMessage); GUI.Box(new Rect(0, 50, 300, 190), string.Empty, mErrorBodyMessage); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.Label(new Rect(1, 55, 300, 135), mCurrentError.Text, mErrorBodyMessage); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); DrawPopUp(); GUILayout.EndArea(); // reset scale after drawing GUIUtility.ScaleAroundPivot(Vector2.one, screenCenter); }
/// <summary> /// Draw the Image preview. /// </summary> public override void OnPreviewGUI(Rect drawArea, GUIStyle background) { DisplayUGUI rawImage = target as DisplayUGUI; Texture tex = rawImage.mainTexture; if (tex == null) { return; } // Create the texture rectangle that is centered inside rect. Rect outerRect = drawArea; Matrix4x4 m = GUI.matrix; // Flip the image vertically if (rawImage.HasValidTexture()) { if (rawImage._mediaPlayer.TextureProducer.RequiresVerticalFlip()) { GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, outerRect.y + (outerRect.height / 2))); } } EditorGUI.DrawTextureTransparent(outerRect, tex, ScaleMode.ScaleToFit); //, outer.width / outer.height); //SpriteDrawUtility.DrawSprite(tex, rect, outer, rawImage.uvRect, rawImage.canvasRenderer.GetColor()); GUI.matrix = m; }
void OnGUI() { if (m_Info != null && m_DebugGui) { GUI.depth = -1; GUI.matrix = Matrix4x4.TRS(new Vector3(m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(s_GuiScale, s_GuiScale, 1.0f)); GUILayout.BeginVertical("box", GUILayout.MaxWidth(s_GuiWidth)); GUILayout.Label(System.IO.Path.GetFileName(m_VideoPath)); GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + " x " + m_Info.GetVideoHeight()); GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s"); GUILayout.Label("Rate: " + m_Info.GetVideoPlaybackRate().ToString("F2") + "Hz"); if (TextureProducer != null && TextureProducer.GetTexture() != null) { // Show texture without and with alpha blending GUILayout.BeginHorizontal(); Rect r1 = GUILayoutUtility.GetRect(32f, 32f); GUILayout.Space(8f); Rect r2 = GUILayoutUtility.GetRect(32f, 32f); if (TextureProducer.RequiresVerticalFlip()) { GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, r1.y + (r1.height / 2))); } GUI.DrawTexture(r1, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, false); GUI.DrawTexture(r2, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, true); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } }
void OnGUI() { GUIUtility.ScaleAroundPivot(guiScale, Vector2.zero); if (isOnGUI == false) { return; } if (STScene.getMode() == SCENE_MODE.TEST_ANIM) { windowType = windowShowContentType.levelGeneration; windowRect = GUI.Window(0, windowRect, windowFunction, "Levels Manager"); return; } guiModeButton(); if (editMode == true) { guiEditToolBarButtons(); if (isDialogHiden == false) { windowRect = GUI.Window(0, windowRect, windowFunction, "Levels Manager"); } } else { guiPlayToolBarButtons(); } }
/// <summary> /// Print string values for all currently tracked words. /// </summary> private void DrawWordList() { var sortedWords = mSortedWords; var textBoxWidth = Screen.width * mTextboxWidth; var textBoxHeight = (Screen.height - mDetectionAndTrackingRect.yMax) * mTextboxHeight; var textBoxOffsetLeft = (Screen.width - textBoxWidth) * 0.5f; var textBoxOffsetTop = mDetectionAndTrackingRect.yMax + (Screen.height - (textBoxHeight + mDetectionAndTrackingRect.yMax)) * 0.5f; var textBox = new Rect(textBoxOffsetLeft, textBoxOffsetTop, textBoxWidth, textBoxHeight); Rect wordBox; var scale = ComputeScaleForWordList(mSortedWords.Count, textBox, out wordBox); var oldMatrix = GUI.matrix; GUIUtility.ScaleAroundPivot(new Vector2(scale, scale), new Vector2(Screen.width * 0.5f, textBoxOffsetTop)); wordBox.y += wordBox.height * mWordPadding; foreach (var word in sortedWords) { if ((wordBox.yMax - textBoxOffsetTop) * scale > textBox.height) { break; } GUI.Label(wordBox, word.Word.StringValue, mWordStyle); wordBox.y += (wordBox.height + wordBox.height * mWordPadding); } GUI.matrix = oldMatrix; }
public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width) { if (!_isInitialized) { return; } Matrix4x4 oldMatrix = GUI.matrix; Color oldColor = GUI.color; float angle = Vector3.Angle((pointB - pointA), Vector2.right); if (pointA.y > pointB.y) { angle = -angle; } GUI.color = color; GUIUtility.ScaleAroundPivot(new Vector2((pointB - pointA).magnitude, width), new Vector2(pointA.x, (pointA.y + 0.5f))); GUIUtility.RotateAroundPivot(angle, pointA); GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1f, 1f), _lineTexture); GUI.matrix = oldMatrix; GUI.color = oldColor; }
// main drawing function public static void Draw(Vector2 pointA, Vector2 pointB, Color color, float width) { d.i_M4x4 = GUI.matrix; if (!d.lineTex) { d.lineTex = d.patternTexture; } d.bColor = GUI.color; GUI.color = color; d.Angle = Vector3.Angle(pointB - pointA, Vector2.right); if (pointA.y > pointB.y) { d.Angle = -d.Angle; } d.vectorA.x = (pointB - pointA).magnitude; d.vectorA.y = width; d.vectorB.x = pointA.x; d.vectorB.y = pointA.y + 0.5f; GUIUtility.ScaleAroundPivot(d.vectorA, d.vectorB); GUIUtility.RotateAroundPivot(d.Angle, pointA); d.rectA.x = pointA.x; d.rectA.y = pointA.y; d.rectA.width = 1f; d.rectA.height = 1f; GUI.DrawTexture(d.rectA, d.lineTex); GUI.matrix = d.i_M4x4; GUI.color = d.bColor; }
static void DrawLineWindows(Vector2 pointA, Vector2 pointB, Color color, float width, bool antiAlias) { float m = (pointB - pointA).magnitude; if (m == 0f) { return; } Color savedColor = GUI.color; Matrix4x4 savedMatrix = GUI.matrix; if (antiAlias) { width *= 3; } float angle = Vector3.Angle(pointB - pointA, Vector2.right) * (pointA.y <= pointB.y ? 1 : -1); Vector3 dz = new Vector3(pointA.x, pointA.y, 0); GUI.color = color; GUI.matrix = translationMatrix(dz) * GUI.matrix; GUIUtility.ScaleAroundPivot(new Vector2(m, width), new Vector2(-0.5f, 0)); GUI.matrix = translationMatrix(-dz) * GUI.matrix; GUIUtility.RotateAroundPivot(angle, new Vector2(0, 0)); GUI.matrix = translationMatrix(dz + new Vector3(width / 2, -m / 2) * Mathf.Sin(angle * Mathf.Deg2Rad)) * GUI.matrix; GUI.DrawTexture(new Rect(0, 0, 1, 1), !antiAlias ? lineTex : adLineTex); GUI.matrix = savedMatrix; GUI.color = savedColor; }
private static void DrawObjectFieldLargeThumb(Rect position, int id, Object obj, GUIContent content) { GUIStyle thumbStyle = EditorStyles.objectFieldThumb; thumbStyle.Draw(position, GUIContent.none, id, DragAndDrop.activeControlID == id, position.Contains(Event.current.mousePosition)); if (obj != null && !showMixedValue) { Matrix4x4 guiMatrix = GUI.matrix; // Initial matrix is saved in order to be able to reset it to default bool isSprite = obj is Sprite; bool alphaIsTransparencyTex2D = (obj is Texture2D && (obj as Texture2D).alphaIsTransparency); Rect thumbRect = thumbStyle.padding.Remove(position); Texture2D t2d = AssetPreview.GetAssetPreview(obj); if (t2d != null) { // A checkerboard background is drawn behind transparent textures (for visibility) if (isSprite || t2d.alphaIsTransparency || alphaIsTransparencyTex2D) { GUI.DrawTexture(thumbRect, EditorGUI.transparentCheckerTexture, ScaleMode.StretchToFill, false); } // Draw asset preview (scaled to fit inside the frame) // GUIStyle.none.Draw is used to allow the asset preview to be caught by AutomatedWindow Vector2 defaultSize = Vector2.one * EditorGUI.kObjectFieldThumbnailHeight; GUIUtility.ScaleAroundPivot(thumbRect.size / defaultSize, thumbRect.position); thumbRect.size = defaultSize; // GUIStyle.none.Draw does not scale, the matrix does. Omitting this reports an incorrect Rect size. GUIStyle.none.Draw(thumbRect, t2d, false, false, false, false); GUI.matrix = guiMatrix; } else { // Preview not loaded -> Draw icon if (isSprite || alphaIsTransparencyTex2D) { // A checkerboard background is drawn behind transparent textures (for visibility) GUI.DrawTexture(thumbRect, EditorGUI.transparentCheckerTexture, ScaleMode.StretchToFill, false); GUI.DrawTexture(thumbRect, content.image, ScaleMode.StretchToFill, true); } else { DrawPreviewTexture(thumbRect, content.image); } // Keep repainting until the object field has a proper preview HandleUtility.Repaint(); } } else { GUIStyle s2 = thumbStyle.name + "Overlay"; BeginHandleMixedValueContentColor(); s2.Draw(position, content, id); EndHandleMixedValueContentColor(); } GUIStyle s3 = thumbStyle.name + "Overlay2"; s3.Draw(position, s_Select, id); }
static void ScaleGUI() { float scale = Mathf.Max(Screen.width, Screen.height) / 1920f; scale += Mathf.Min(Screen.width, Screen.height) / 1080f; GUIUtility.ScaleAroundPivot(new Vector2(scale, scale), Vector2.zero); }
void OnGUI() { PlayerManager Manager = (PlayerManager)FindObjectOfType(typeof(PlayerManager)); GUI.Label(new Rect(240, 500, 300, 50), Manager.TotalPlayers.ToString()); GUIUtility.ScaleAroundPivot(new Vector2(-1, -1), new Vector2(m_Texture.width / 2, m_Texture.height / 2)); GUI.Label(new Rect(-640, -240, m_Texture.width, m_Texture.height), m_Texture); }
void BeginZoomCenterWindow() { GUI.EndGroup(); _noZoomMatrix = GUI.matrix; Vector2 scale = new Vector2(currentGraph.zoom, currentGraph.zoom); GUIUtility.ScaleAroundPivot(scale, _zoomPivotPos); }
/// <summary>Updates the current GUI matrix to adjust the scale.</summary> /// <remarks> /// This method can trigger the <c>onScaleUpdatedFn</c> callback. So it's best to call it at the very beginning of /// the <c>OnGUI</c> method. /// </remarks> public void UpdateMatrix() { if (scaleIsDirty) { UpdateScale(); } GUIUtility.ScaleAroundPivot(scale, pivot); }
public static void EndZoom(Rect rect, float zoom, float topPadding) { GUIUtility.ScaleAroundPivot(Vector2.one * zoom, rect.size * 0.5f); Vector2 reverseViewport = rect.size * (zoom - 1) * 0.5f; Vector3 offset = new Vector3(reverseViewport.x, reverseViewport.y + topPadding * (1 - zoom), 0); GUI.matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one); }
private static void ControlHighlightGUI() { if (!activeVisible || searching) { return; } if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "HandleControlHighlight") { if (s_View.screenPosition.Overlaps(s_RepaintRegion)) { s_View.Repaint(); } return; } if (Event.current.type != EventType.Repaint) { return; } Rect localRect = GUIUtility.ScreenToGUIRect(activeRect); localRect = highlightStyle.padding.Add(localRect); // Animation calculations // Value pulses between 0 and 1 float pulseValue = (Mathf.Cos(s_HighlightElapsedTime * Mathf.PI * 2 * kPulseSpeed) + 1) * 0.5f; // Value expands from 0.01 to 1 and stays at 1 float popupScale = Mathf.Min(1, 0.01f + s_HighlightElapsedTime / kPopupDuration); // Value goes from 0.01 towards 1, overshoots a bit, and ends at 1. popupScale = popupScale + Mathf.Sin(popupScale * Mathf.PI) * 0.5f; // Scale calculations Vector2 pulseScaleAddition = new Vector2( (localRect.width + kExpansionMovementSize) / localRect.width - 1.0f, (localRect.height + kExpansionMovementSize) / localRect.height - 1.0f ) * pulseValue; Vector2 scale = (Vector2.one + pulseScaleAddition) * popupScale; // Cache old values Matrix4x4 oldMatrix = GUI.matrix; Color oldColor = GUI.color; // Set pulsing values GUI.color = new Color(1, 1, 1, Mathf.Clamp01(0.8f * popupScale - 0.3f * pulseValue)); GUIUtility.ScaleAroundPivot(scale, localRect.center); // Draw highlight highlightStyle.Draw(localRect, false, false, false, false); // Reset to old values GUI.color = oldColor; GUI.matrix = oldMatrix; }
/** * @brief UI表示周り. */ void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } // 縁取りを行なうように、位置をずらしつつ表示 GUILayout.BeginArea(new Rect(-1, -1, guiScreenSize.x, guiScreenSize.y)); { OnGUI_InWindow(false, new GUIStyleState() { textColor = Color.black }); } GUILayout.EndArea(); GUILayout.BeginArea(new Rect(-1, 1, guiScreenSize.x, guiScreenSize.y)); { OnGUI_InWindow(false, new GUIStyleState() { textColor = Color.black }); } GUILayout.EndArea(); GUILayout.BeginArea(new Rect(1, -1, guiScreenSize.x, guiScreenSize.y)); { OnGUI_InWindow(false, new GUIStyleState() { textColor = Color.black }); } GUILayout.EndArea(); GUILayout.BeginArea(new Rect(1, 1, guiScreenSize.x, guiScreenSize.y)); { OnGUI_InWindow(false, new GUIStyleState() { textColor = Color.black }); } GUILayout.EndArea(); GUILayout.BeginArea(new Rect(0, 0, guiScreenSize.x, guiScreenSize.y)); { OnGUI_InWindow(true, new GUIStyleState() { textColor = Color.white }); } GUILayout.EndArea(); }
// GUIまわりの記述 public void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } if (MonobitNetwork.isConnect) { // ルーム一覧を取得 m_RoomData = MonobitNetwork.GetRoomData(); // ルーム一覧からボタン選択 if (m_RoomData != null) { for (int i = 0; i < m_RoomData.Length; i++) { if (GUILayout.Button(m_RoomData[i].name + "(" + m_RoomData[i].playerCount + ")", GUILayout.Width(100))) { MonobitNetwork.JoinRoom(m_RoomData[i].name); } } } // ルーム名の入力 this.roomName = GUILayout.TextField(this.roomName); // ルームの作成 if (GUILayout.Button("Create Room", GUILayout.Width(100))) { MonobitNetwork.CreateRoom(this.roomName, new RoomSettings() { isVisible = true, isOpen = true, maxPlayers = this.maxPlayers }, null); } // ルームへの入室(ランダム) if (GUILayout.Button("Join Room", GUILayout.Width(100))) { MonobitNetwork.JoinRandomRoom(); } // メニューに戻る if (GUILayout.Button("Return Menu", GUILayout.Width(100))) { Application.LoadLevel("SampleMenu"); } } }
protected void ShowLargeTooltip(Vector2 pos, Rect fullRect, string text) { var textC = GUIContent.Temp(text); var style = BaseStyles.tooltip; var size = style.CalcSize(textC); // Arrow of tooltip var arrowRect = new Rect(pos.x - 32, pos.y, 64, 6); // Label box var rect = new Rect(pos.x, pos.y + 6, size.x, size.y); // Ensure it doesn't go too far right if (rect.xMax > fullRect.xMax + 16) { rect.x = fullRect.xMax - rect.width + 16; } if (arrowRect.xMax > fullRect.xMax + 20) { arrowRect.x = fullRect.xMax - arrowRect.width + 20; } // Adjust left to we can always see giant (STL) names. if (rect.xMin < fullRect.xMin + 30) { rect.x = fullRect.xMin + 30; } if (arrowRect.xMin < fullRect.xMin - 20) { arrowRect.x = fullRect.xMin - 20; } // Flip tooltip if too close to bottom (but do not flip if flipping would mean the tooltip is too high up) const float lineHeight = 16.0f; var flipRectAdjust = (lineHeight + rect.height + 2 * arrowRect.height); var flipped = (pos.y + size.y + 6 > fullRect.yMax) && (rect.y - flipRectAdjust > 0); if (flipped) { rect.y -= flipRectAdjust; arrowRect.y -= (lineHeight + 2 * arrowRect.height); } // Draw small arrow GUI.BeginClip(arrowRect); var oldMatrix = GUI.matrix; if (flipped) { GUIUtility.ScaleAroundPivot(new Vector2(1.0f, -1.0f), new Vector2(arrowRect.width * 0.5f, arrowRect.height)); } GUI.Label(new Rect(0, 0, arrowRect.width, arrowRect.height), GUIContent.none, BaseStyles.tooltipArrow); GUI.matrix = oldMatrix; GUI.EndClip(); // Draw tooltip GUI.Label(rect, textC, style); }
public static void DrawGUILine(Vector2 pointA, Vector2 pointB, Color color, float width) { if (pointA.Equals(pointB)) { // points are the same. return; } // Save the current GUI matrix, since we're going to make changes to it. Matrix4x4 matrix = GUI.matrix; // Generate a single pixel texture if it doesn't exist if (!lineTex) { lineTex = new Texture2D(1, 1); // Setting to never save this texture to the scene, so that the editor doesn't complain about an unreferenced texture in memory. lineTex.hideFlags = HideFlags.DontSave; } // Store current GUI color, so we can switch it back later, // and set the GUI color to the color parameter Color savedColor = GUI.color; GUI.color = color; // Determine the angle of the line. float angle = Vector3.Angle(pointB - pointA, Vector2.right); // Vector3.Angle always returns a positive number. // If pointB is above pointA, then angle needs to be negative. if (pointA.y > pointB.y) { angle = -angle; } // Use ScaleAroundPivot to adjust the size of the line. // We could do this when we draw the texture, but by scaling it here we can use // non-integer values for the width and length (such as sub 1 pixel widths). // Note that the pivot point is at +.5 from pointA.y, this is so that the width of the line // is centered on the origin at pointA. GUIUtility.ScaleAroundPivot(new Vector2((pointB - pointA).magnitude, width), new Vector2(pointA.x, pointA.y + 0.5f)); // Set the rotation for the line. // The angle was calculated with pointA as the origin. GUIUtility.RotateAroundPivot(angle, pointA); // Finally, draw the actual line. // We're really only drawing a 1x1 texture from pointA. // The matrix operations done with ScaleAroundPivot and RotateAroundPivot will make this // render with the proper width, length, and angle. GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1, 1), lineTex); // We're done. Restore the GUI matrix and GUI color to whatever they were before. GUI.matrix = matrix; GUI.color = savedColor; }
public static void BeginZoom(Rect rect, float zoom, float topPadding) { GUI.EndClip(); GUIUtility.ScaleAroundPivot(Vector2.one / zoom, rect.size * 0.5f); Rect viewport = new Rect(rect.size * (1 - zoom) * 0.5f, rect.size * zoom); viewport.y += topPadding * zoom; GUI.BeginClip(viewport); }
//NKDebugLogを表示するためのWindowを表示 void OnGUI() { if (DebugMode) { GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); GUI.ModalWindow(7, new Rect(guiScreenSize.x * 0.1f, guiScreenSize.y * 0.1f, guiScreenSize.x * 0.8f, guiScreenSize.y * 0.8f), modalWindowFunction, "NKDebugLog"); GUI.matrix = Matrix4x4.identity; } }
// Draw menus. public void OnGUI() { if (mMenuOpen) { // scale the menu buttons // because of this scaling, hardcoded values can be used int smallerScreenDimension = Screen.width < Screen.height ? Screen.width : Screen.height; float deviceDependentScale = smallerScreenDimension / 480f; Vector2 screenCenter = new Vector2(Screen.width / 2f, Screen.height / 2f); GUIUtility.ScaleAroundPivot(new Vector2(deviceDependentScale, deviceDependentScale), screenCenter); GUIStyle itemButtonStyle; if (mButtonGUIStyles.TryGetValue("ItemMenu", out itemButtonStyle)) { if (!mContinousAFSupported) { mAutoFocusText = "Cont. Auto Focus not supported "; } if (GUI.Button(new Rect(0, Screen.height / 2 - 100, Screen.width, 114), mAutoFocusText, itemButtonStyle)) { if (mFocusMode != CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO) { if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO)) { mFocusMode = CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO; mAutoFocusText = AUTOFOCUS_OFF; } mMenuOpen = false; mUserDefinedTargetEventHandler.UserInterFace.ButtonPressed = true; } else { if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL)) { mFocusMode = CameraDevice.FocusMode.FOCUS_MODE_NORMAL; mAutoFocusText = AUTOFOCUS_ON; } mMenuOpen = false; mUserDefinedTargetEventHandler.UserInterFace.ButtonPressed = true; } } if (GUI.Button(new Rect(0, Screen.height / 2 + 20, Screen.width, 114), "Cancel", itemButtonStyle)) { mMenuOpen = false; mUserDefinedTargetEventHandler.UserInterFace.ButtonPressed = true; } } // reset scale after drawing GUIUtility.ScaleAroundPivot(Vector2.one, screenCenter); } }
public static void EndZoomed(Rect rect, float zoom) { GUIUtility.ScaleAroundPivot(Vector2.one * zoom, rect.size * 0.5f); Vector3 offset = new Vector3( (((rect.width * zoom) - rect.width) * 0.5f), (((rect.height * zoom) - rect.height) * 0.5f) + (-22 * zoom) + 22, 0); GUI.matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one); }
void OnGUI() { GUI.color = new Color(1, 1, 1, alpha); Vector2 pivotPoint = new Vector2(currRect.x + currRect.width * 0.5F, currRect.y + currRect.height * 0.5F); GUIUtility.ScaleAroundPivot(scale * Vector2.one, pivotPoint); GUI.Label(currRect, txt, style); }
/// <summary> Draws the texture flipped around Y axis. </summary> public static void DrawTextureWithYFlipped(Rect rect, Texture2D tex) { var savedMatrix = GUI.matrix; GUIUtility.ScaleAroundPivot(new Vector2(1, -1), rect.center); GUI.DrawTexture(rect, tex); GUI.matrix = savedMatrix; }
public static void BeginZoom(Rect rect, float zoom, float topPadding) { GUI.EndClip(); GUIUtility.ScaleAroundPivot(Vector2.one / zoom, rect.size * 0.5f); GUI.BeginClip(new Rect(-((rect.width * zoom) - rect.width) * 0.5f, -(((rect.height * zoom) - rect.height) * 0.5f) + (topPadding * zoom), rect.width * zoom, rect.height * zoom)); }