I posted yesterday about a scroll bar that I couldn’t get working but I boiled it down to the actual 9-slice image that isn’t working. I have edited this post with updated code to simplify reproduction. It looks as though the areas that are supposed to stretch in the 9-slice are actually being removed and the four corners are being stretched. I’m not sure what I’m missing here. In the editor when I create one, it looks identical to the image I create in code. Any help here would be great!
Update: I edited the post above to update it to talk about the image 9-slice problem which is the heart of the scroll bar problem I posted yesterday. Any help would be greatly appreciated!
Thanks for the response. Ideally, no, I’m not using prefabs for anything. I have found it’s simpler and easier to manage assets with version control and my team without them. There must be a way to achieve a 9 slice in code right?
Thanks for getting back to me @eses . I haven’t solved this yet unfortunately.
Now, correct me if I’m wrong, but am I not doing just what you said? The only difference is that I’m creating my Vector4 inline with my sprite creation. For the sake of argument I broke out out. These lines look like this:
I played around with the parameters and finally figured out what the problem is. The fourth parameter, pixelsPerUnit, was set to 1f. If I set this to 100f, it works as expected. In my project, I have been using a 1 pixelPerUnit settings since it is a 2D game and I am doing everything pixel perfect and that setting works for my setup. I then assumed that I would maintain that setting throughout.
I’m not entirely sure what pixelsPerUnit is, however. I have read several articles and it’s still not making a lot of sense to me. I’m not sure how that setting was responsible for the problem I was having. So, the problem is solved, but if anyone could provide further insight as to what pixelsPerUnit does, especially in relation to this problem, it would be welcome.
I didn’t read your code so carefully, I guess you can just make the pixels to units 100, it works in similar manner to Canvas Scaler’s Reference PPU - In this case it’s inverse IIRC, smaller the value, bigger the pixels are on screen.
EDIT: So, if you keep it at 1, you are going to have very pixelated effect…