I am having a problem in resizing a UI panel in unity on button click. I enter a negative value on the left but after I run it it doesn't read the "-" value and I also want to scale the size of the panel to 1.24 here is a picture of its default state, after I execute the code and what I want it to be like.
I'm sorry cause its hard for me to explain it in words so I just compile it in one picture.
PS. I've searched for codes that can resize the scale of the Rect but the Rect just disappear.
//Scaling left and right of the panel
DescriptionPanel.GetComponent<RectTransform>().offsetMax = new Vector2(-91.375f, -1);
DescriptionPanel.GetComponent<RectTransform>().offsetMin = new Vector2(76.295f, 0);
//Scaling x-axis of the panel when I include it in runtime my panel disappear so I did not include it in the picture below.
DescriptionPanel.GetComponent<RectTransform>().transform.localScale = new Vector2(1.24f, 1f);
UPDATE - Ive already fixed the Left and Right RectTransform problem.
The remaining problem is resizing the scale of the rectTransform.
When I execute this code my Panel disappears. I need to set the X axis to 1.24.
DescriptionPanel.GetComponent<RectTransform>().transform.localScale = new Vector2(1.24f, 1f);
You might have to use Vector3 when transforming a localscale, because Your DescriptionPanel might be moved over behind the canvas
Related
I want to make the ground in this place of the terrain a bit deeper a bit lower but left shift key or right shift key and the left mouse button does not change anything on the terrain.
I've been looking for an answer for hours, and I finally found it.
If you are trying to lower a piece of land that is already at 0 height, you will not be able.
You can only lower areas that are above to height 0. In short, height 0 is the minimum: you cannot go to snow values due to the way the terrain is created.
To be able to make valleys then you have to select the tool "Set Height", enter a height and raise all the ground to that height with "Flatten All", or small pieces of land by dragging the mouse on the ground.
If you click "Flatten All", all the terrain will be brought to that height, losing all the changes made previously for the mountains.
However, if you have already made land and you don't want to lose it and redo it from scratch, you can use the following solution:
Export the current heightmap;
Open the image in an editor; (I'm not an expert in Photoshop or other
graphics programs, but I'm sure Photoshop has a way. If there isn't
an entry in the program, find out how to use scripts in photoshop)
Find a way to set the pixels according to a formula: maximum depth of
valleys + current value of the grayscale pixel * original height /
(original height + maximum depth of valleys);
Export the image in Raw format;
Go back to Unity and import it on the ground as you read in the link
above;
In the terrain settings set the height equal to the value you used
in the formula called "original height" + the “maximum depth of
valleys” value;
You should now have the ground as before, but higher. Set the value
in the transform of the Y position equal to "-maximum depth of
valleys" so that it is at the same height as before.
You should now be able to create valleys!
I haven't tried the process, but I've thought about it so much I'm pretty sure it will work.
Good work!
I have canvas with vertical layout and 2 elements within (in fact it's element with only recttransform on it, let's call it container). So these 2 containers take a half of the screen by height and stretched by width, ok. How can I place an text element in above container and snap it to the bottom of this container? I tried press bottom button in recttransform widget (also with shift and alt) and it seems it doesn't affect my transform at all
P.s. May be I can use some free plugin instead of default unity components of UI layout?
There are different ways of placing your UI elements
Simply drag and drop it to the bottom where you want it
Use the anchor widget to set the anchoring to bottom with horizontal stretch and hold shift to also set pivot. Then set Pos Y to 0. Set Left and Right to 0.
Assuming you also want other elements in your containers, place a Vertical Layout Group on each container and make sure that your text element is the last child of the container in the hierarchy.
I would also advise you to seek out tutorials on Unity UI anchoring, positioning, scaling, and layout. You need a deeper understanding of how these things interact than you are likely to get from Stack Overflow. Otherwise you will suddenly find that your UI behaves in unexpected ways when rearranged or displayed on a different aspect ratio.
It's fairly easy with Unity UI system. You just need to get used to it. Here are simple steps to accomplish what you want:
Create Text element as a child of that container.
Select your newly created element and edit its RectTransform component values:
2.1. Set both Y axis anchors (min and max) to 0.
2.2. Set pivot value to 0 as well.
2.3. Set Pos Y value to 0 as well.
Now your Text element is anchored at the bottom of the container and its position (and height) is measured from the bottom of the Text element itself.
(pretty new to Mapbox and JS, so I'm in a bit over my head)
I'm working on a page where the user needs to adjust the size of map container. It needs to be able to get accurate bounds and center point of the resized map (via map.getBounds and map.getCenter).
When I use JS to adjust the size of the container div, the center and bounds are not adjusted.
Fiddle: http://jsfiddle.net/xcow63sm/3/
Panning/zooming results in updated center and bounds. Browser window resize (if you have width or height set to 100%) works too. I would expect changing the container dimensions would adjust center and bounds.
However, if you use the form fields to adjust the height/width of the container div, the center and bounds do not. I've tried (with increasing desperation):
function resize (){
var inputwidth = document.getElementsByName("mapwidth")[0].value;
var inputheight = document.getElementsByName("mapheight")[0].value;
var mapDiv = document.getElementById('map');
var mapcenter = map.getCenter();
mapDiv.style.width = inputwidth;
mapDiv.style.height = inputheight;
map.updateSize();
map.update();
map.resize();
map.invalidateSize();
document.getElementById("mapcenter").value = mapcenter;
Edit: this seems to apply but I can't make sense of it: Resizing a leaflet map on container resize
If I understand you, you have two issues: you don't like how the map is positioned after its size changes, and you're getting white space.
Map positioning after resize
There are at least three valid options for how a map should update if, say, its width and height are suddenly doubled:
keep the same northern and western bound, extend the eastern and southern bounds. (Expanding the viewing area right and down)
move all four bounds outwards (keeping the centre of the map in the same place)
leave all four bounds where they are are, but change the zoom, so the same geographic area is displayed, but in more detail.
I think your issue is that Mapbox is choosing option 1, but you want one of the other two options. The solution, as I think you've discovered, is simply to do your own maths and set the bounds how you want them.
Map failing to repaint correctly
Your second issue is that when you resize, calling map.resize() isn't updating the internal size of the map properly, and you're left with white space. The reason for this is you're using animated CSS properties. So when you do this:
mapDiv.style.width = inputwidth;
mapDiv.style.height = inputheight;
map.resize();
This doesn't work because the map's size hasn't actually transitioned to the new size yet. You can work around it like this:
mapDiv.style.width = inputwidth;
mapDiv.style.height = inputheight;
window.setTimeout(()=>map.resize(), 500);
There's probably a better event you can listen to, to keep updating as the map area expands.
Updated fiddle here: http://jsfiddle.net/xcow63sm/11/
Btw you should consult the documentation here. I'm not sure where you got map.updateSize() from but that's not Mapbox-GL-JS :)
I'm trying to make some figures in JavaFX. I can create these figures with the Polygon class or in this case with the Circle class. But I want to add an image on top of it. So I'm using a group for this with 2 elements, the figure and the image in an ImageView. But if I use this group, the image isn't in the middle. I would like to center the image. I also would like to be able to drag and drop it with a mouse, so then it needs to stay in the middle. I've tried it with a circle and a polygon but in both cases the image was in the bottom right corner.
Edit: I just figured out that you can move your image with setX and setY, but this isn't an easy way to center the image.
Here's what I have at the moment:
public class Figure extends Group {
public Figure() {
Circle circle = new Circle(100);
ImageView imageView = new ImageView();
circle.setFill(Color.BLUE);
circle.setStroke(Color.BLACK);
Image image = new Image("images/blue/bike.png");
imageView.setImage(image);
imageView.setFitWidth(100);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
super.getChildren().addAll(circle, imageView);
}
The easiest solution would be to use a StackPane instead of a Group. That might give problems with clickability if you let them overlap: one of two Circles is then obscured by the other figure's StackPane.
Though a bit inelegant, I would do it with setX and setY as you propose.
I created a new document with 36 points margin all around:
Rectangle rect = new Rectangle(1224f, 792f);
Document doc = new Document(rect, 36f, 36f, 36f, 36f);
I drew a rectangle at (0, 0) using PdfContentByte:
cb.rectangle(0, 0, 100, 100);
cb.fill();
The rectangle gets drawn at the lower-left hand corner of the page. It ignores the margins completely. Is this the expected result?
Is this the expected result?
Yes, it is. The margins only are taken into account by operations adding content via the Document.
Whenever you access the content directly (DirectContent, UnderContent,OverContent), you can draw wherever you want.
When creating footers or headers, you actually rely on that behavior.
Furthermore, the margins have no influence on the coordinate system. As the coordinate system is configurable, one could have chosen 0,0 to be the lower left of the margin border. Actually you can do so by defining a page size rectangle that way. But that is not the normal usage of iText.