Good morning everyone!
I am developing a project in Unity where I use .CSV files to collect the data to be used in the project. Important fact is that I am developing the project with the region of the operating system (OS) in Spanish (Spain, international).
I use this .CSV to list a series of actions that I want my characters to perform within the game, such as moving from the point where they are to point A or waiting for the current position for X seconds. In the .CSV I save the data as a string, but when entering it in the project I need it as a float:
- MOVE: float Velocity, float Position.x, float Position.y, float Position.z
- WAIT: float Time
Any of these actions is bound to an object that receives this action and executes perfectly.
The problem arose when I sent a build to Steam to validate the project and they notified me that they had not been able to advance because the characters did not move (the game worked, but nothing moved).
After many tests, I found the problem. It turns out that if the OS where the project build is run is in a region other than Spanish (Spain, international), such as English (United Kingdom), the game runs but nothing moves at the times originally I programmed.
This problem is given because each region has a different decimal system, for example, in Spain dots are used to indicate units and commas to indicate decimals ("1,234.24") and in England it is the opposite ("1,234.24 "), so if I declare my character to wait (WAIT) for "0.2" seconds (Spain), in an OS with English (United Kingdom) region, it will be "20" seconds, because it interprets commas as unit separator. The same goes for MOVE actions.
To avoid having to change my OS region, I changed the commas to periods in the .CSV to translate the problem to my region and do the necessary tests. With what I could test the direct that if I put "3.00" (which would be 3 seconds) my OS interprets it as 3 minutes.
My question is how can I fix this so that it works at the times I want regardless of the region of the OS it's running on?
I tried to do a manual parse from string to float by changing the dot to a comma, but I realized that even if it fixed the error in my region, it would carry over to another region.
Is there a way to configure the project to always use a particular number system independent of the OS? That is, interpret the comma as a decimal and use it for that purpose regardless of the region.
I tried with System.Globalization.CultureInfo
, but I didn't get anything (or I didn't finish understanding it).
Is there a way to create a manual parse that works in any region?
Thank you very much in advance.