public void Begin(Vector2 size, bool drawGUI = false) { if (Event.current.type != EventType.Layout) { var p = GUIUtility.ScreenToGUIPoint(this.screenPos); this.areaRect = new Rect(p, this.areaRect.size); } this.areaRect = new Rect(this.areaRect.position, size); GUIHelper.BeginIgnoreInput(); GUILayout.BeginArea(this.areaRect, SirenixGUIStyles.None); if (Event.current.type == EventType.Repaint) { this.prev = RenderTexture.active; if (this.target != null) { RenderTexture.ReleaseTemporary(this.target); } this.target = RenderTexture.GetTemporary(Screen.width, Screen.height, 0); RenderTexture.active = this.target; GL.Clear(false, true, new Color(0, 0, 0, 0)); } }
public void OnGUI() { if (display == true) { float y = 0f; Vector2 screenPos = Camera.main.WorldToScreenPoint(unit.position); Vector2 convertedGUIPos = GUIUtility.ScreenToGUIPoint(screenPos); const int buttonWidth = 50; const int buttonHeight = 50; foreach (string item in opponent.army) { Rect moveRect = new Rect(convertedGUIPos.x + (buttonWidth / 2), convertedGUIPos.y * -1 + Screen.height + y + 25, buttonWidth, buttonHeight); image = Resources.Load(item, typeof(Texture2D)) as Texture2D; //GUI.skin.color = opponent.color; GUI.skin.button.normal.background = backImage; GUI.skin.button.hover.background = backImage; GUI.skin.button.active.background = backImage; if (GUI.Button(moveRect, image)) { //print (item); target = item; display = false; } y = y + 45f; } } if (over == true || opponent.over == true) { inkUI.text = ""; } }
private void OnGUI() { if (Event.current.type == EventType.Repaint) { Vector3 position = this.t_mc.position; Camera main = Camera.main; if (main != null) { Vector3 screenPoint = main.WorldToScreenPoint(position); if ((screenPoint.z > 0f) && (screenPoint.z < 150f)) { Vector2 vector3 = GUIUtility.ScreenToGUIPoint(screenPoint); vector3.y = Screen.height - (vector3.y + 1f); if (screenPoint.z > 10f) { GUI.color *= new Color(1f, 1f, 1f, 1f - ((screenPoint.z - 10f) / 140f)); } Rect rect = new Rect(vector3.x - 64f, vector3.y - 12f, 128f, 24f); if (string.IsNullOrEmpty(this.groupString)) { this.groupString = base.networkView.group.ToString(); } GUI.Label(rect, this.groupString); } } } }
public static Rect ResizeWindow(Rect _rect, int ID) { GUILayout.BeginHorizontal(); GUILayout.Space(_rect.width - 35); GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Width(25), GUILayout.Height(25) }); var r = GUILayoutUtility.GetLastRect(); Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); if (r.Contains(mouse) && Input.GetMouseButtonDown(0)) { isResizing = true; m_currentWindow = ID; m_currentResize = new Rect(mouse.x, mouse.y, _rect.width, _rect.height); } else if (!Input.GetMouseButton(0)) { isResizing = false; } if (isResizing && ID == m_currentWindow) { _rect.width = Mathf.Max(100, m_currentResize.width + (mouse.x - m_currentResize.x)); _rect.height = Mathf.Max(100, m_currentResize.height + (mouse.y - m_currentResize.y)); _rect.xMax = Mathf.Min(Screen.width, _rect.xMax); // modifying xMax affects width, not x _rect.yMax = Mathf.Min(Screen.height, _rect.yMax); // modifying yMax affects height, not y } GUILayout.EndHorizontal(); return(_rect); }
// Token: 0x06001995 RID: 6549 RVA: 0x00062D20 File Offset: 0x00060F20 private void OnGUI() { if (Event.current.type != 7) { return; } Vector3 position = this.t_mc.position; Camera main = Camera.main; if (main) { Vector3 vector = main.WorldToScreenPoint(position); if (vector.z > 0f && vector.z < 150f) { Vector2 vector2 = GUIUtility.ScreenToGUIPoint(vector); vector2.y = (float)Screen.height - (vector2.y + 1f); if (vector.z > 10f) { GUI.color *= new Color(1f, 1f, 1f, 1f - (vector.z - 10f) / 140f); } Rect rect; rect..ctor(vector2.x - 64f, vector2.y - 12f, 128f, 24f); if (string.IsNullOrEmpty(this.groupString)) { this.groupString = base.networkView.group.ToString(); } GUI.Label(rect, this.groupString); } } }
void OnGUI() { var style = new GUIStyle(); style.fontSize = 24; style.normal.textColor = Color.cyan; style.alignment = TextAnchor.MiddleCenter; if (!string.IsNullOrEmpty(hint)) { float opacity; if (hintFadeoutAfter <= 0) { opacity = 1; } else { opacity = Mathf.Clamp01(hintFadeoutTriggeredTime + hintFadeoutAfter - Time.realtimeSinceStartup) / (hintFadeoutTime); } if (opacity > 0) { var hintPos = GUIUtility.ScreenToGUIPoint(new Vector2(Screen.width / 2, Screen.height / 3)); var color = GUI.color; color.a = opacity; GUI.color = color; GUI.Label(new Rect(hintPos.x, hintPos.y, 0.2f, 0.2f), hint, style); color.a = 1; GUI.color = color; } } }
public override void draw() { if (!survive) { GUIManager.removeGUI(this); ScriptableObject.Destroy(this); return; } Vector2 pos = GUIUtility.ScreenToGUIPoint(position); Rect rect = new Rect(pos.x - radius, pos.y - radius, radius * 2f, radius * 2f); GUISkin natural = GUI.skin; GUI.skin = Resources.Load <GUISkin>("Skin"); GUI.Box(rect, ""); for (int i = 0; i < options.Length; i++) { Rect buttonRect = new Rect(pos.x + (radius - minDist / 2f) * Mathf.Sin(angle * i) - minDist / 2f, pos.y - (radius - minDist / 2f) * Mathf.Cos(angle * i) - minDist / 2f, minDist, minDist); if (Event.current.isMouse && Event.current.type == EventType.MouseUp) { if (buttonRect.Contains(GUIUtility.ScreenToGUIPoint(Event.current.mousePosition))) { returningOption = new Option[] { options[i] }; } } GUI.Button(buttonRect, options[i].Name); } GUI.skin = natural; }
Rect ResizeWindow(int id, Rect windowRect, Vector2 minWindowSize) { Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); //Rect r = GUILayoutUtility.GetRect(gcDrag, GUI.skin.window); Rect r = new Rect(windowRect.width - 20, windowRect.height - 20, 20, 20); if (Event.current.type == EventType.MouseDown && r.Contains(mouse)) { resizing = id; resizeStart = new Rect(mouse.x, mouse.y, windowRect.width, windowRect.height); } else if (Event.current.type == EventType.MouseUp && resizing == id) { resizing = 0; } else if (!Input.GetMouseButton(0)) { resizing = 0; } else if (resizing == id) { windowRect.width = Mathf.Max(minWindowSize.x, resizeStart.width + (mouse.x - resizeStart.x)); windowRect.height = Mathf.Max(minWindowSize.y, resizeStart.height + (mouse.y - resizeStart.y)); windowRect.xMax = Mathf.Min(Screen.width, windowRect.xMax); // modifying xMax affects width, not x windowRect.yMax = Mathf.Min(Screen.height, windowRect.yMax); // modifying yMax affects height, not y } GUI.Button(r, gcDrag, GUI.skin.label); return(windowRect); }
public static Rect ResizeWindow(Rect windowRect, ref bool isResizing, ref Rect resizeStart, Vector2 minWindowSize) { Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); if (Event.current.type == EventType.MouseDown && windowRect.Contains(mouse)) { isResizing = true; resizeStart = new Rect(mouse.x, mouse.y, windowRect.width, windowRect.height); } else if (Event.current.type == EventType.MouseUp && isResizing) { isResizing = false; } else if (!Input.GetMouseButton(0)) { isResizing = false; } else if (isResizing) { windowRect.width = Mathf.Max(minWindowSize.x, resizeStart.width + (mouse.x - resizeStart.x)); windowRect.height = Mathf.Max(minWindowSize.y, resizeStart.height + (mouse.y - resizeStart.y)); windowRect.xMax = Mathf.Min(Screen.width, windowRect.xMax); windowRect.yMax = Mathf.Min(Screen.height, windowRect.yMax); } return(windowRect); }
/// <summary> /// Shows popup for the user to choose a Canvas that will be used and adds a MenuController component to it. /// </summary> public static void CreateMenuController(UnityEngine.Events.UnityAction <MenuController> onFinish) { Canvas[] canvasses = HierarchyHelper.GetSelectedOrGeneralObjectsOfType <Canvas>(); Vector2 coordinates = EditorUtils.GetMousePosition(); try { PopupWindow.Show(new Rect(GUIUtility.ScreenToGUIPoint(coordinates), new Vector2(250, 150)), new CanvasSelector(canvasses, (Canvas canvas) => { if (canvas == null) { // The user wants us to create a canvas EditorApplication.ExecuteMenuItem("GameObject/UI/Canvas"); Canvas[] newCanvasses = HierarchyHelper.GetObjectsOfType <Canvas>(); canvasses = newCanvasses.Except(canvasses).ToArray(); if (canvasses == null || canvasses.Length <= 0) { Debug.LogError("Something went wrong with creating the new canvas. Please try again."); return; } canvas = canvasses[0]; } MenuController result = Undo.AddComponent <MenuController>(canvas.gameObject); if (onFinish != null) { onFinish(result); } })); } catch (UnityEngine.ExitGUIException) { // https://answers.unity.com/questions/385235/editorguilayoutcolorfield-inside-guilayoutwindow-c.html } }
private void OnGUI() { if (Event.current.type != EventType.Repaint) { return; } Vector3 tMc = this.t_mc.position; Camera camera = Camera.main; if (camera) { Vector3 screenPoint = camera.WorldToScreenPoint(tMc); if (screenPoint.z > 0f && screenPoint.z < 150f) { Vector2 gUIPoint = GUIUtility.ScreenToGUIPoint(screenPoint); gUIPoint.y = (float)Screen.height - (gUIPoint.y + 1f); if (screenPoint.z > 10f) { GUI.color = GUI.color * new Color(1f, 1f, 1f, 1f - (screenPoint.z - 10f) / 140f); } Rect rect = new Rect(gUIPoint.x - 64f, gUIPoint.y - 12f, 128f, 24f); if (string.IsNullOrEmpty(this.groupString)) { this.groupString = [email protected](); } GUI.Label(rect, this.groupString); } } }
private void DrawNodeConnections(Rect container) { GUI.depth = -150; foreach (var n in Program.Nodes) { foreach (var c in n.Outputs) { if (c.Value.Connected) { if (connections.ContainsKey(c.Value)) { foreach (var c2 in c.Value.Connections) { if (connections.ContainsKey(c2)) { Vector2 a = connections[c.Value]; Vector2 b = connections[c2]; GUILine.DrawLine(GUIUtility.ScreenToGUIPoint(a), GUIUtility.ScreenToGUIPoint(b), ConnectionColor(c.Value), 2, true); } } } } } } }
public void Draw2DBoundingBoxes() { Player[] allPlayers = PlayerManager.GetAllPlayers(); for (int i = 0; i < allPlayers.Length; i++) { APIUser apiuser = allPlayers[i].GetAPIUser(); if (apiuser != null && !(apiuser.id == APIUser.CurrentUser.id)) { Vector3 position = allPlayers[i].transform.position; Vector3 position2 = position; position2.y += 1.7f; Vector3 vector = VRCVrCamera.GetInstance().screenCamera.WorldToScreenPoint(position); Vector3 vector2 = VRCVrCamera.GetInstance().screenCamera.WorldToScreenPoint(position2); if ((double)vector.z > 0.0 && (double)vector2.z > 0.0) { Vector3 vector3 = GUIUtility.ScreenToGUIPoint(vector); vector3.y = (float)Screen.height - vector3.y; Vector3 vector4 = GUIUtility.ScreenToGUIPoint(vector2); vector4.y = (float)Screen.height - vector4.y; float num = (float)((double)Math.Abs(vector3.y - vector4.y) / 2.20000004768372 / 2.0); Vector3 v = new Vector3(vector4.x - num, vector4.y); Vector3 v2 = new Vector3(vector4.x + num, vector4.y); Vector3 v3 = new Vector3(vector4.x - num, vector3.y); Vector3 v4 = new Vector3(vector4.x + num, vector3.y); Color c = new Color((float)color.R, (float)color.G, (float)color.B); GUIHelper.DrawLine(v, v2, c); GUIHelper.DrawLine(v, v3, c); GUIHelper.DrawLine(v3, v4, c); GUIHelper.DrawLine(v2, v4, c); } } } }
Vector3 GetHitPoint(bool isAiming) { Vector3 hitpoint; float x; float y; if (isAiming == false) { x = UnityEngine.Random.Range(Screen.width / 2 - aim_pos_horz - baseSettings.addedHipInaccuracy, Screen.width / 2 + aim_pos_horz + baseSettings.addedHipInaccuracy); y = UnityEngine.Random.Range(Screen.height / 2 - aim_pos_vert - baseSettings.addedHipInaccuracy, Screen.height / 2 + aim_pos_vert + baseSettings.addedHipInaccuracy); hitpoint = new Vector3(x, y, 0); debugging.hitpoint = hitpoint; } else { // x = (baseSettings.shotPoint == null) ? Screen.width/2 : weaponEffects.zoomEffect.WorldToViewportPoint(baseSettings.shotPoint.position).x; // y = (baseSettings.shotPoint == null) ? Screen.height/2 : weaponEffects.zoomEffect.WorldToViewportPoint(baseSettings.shotPoint.position).y; // hitpoint = weaponEffects.recoilEffect.ViewportToWorldPoint(baseSettings.shotPoint.position); // hitpoint = weaponEffects.recoilEffect.ViewportToScreenPoint(hitpoint); // hitpoint = weaponEffects.zoomEffect.ScreenToWorldPoint(hitpoint); hitpoint.x = (Screen.width / 2f) + overridePosition.shot_offset.x; hitpoint.y = (Screen.height / 2f) + overridePosition.shot_offset.y; hitpoint.z = 0; if (baseSettings.aimInaccuracy > 0) { hitpoint.x = UnityEngine.Random.Range(hitpoint.x - baseSettings.aimInaccuracy, hitpoint.x + baseSettings.aimInaccuracy); hitpoint.y = UnityEngine.Random.Range(hitpoint.y - baseSettings.aimInaccuracy, hitpoint.y + baseSettings.aimInaccuracy); } debugging.hitpoint = GUIUtility.ScreenToGUIPoint(new Vector2(hitpoint.x, hitpoint.y)); } return(hitpoint); }
void OnGUI() { if (bTransitioning) { fTimeSinceClick += Time.deltaTime; if (fTimeSinceClick >= 0.5f) { bTransitioning = false; fTimeSinceClick = 0.5f; } fSlide = fTransitionDirection * (-32.0f * fTimeSinceClick * fTimeSinceClick * fTimeSinceClick + 24.0f * fTimeSinceClick * fTimeSinceClick - 1); fSlide = Mathf.Clamp(fSlide, -1.0f, 1.0f); } RectTransform tf = GetComponent <RectTransform>(); tf.localPosition = new Vector3(848.0f * fSlide, 0.0f, 0.0f); Vector3[] fourCorners = new Vector3[4]; tf.GetWorldCorners(fourCorners); float fMinX = fourCorners [0].x / Screen.width; float fMaxX = fourCorners [2].x / Screen.width; float fMinY = fourCorners [0].y / Screen.height; float fMaxY = fourCorners [2].y / Screen.height; float fCentreX = (fMinX + fMaxX) * 0.5f; float fWidthX = fMaxX - fMinX; float fCentreY = (fMinY + fMaxY) * 0.5f; float fHeightY = fMaxY - fMinY; // Should be -0.883333333 to 1 float fScaleX = fWidthX / 1.8833333333333f; float fScaleY = fHeightY / 1.0f; for (int i = 0; i < 5; i++) { if (previews [i] != null) { //Rect old = previews [i].cam.rect; //float fParametric = 0.5f * (fSlide + 1.0f); //previews [i].cam.rect = new Rect (fParametric * 0.8875f, old.y, 0.1125f, old.height); previews [i].cam.rect = new Rect( fCentreX - (0.1125f * 0.5f * fScaleX), fCentreY + (-0.5f + (4 - i) * 0.2f) * fScaleY, 0.1125f * fScaleX, 0.2f * fScaleY); } } if (Event.current != null) { Vector3 v = GUIUtility.ScreenToGUIPoint(Event.current.mousePosition); hoverBox.position = new Vector3(v.x, Screen.height - v.y, v.z); } }
public void OnGUI() { if (this.behaviorManager == null) { this.behaviorManager = BehaviorManager.instance; } if (this.behaviorManager == null || this.mainCamera == null) { return; } List <BehaviorManager.BehaviorTree> behaviorTrees = this.behaviorManager.BehaviorTrees; for (int i = 0; i < behaviorTrees.Count; i++) { BehaviorManager.BehaviorTree behaviorTree = behaviorTrees[i]; string text = string.Empty; for (int j = 0; j < behaviorTree.activeStack.Count; j++) { Task task = behaviorTree.taskList[behaviorTree.activeStack[j].Peek()]; if (task is BehaviorDesigner.Runtime.Tasks.Action) { text = text + behaviorTree.taskList[behaviorTree.activeStack[j].Peek()].FriendlyName + ((j >= behaviorTree.activeStack.Count - 1) ? string.Empty : "\n"); } } Transform transform = behaviorTree.behavior.transform; Vector3 v = Camera.main.WorldToScreenPoint(transform.position); Vector2 vector = GUIUtility.ScreenToGUIPoint(v); GUIContent content = new GUIContent(text); Vector2 vector2 = GUI.skin.label.CalcSize(content); vector2.x += 14f; vector2.y += 5f; GUI.Box(new Rect(vector.x - vector2.x / 2f, vector.y + vector2.y / 2f, vector2.x, vector2.y), content); } }
// Originally from the following URL and modified: // http://answers.unity3d.com/questions/17676/guiwindow-resize-window.html public void HandleResize() { Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); Rect r = GUILayoutUtility.GetRect(gcDrag, WindowStyles.WindowButtonStyle); if (Event.current.type == EventType.mouseDown && r.Contains(mouse)) { isResizing = true; resizeStart = new Rect(mouse.x, mouse.y, position.width, position.height); //Event.current.Use(); // the GUI.Button below will eat the event, and this way it will show its active state } else if (Event.current.type == EventType.mouseUp && isResizing) { isResizing = false; } else if (!Input.GetMouseButton(0)) { // if the mouse is over some other window we won't get an event, this just kind of circumvents that by checking the button state directly isResizing = false; } else if (isResizing) { position.width = Mathf.Max(minSize.x, resizeStart.width + (mouse.x - resizeStart.x)); position.height = Mathf.Max(minSize.y, resizeStart.height + (mouse.y - resizeStart.y)); position.xMax = Mathf.Min(Screen.width, position.xMax); // modifying xMax affects width, not x position.yMax = Mathf.Min(Screen.height, position.yMax); // modifying yMax affects height, not y } GUI.Button(r, gcDrag, WindowStyles.WindowButtonStyle); }
public static bool CursorIsOnGUI() { Vector2 coord = GUIUtility.ScreenToGUIPoint(Input.mousePosition); coord.y = Screen.height - coord.y; return(new Rect(Screen.width / 2 - 75, 25, 150, 50).Contains(coord)); }
public static Vector2 ScreenToGUIPoint(Vector2 screenPoint) { #if CPP return(Internal.ScreenToGUIPoint(screenPoint)); #else return(GUIUtility.ScreenToGUIPoint(screenPoint)); #endif }
void OnGUI() { if (mouseDragging && isMoving == false) { Vector2 guiMouseCoord = GUIUtility.ScreenToGUIPoint(Input.mousePosition); GUI.Box(new Rect(guiMouseCoord.x - 30, Screen.height - guiMouseCoord.y + 15, 100, 20), "force: " + Mathf.Round((forceVector).magnitude)); } }
static Rect ScreenToGUIRect(Rect rect) { var vector = GUIUtility.ScreenToGUIPoint(new Vector2(rect.x, rect.y)); rect.x = vector.x; rect.y = vector.y; return(rect); }
public override void OnGUI(Context context) { if (m_Style == null) { m_Style = new GUIStyle { richText = true, font = Font.CreateDynamicFontFromOSFont("Roboto-Regular", 27), fontStyle = FontStyle.Bold, fontSize = 27 } } ; Color color = Color.white; switch (m_ColorMode) { case ColorMode.Fixed: color = Color.red; break; case ColorMode.Rainbow: color = m_ColorModifierRainbow.Current; break; } foreach (AgentHumanDT agentHumanDT in context.LivingEnitites) { if (m_ColorMode == ColorMode.Visibility) { color = context.VisibleEntities.Contains(agentHumanDT) ? Color.green : Color.red; } Vector3 spos = Camera.main.WorldToScreenPoint(agentHumanDT.transform.position + new Vector3(0f, 1.9f)); if (spos.z > 0f) { Vector2 gPos = GUIUtility.ScreenToGUIPoint(spos); gPos.y = Screen.height - gPos.y; string distStr = ((int)Vector3.Distance(context.LocalPlayer.transform.position, agentHumanDT.transform.position)).ToString() + "m"; if (m_ColorMode == ColorMode.Gradient) { string str = "<b><size=27>"; for (int i = 0; i < distStr.Length; i++) { Color now = Color.Lerp(m_ColorModifierAnimatedGradient.Colors[0, 0], m_ColorModifierAnimatedGradient.Colors[1, 0], (i + 1f) / distStr.Length); str += string.Format("<color=#{0}>{1}</color>", now.ToHexString(), distStr[i]); } str += "</size></b>"; GUI.Label(new Rect(gPos.x, gPos.y, 200f, 200f), str, m_Style); } else { GUI.Label(new Rect(gPos.x, gPos.y, 200f, 200f), string.Format("<b><color=#{0}><size=24>{1}</size></color></b>", color.ToHexString(), distStr)); } } } } }
private void OnGUI() { if (hover && _content) { var mouse = Event.current.mousePosition; mouse = GUIUtility.ScreenToGUIPoint(mouse); _content.DisplayItemInfo(mouse); } }
private void DrawNodes(Rect area) { nodeViewScrollPos = GUI.BeginScrollView(area, nodeViewScrollPos, programRect); if (draggedNode != null) { if (GUIController.mouseReleased) { if (GUIController.mousePos.x < toolbarWidth) { Log.Write("Removing node: " + draggedNode); Program.RemoveNode(draggedNode); } draggedNode = null; } else { var vec = GUIUtility.ScreenToGUIPoint(GUIController.mousePos) - dragInfo; draggedNode.Position = new SVector2(Mathf.Max(0, Mathf.Min(programRect.width - 120, vec.x)), Mathf.Max(0, Mathf.Min(programRect.height - 120, vec.y))); } } connections.Clear(); GUI.skin.box.alignment = TextAnchor.UpperLeft; GUI.skin.box.padding = new RectOffset(2, 2, 2, 2); foreach (var n in Program.Nodes) { DrawNode(n); } GUI.skin.box.padding = new RectOffset(0, 0, 0, 0); GUI.skin.box.alignment = TextAnchor.UpperCenter; DrawNodeConnections(new Rect(toolbarWidth + 20, GUIController.ElSize, WinRect.width - toolbarWidth - GUIController.ElSize, WinRect.height - GUIController.ElSize)); GUI.EndScrollView(); if (GUIController.mousePressed) { if (draggedConnection == null && draggedNode == null && !dragging) { if (area.Contains(GUIUtility.ScreenToGUIPoint(GUIController.mousePos))) { dragging = true; dragInfo = GUIController.mousePos; } } } if (dragging) { if (GUIController.mouseReleased) { dragging = false; } else { nodeViewScrollPos -= GUIController.mousePos - dragInfo; dragInfo = GUIController.mousePos; } } GUI.backgroundColor = GUIController.DefaultColor; }
/* Draw text on screen from worldspace */ private void DrawLabel(Vector3 point, string label, Color color) { Vector3 vector = Camera.main.WorldToScreenPoint(point); Vector3 value = vector; Vector2 vector2 = GUIUtility.ScreenToGUIPoint(value); vector2.y = (float)Screen.height - (vector2.y + 1f); GUI.color = color; GUI.Label(new Rect(vector2.x - 64f, vector2.y - 12f, 500f, 48f), label); }
void UpdateSettings() { pos = GUIUtility.ScreenToGUIPoint(new Vector2(transform.localPosition.x, transform.localPosition.y)); //Change the editors position to that of the object in GUI Space in pixels pos = new Vector2(Screen.width * screenPosX, Screen.height * screenPosY); //The position of the compass on screen. Dynamically when window is resized. needleRect = new Rect(pos.x - needleSize.x * halfSize, Screen.height - (pos.y - needleSize.y * halfSize), needleSize.x, needleSize.y); //Create the Object at 0,0 position from the botton left. pivot = new Vector2(needleRect.xMin + needleRect.width * xCenterPos, needleRect.yMin + needleRect.height * yCenterPos); //Calculation of the pivot point of the object. (Adjust values xCenterPos and yCenterPos). compassRect = new Rect(pos.x - compassSize.x * 0.50f, Screen.height - (pos.y - compassSize.y * 0.15f), compassSize.x, compassSize.y); //Create the Object at 0,0 position from the bottom left. Play alittle with the (0.5 vars) in this example to allign the needle with the compass. }
void OnGUI() { if (displayObjectName) { Debug.Log("HIGHLIGHTING"); Vector2 screenPos = Event.current.mousePosition; Vector2 converteddGUIPos = GUIUtility.ScreenToGUIPoint(screenPos); GUI.Box(new Rect(converteddGUIPos.x, converteddGUIPos.y, 120, 25), objectName); } }
public static void Menu() { if (GUI.Button(new Rect(670f, 20f, 130f, 30f), string.Format("Mod Menu is {0}", ModMenu.showMenu ? "ON" : "OFF"), ModMenu.BtnStyle)) { ModMenu.showMenu = !ModMenu.showMenu; } if (ModMenu.showMenu) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; ModMenu.windowRect0 = GUI.Window(0, ModMenu.windowRect0, new GUI.WindowFunction(ModMenu.WindowFunction), "Modz"); return; } if (ModMenu.esp) { Collider[] array = Physics.OverlapSphere(UnitySingletonBehavior <GameState> .Instance.PlayerManager.transform.position, 100f, LayerUtils.MonsterLayerMask); for (int i = 0; i < array.Length; i++) { VisualActorMonster componentInParent = array[i].GetComponentInParent <VisualActorMonster>(); if (!(componentInParent == null)) { RemoteEntityMonster remoteEntityMonster = componentInParent.GetEntity() as RemoteEntityMonster; if (remoteEntityMonster != null && !remoteEntityMonster.IsDead) { Vector3 position = remoteEntityMonster.Position; Vector3 vector = Camera.main.WorldToScreenPoint(position); if (vector.z > 0f && ModMenu.IsInScreen(position)) { Vector3 v2 = GUIUtility.ScreenToGUIPoint(vector); v2.y = (float)Screen.height - v2.y; ModMenu.RenderLines(new Vector2((float)(Screen.width / 2), (float)Screen.height), v2, Color.cyan); GUI.Label(new Rect(vector.x, (float)Screen.height - vector.y, 120f, 120f), string.Concat(new object[] { remoteEntityMonster.DisplayName, "\nCurrent Health: ", remoteEntityMonster.Health.ToString(), "\nMax Health: ", remoteEntityMonster.HealthMax.ToString(), "\nID:", remoteEntityMonster.Id.ToString() }), new GUIStyle { fontSize = 13, fontStyle = FontStyle.Bold, normal = { textColor = Color.red } }); } } } } } }
void OnGUI() { if (RadarPointList.Count > 0) { foreach (Rect r in RadarPointList) { Vector2 top = GUIUtility.ScreenToGUIPoint(new Vector2(r.x, r.y)); GUI.DrawTexture(new Rect(top.x, top.y, r.width, r.width), RadarDot); } } }
void OnGUI() { Vector2 screenPos = Camera.main.WorldToScreenPoint(gameObject.transform.position); Vector2 convertedGUIPos = GUIUtility.ScreenToGUIPoint(screenPos); int wid = Screen.width / 17; int hei = Screen.height / 6; //print (wid); //print (hei); GUI.DrawTexture(new Rect(convertedGUIPos.x - (wid / 2), -1 * convertedGUIPos.y + (hei * 5.5f), wid, Screen.height / 8f), image); }