I'm developing a project in Unity where I use .CSV files to collect data to be used in the project. An important fact is that I'm developing the project with the operative system (OS) region in Spanish (Spain, international).
I use this .CSV file to list actions that I want my characters to perform in the game, such as moving from the current position to point A or stay still in the position for X seconds. In the .CSV I save the data as a string, but when I introduce 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 are attached to an object that receives the action and it executes perfectly.
The problem came when I sent a build to Steam to validate the project and they notified me that they couldn't advance because the characters didn't move (the game worked, but nothing moved).
After many tests, I found the problem. It turns out that if the OS where the project's build is executed is in a region different from Spanish (Spain, international), for example in English (United Kingdom), the game runs but nothing moves in the times I originally programmed.
This problem comes because each region has a different decimal system, for example, in Spain the points are used to indicate the units and the commas to indicate the decimals ("1.234,24") and in England it is the opposite ("1,234.24"), so if I declare that my character will wait (WAIT) for "0,2" seconds (Spain), in an OS with English (United Kingdom) region, it will be "20" seconds, because it interprets the commas as unit separators. The same happens with MOVE actions.
In order not to have to change the region of my OS, I changed the commas to dots in the .CSV to move the problem to my region and make the necessary tests. So I could prove that if I put "3.00" (which would be 3 seconds) my OS interprets it as 3 minutes.
My question is: how could I solve this so that the timers works how I want no matter what region is the OS running?
I tried to make a manual parse from string to float by changing the dot to the comma, but I realized that even if I fixed the error in my region, it would move to another region.
Is there a way to configure the project so that it always used a specific number system independent from the OS? I mean, to understand the comma as a decimal and to use it for that purpose whatever the region is.
I tried System.Globalization.CultureInfo
, but I didn't get anything (or I didn't fully understand it).
Is there a way to create a manual parser that works in any region?
Thank you very much.