Can’t get the exact iPhone notch size in Unity - c#

Getting the notch size isn't supported in Unity.
I've tried to first get the notch size for all iOS devices in Xcode and then convert them to pixels in Unity but it’s always wrong and I’m not sure why.
No information regarding this can be found on the internet - I think this is because no games require knowing the exact notch size for every iOS device especially in Unity but in my case, I do need it so I can do something with it.
It would be nice to be able to get the position as well (notch and 14 Pro's island)
I know how to handle safe area in Unity. This is not about that. This is about getting the notch size.
Since hardcoding seems to be the only option at this point, I convert these values to px because Xcode uses pt and Unity uses px. However things become too small in Unity when I do that.
var size: CGSize {
switch self {
case .large:
if UIDevice.current.hasSmallNotchArea {
return .init(width: 206.30, height: 29.10)
} else {
return .init(width: 207.50, height: 31.30)
}
case .medium:
return .init(width: 160.90, height: 33.20)
case .pill:
return .init(width: 124, height: 35.20)
}
}

It doesn't seem like Unity has any support for giving you that info, so your best bet will likely be to make your own solution by getting the "DeviceGeneration", figuring out if you're on one with the notch and then having a catalogue of the different notch sizes and positions to return.
Probably not what you wanted to hear, but unless someone has put it up as a github repo I couldn't track down, I think you might have to forge the way on this one.
Also instead of using pixels, would likely be more reliable to use percentages and space from the edges to generate it on the fly.

Related

Best way to implement a 2D hex-based/isometric grid system in Unity (for complex tiles)?

I'm trying to create a grid system for a 2D game. Not completely sure if I'll go with a hexagon-grid or isometric, but which shouldn't matter too much here. Basically, I'm trying to create a tower defense game where you deploy units instead of towers, and can move those as if you were playing a tactical game. The problem is that the tiles themselves are gonna be complex - there will be different types of terrain. Some units can only be deployed in X, and can't go through Y, that kind of thing. I also need the ability to add some logic to these tiles at will - who knows, maybe I want a special tile to give extra attack range to units above it, that kind of thing. The game must also "feel" like a grid - making things snap to the center of the tiles, as well as highlighting the tiles on hover and when moving/attacking.
Okay, this leads me to a pretty obvious route: I can create prefabs for the different types of tiles I need, add all the proprieties and logic as script components and create a grid class that instantiates each tile in the world. This works great, cause this way I have full control over everything - I can do whatever I want with the tiles, and I can also create a 2d matrix for their positions as I instantiate them. This way I can call tile[3, 6] for example, which sounds like a huge deal for pathing, highlighting and such. I can also link whatever gameobject is on top of it to the tile itself, so I could call something like tile[6, 2].ObjectOnTop.~WhateverInfoINeedFromIt, which also sounds super handy for overall logic.
But the shortcomings are also terrible - how do I even design and deploy different levels designs? The only way I can think of it is to figure out a way to do it all by hand, export that info somehow to a json file, and have the grid class that instantiates everything select which tile will be instantiated where based on the json info. I not only have no idea how to actually implement that, but I also think it would be an absurd amount of work for something that is supposed to be natural. I'm also not sure if a gameobject for each tile is a good idea in terms of performance. The biggest problem? It's easy to create such a grid if it's a simple squared tiles grid - but when we start talking about hexagons and isometric grids... it's not nearly as easy, honestly. The complex shapes make it so difficult to work with this kind of thing. For example, how do I even convert the mouse position into the equivalent tile? It's super easy for squares... not so much for the rest. It also kind of sucks that the grid is only really deployed when the game runs (is this generally considered a bad thing that I should avoid, btw?).
But don't worry, cause I've found the solution: tilemaps! Of course! It fixes all the problems I have, right? Supposedly yes, but it also removes all the power I had from having prefabs. Now I can't have any logic with tiles... They can't store any properties... so I'm doomed, I guess. I've read a bit on ways to overcome this (prefab brushes, custom classes inherenting from Tile, making a tilemap for each tile type), but they are honestly extremely niche and just don't feel right.
It's so weird, a generic grid system like this was supposed to be so simple and common. But I can barely find any information at all. It's like I'm missing this pretty obvious tool that no one seems to mention cause it's that obvious. So here I am, struggling to start a project cause I can't even figure out how to implement the basic structure of the game. Everything I see online leads me to tilemaps - but they only work for very basic stuff, from what I understood. I won't work for this kind of game, I think. I have no idea what to do at this point - there must be an optimal way to solve everything, the one that is likely used for all the devs that work on this kind of game. And honestly, there are a ton of them.
So, please, shed me some light. And thanks a lot in advance!
(Here's someone that posted an extremely similar question: Per Tilemap Tile Data Storage & Retrieval)
I have the exact same problem. The best i found is this: https://m.youtube.com/playlist?list=PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722
It is playlist by CodeMonkey where he creates grid by script but also adding generics, which allow you to have that logic that you want and adding visual tiles. The only problem is that while I want squares while you want different shapes. I don't know how to do that, maybe you can adjust the grid(more likely tilemap it uses to display visuals) or maybe you should just let go of different shapes, i don't know.
Hope i helped at least little. I seen this post and it is very sad that noone replied to you. Hope you can achieve what you want and that it will be succes. Good luck and mainly have fun : )
convert mouse position to tile position can be done different ways, simplest would be to raycast the mouse and see if it hits a tile
probably easiest to make a 2dimensional array of tiles of class 'Tile', even if its hex break it down into a 2d array and offset , setup the tiles dynamically in code
for pathing and such djikstra algorithm is pretty useful
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
May be it can help
grid = new gridSpace[roomWidth + 3, (roomWidth / 2) + 2];
int xStep = 4; # 2:1 isometry type
for (int x = 0; x < roomWidth - 1; x += xStep) #xStep depends by type of isometry
{
int minX = x;
int maxX = x + 2;
int localX = x;
for (int y = roomWidth / 2; y > -1; y--)
{
grid[localX, y] = gridSpace.empty;
if (localX == minX)
{
localX = maxX;
}
else
{
localX = minX;
}
}
}

Dynamic editor window is not correctly scaling

Afternoon, Recently while trying to develop the more; Err Graphical part of my 'Editor Extension', Through towards unity3d's Audience I've been looking at creating more of a dynamic window for screen sizes!
Throughout my testing I've noticed many hard-core glitches that I cannot seem to persuade, Currently I've tried "doubles, int, float, etc.. etc..", Though my issue might just be with unity, I'm sure someone here has had this event occur while attempting to scale their "Editor Application", Here are some visual representations of the variable issues i've been having.
Error && Success Image Collection!
Upon my Journey of Dynamic Screen Fitting Here is some of my current attempted code that I have within my project for the window as of now.
private Rect Topic_Selection_Rect_Window = new Rect(5, 5, Screen.width / 6, 350);
static void Init()
{
EditorWindow Toolbox = GetWindowWithRect(typeof(Toolbox), new Rect(0, 0, 1250, 900));
Toolbox.Show();
}
private void OnGUI()
{
BeginWindows();
GUILayout.Window(0, Topic_Selection_Rect_Window, Topic, "Please Select A Listed Topic!");
EndWindows();
}
private void Topic(int id)
{
GUILayout.TextField("pre-text");
}
Now with the code shown above, We Have on the "Price rect topic_selection_rect_window", We have the idea that 'Oh, we can just use the API for 'Screen.width', Though initially i've noticed that the idea of that is knowing the users screen - information, Though the reality of it is I'm thinking that initally it's all wonky for inital load to get user-information which I need to entail an idea on how to attempt to get that upon init, Though i've tried hasn't seemed to work accordingly, Though once I load and it's all wonky and I exit and load again it's less wonky and one last time and it's fine; I've had some issues for some time such as "Screen.height" never seems to work and give me a good ## or Screen %% availability and just tends to not work with my monitor or what; I'm fairly new to programming and I'm looking to figure out how this API works, etc thanks for any
comments / answers!
-- DrEncompass --
After-Hours of tinkering, I'd have given up while messing around I later had an issue with my window not being able to have de-bugging and I had to re-boot Unity3d Every-time I had crashed my Editor-Window, So after some messing around I figured I could just directly call the window with the [.show();], And so far it's appearing to be a strong solution!

Do something similar to Auto Tone of Photoshop with Aforge.net or c#

Im developing an image skin detection app.
But there is a problem with my camera, that try to compensate the light and the result image is bad, in most of cases i have a cold or warm effect on the image.
When i use photoshop there is the AutoTone function that normalize an image and reduce this problem.
With aforge i want to use HistogramEqualization() filter but the result is very bad:
// create filter
HistogramEqualization filter = new HistogramEqualization( );
// process image
filter.ApplyInPlace( sourceImage );
So my question is:
There is a function in Accord or Aforge to have the same result of the autotone of Photoshop?
If not, there is some library or script that let to do this?
Thank you all.
I use the LevelsLinear filter and base it on image stats:
ImageStatistics stats = new ImageStatistics(sourceImage);
LevelsLinear levelsLinear = new LevelsLinear {
InRed = stats.Red.GetRange( 0.90 ),
InGreen = stats.Green.GetRange( 0.90 ),
InBlue = stats.Blue.GetRange( 0.90 )
};
levelsLinear.ApplyInPlace(sourceImage);
You can play with the range to tweak the result.
You probably don't want to equalize the histogram, because as you see, a photo that wouldn't normally have much red, would have alot of red created and make it look nasty. Instead you probably want to examine for a bias to a hue that occurs almost everywhere. For example, your original photo probably had a bias towards blue in almost every pixel, and thus probably shouldn't be there. Look for a minimum bias and remove that amount everywhere.
A more practical solution is to experiment with the white balance setting on your camera to see what gives you the best result. Choosing the right preset, will leverage an algorithm that's probably as good as what you would write by hand. But maybe you are doing this as a learning experience.

Screen Region Recognition to Find Field location on Screen

I am trying to figure out a way of getting Sikuli's image recognition to use within C#. I don't want to use Sikuli itself because its scripting language is a little slow, and because I really don't want to introduce a java bridge in the middle of my .NET C# app.
So, I have a bitmap which represents an area of my screen (I will call this region BUTTON1). The screen layout may have changed slightly, or the screen may have been moved on the desktop -- so I can't use a direct position. I have to first find where the current position of BUTTON1 is within the live screen. (I tried to post pictures of this, but I guess I can't because I am a new user... I hope the description makes it clear...)
I think that Sikuli is using OpenCV under the covers. Since it is open source, I guess I could reverse engineer it, and figure out how to do what they are doing in OpenCV, implementing it in Emgu.CV instead -- but my Java isn't very strong.
I looked for examples showing this, but all of the examples are either extremely simple (ie, how to recognize a stop sign) or very complex (ie how to do facial recognition)... and maybe I am just dense, but I can't seem to make the jump in logic of how to do this.
Also I worry that all of the various image manipulation routines are actually processor intensive, and I really want this as lightweight as possible (in reality I might have lots of buttons and fields I am trying to find on a screen...)
So, the way I am thinking about doing this instead is:
A) Convert the bitmaps to byte arrays and do brute force search. (I know how to do that part). And then
B) Use the byte array position that I found to calculate its screen position (I'm really not completely sure how I do this) instead of using the image processing stuff.
Is that completely crazy? Does anyone have a simple example of how one could use Aforge.Net or Emgu.CV to do this? (Or how to flesh out step B above...?)
Thanks!
Generally speaking, it sounds like you want basic object recognition. I don't have any experience with SIKULI, but there are a number of ways to do object recognition (Edge based template matching, etc.). That being said you might be able to go with just straight histogram matching.
http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx
That page should show you how to use AForge.net to get the histogram of an image. You would just do a brute force search using something like this:
Bitmap ImageSearchingWithin=new Bitmap("Location of image"); //or just load from a screenshot or whatever
for (int x = 0; x < ImageSearchingWithin.Width - WidthOfImageSearchingFor; ++x)
{
for (int y = 0; y < ImageSearchingWithin.Height - HeightOfImageSearchingFor; ++y)
{
Bitmap MySmallViewOfImage = ImageSearchingWithin.Clone(new Rectangle(x, y, WidthOfImageSearchingFor, HeightOfImageSearchingFor), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
}
}
And then compare the newly created bitmap's histogram to the one that you calculated of the original image (whatever area is the closest in terms of matching is what you would select as being the region of BUTTON1). It's not the most elegant solution but it might work for your needs. Otherwise you get into more difficult techniques (of course I could be forgetting something at the moment that might be simpler).

filter pornography in a video/picture c# library

How can you filter pornography in a video/picture?
Is there a library I can use? Commercial or open source is OK.
For Video:
You would analyze the sound waves from the video. If there's lot of grunting and moans, find a way to recognize those patterns and label it as porn. However, you might get false tags for women's tennis match.
For Image:
Build a simulation model of a human brain which signals arousal from viewing erotic pictures. Some paramters would be excessive curves, and image recognition of the human anatomy. This is far more difficult.
If it is not a real-time, you could use Amazon's Mechanical Turk to do the work. You'll have to pay the workforce, but it's a very cheap way to get menial jobs like this done.
See, Porn Detection is not a very easy.
But there is surely a range of color that identifies the human skin. And you need to make a threshold of the color to identify the picture as porn. Say you take it as 70 %, so you go through all the pixel on the current screen and determine whether 70% of the pixels comes within the range of human skin color.
There is already few algorithm prepared for Face detection like :
http://www.codeproject.com/KB/cs/Face_Detection_processing.aspx
I hope this would help you to find a way on your point.

Categories