A collection of scripts for C#
-
RoWa.LoCa.cs (Simple localization system)
-
RoWa.Xamarin.LoCa.cs (Simple localization system for Xamarin)
-
RoWa.Functions.cs (Various useful functions)
-
RoWa.Xamarin.Functions.cs (Various useful functions for Xamarin)
-
RoWa.Debug.cs (Debugging system)
-
RoWa.Settings.cs (Settings system)
-
RoWa.Networking.cs (Networking functions)
-
RoWa.Serializer.cs (Object serializer)
-
RoWa.Game.cs (Useful game functions)
-
RoWa.Game.GameTime.cs (Gametime system)
-
RoWa.Game.SaveHandler.cs (Savegame system)
-
RoWa.Xamarin.WebControls.cs (Xamarin WebControls)
C# 4.0+
Xamarin.Android 9.0+ Xamarin.iOS and Xamarin.Forms not tested! (RoWa.Xamarin.WebControls only works with Android!)
RoWa.LoCa.Init(LOCALIZATION_FILES_DIRECTORY);
RoWa.LoCa.Init("/localization");
RoWa.LoCa.Init(LOCALIZATION_FILES_DIRECTORY,DEFAULT_LANGUAGE);
RoWa.LoCa.Init("/localization","en");
RoWa.LoCa.Init(LOCALIZATION_FILES_DIRECTORY,DEFAULT_LANGUAGE,EXTENSION);
RoWa.LoCa.Init("/localization","en",".txt");
RoWa.LoCa.Trans(KEY);
RoWa.LoCa.Trans("word");
RoWa.LoCa.Translate("word");
SetDefault(KEY);
SetDefault("en");
SetDefault(LANGUAGE_OBJECT);
SetLanguage(KEY);
SetLanguage("en");
SetLanguage(LANGUAGE_OBJECT);
Xamarin
The Xamarin version of RoWa.LoCa.cs is identical to the main version of the script. The only difference is the way the data is saved and the way it is loaded.
The data has the same structure as in the main version, but it is saved as Android Asset. To load it simply write the assets directory to the RoWa.Xamarin.LoCa.Init() function like this:
RoWa.Xamarin.LoCa.Init("localization"); //Loads all files from the directory 'Project/Assets/localization'
With the newest update I did add a function to add placeholders to the translations which then will be replaced by code.
LanguageFile:
test1=This is a {TEST}
test2=You can set different {KEY1} with a {KEY2}
test3=You can also set unlimited {KEY1} with the new {KEY2}
Code:
KeyValuePair<string,string> kvp = new KeyValuePair<string,string>("{TEST}","Test");
RoWa.Xamarin.LoCa.Trans("test1",kvp); //output: This is a Test
Dictionary<string,string> dict = new Dictionary<string,string>();
dict.add("{KEY1}","keys");
dict.add("{KEY2}","dictionary");
RoWa.Xamarin.LoCa.Trans("test2",dict); //output: You can set different keys with a dictionary
KeyValuePair<string,string> vp1 = new KeyValuePair<string,string>("{KEY1}","KeyValuePairs");
KeyValuePair<string,string> vp2 = new KeyValuePair<string,string>("{KEY2}","system");
RoWa.Xamarin.LoCa.Trans("test3"),vp1,vp2); //output: You can slo set unlimited KeyValuePairs with the new system
IsUserAdmin(); //Returns true if user is admin
string message = "make a hash out of me!";
Hashtype ht = HashType.SHA256;
GetHash(message,ht);
double value = 50.25;
string prefix = "ÂŁ";
DoubleToCurrency(value,prefix);
//Not for production!
//Not for production!
ResizeControl(CONTROL);
//Shuffles a list of strings
List<string> lst = new List<string>();
lst.Add("a");
lst.Add("b");
Shuffle(lst);
byte[] arr = new byte[]{ 0,1,2,3,4,5 };
SliceBytes(arr, 1, false); //arr = 0,1,2,3,4
SliceBytes(arr, 2, true); //arr = 2,3,4,5
double degrees = 45;
DegreesToRadians(degrees);
//Get distance from 2 Coordinates objects
Coordinates c1 = new Coordinates(1,1);
Coordinates c2 = new Coordinates(2,2);
GetDistance(c1, c2);
//Get distance from decimal values
decimal lat1 = 10;
decimal long1 = 10;
decimal lat2 = 11.5;
decimal long2 = 12.5;
GetDistance(lat1, long1, lat2, long2);
Same as RoWa.Functions.cs but without some Desktop only functions
logdir = "/directory/from/log";
string message = "this is a log message";
//Standart Log
Log(message);
//Exception Log
ExceptionLog(new Exception(message));
//Warning Log with popup
WarningLog(message, true);
//Warning Log without popup
WarningLog(message, false);
//Empty Log
EmptyLog();
RoWa.Settings.Location = "settings.cfg" //Sets the location of the file (default is "settings.cfg"
RoWa.Settings.Load(); //Loads the settings from the file
RoWa.Settings.SetValue("language","en"); //Adds/Updates the value to the settings and saves the file
RoWa.Settings.RemoveValue("language"); //Removes the value from the settings and saves the file
RoWa.Settings.GetValue<T>("language"); //Returns a variable from type T with the value
Includes WebServer, Server and Client objects.
RoWa.Networking.WebServer ws = new RoWa.Networking.WebServer("www.rowa-digital.ch"); //Creates a new WebServer for the url
RoWa.Networking.WebServer wsNoSSL = new RoWa.Networking.WebServer("www.rowa-digital.ch",false); //Creates a new WebServer from the url with SSL disabled
ws.SetSubs("sub","sub2"); //Sets the sub folders for the WebServer (https://www.rowa-digital.ch/sub/sub2/)
ws.SetSubs(); //Sets the directory of the WebServer back to root
ws.GetString("page.html"); //Returns the content of www.rowa-digital.ch/page.html as a string
ws.GetData("page.html"); //Returns the content of www.rowa-digital.ch/page.html as a byte array
ws.DownloadFile("file.txt","destination.txt"); //Downloads the file www.rowa-digital.ch/page.html to destination.txt
KeyValuePair<string,string> content1 = new KeyValuePair<string,string>("key1","value1");
KeyValuePair<string,string> content2 = new KeyValuePair<string,string>("key2","value2");
ws.GetString("page.html", content1, content2); //Returns the content of www.rowa-digital.ch/page.html as a string with the GET parameters set
ws.GetData("page.html", content1, content2); //Returns the content of www.rowa-digital.ch/page.html as a byte array with the GET parameters set
ws.DownloadFile("file.txt","destination.txt", content1, content2); //Downloads the file www.rowa-digital.ch/page.html to destiantion.txt with the GET parameters set
ws.GetPostString("page.html", content1, content2); //Returns the content of www.rowa-digital.ch/page.html as a string with the POST parameters set
Not included in actual version!
Not included in actual version!
- For XML Serialization you'll need to include the System.Xml Assembly
- For JSON Serialization you'll need to include the Newtonsoft.JSON Nuget ( https://www.nuget.org/packages/Newtonsoft.Json/ )
[Serializable]
public class TestObject
{
public long Id = 1;
public string Name = "test";
public int Number = 5;
}
TestObject to = new TestObject();
RoWa.Serializer.Binary.WriteToFile("test.dat",to,false); //Writes the object to a binary file (Object needs to be 'Serializable'!)
RoWa.Serializer.Xml.WriteToFile("test.xml",to,false); //Writes the object to a XML file (Needs to include System.Xml Assembly and function needs to be uncommented)
RoWa.Serializer.Json.WriteToFile("test.json",to,false); //Writes the object to a JSON file (Needs to include Newtonsoft.Json NuGet and function needs to be uncommented)
RoWa.Serializer.Binary.ReadFromFile<TestObject>("test.dat"); //Returns the object from a binary file
RoWa.Serializer.Xml.ReadFromFile<TestObject>("test.xml"); //Returns the object from a XML file
RoWa.Serializer.Json.ReadFromFile<TestObject>("test.json"); //Returns the object from a JSON file
//Vector2
RoWa.Game.Vector2 v21 = RoWa.Game.Vector2(); //Creates an empty Vector2 value
RoWa.Game.Vector2 v22 = RoWa.Game.Vector2(5,5); //Creates a Vector2 value with x and y values
RoWa.Game.Vector2.Compare(v21,v22); //Returns a Vector2 value with the difference between v21 and v22
RoWa.game.Vector2.Distance(v21,v22); //Returns a float with the distance between v21 and v22
RoWa.Game.Vector2.Parse("5/5"); //Creates a Vector2 value with x and y values from a string
RoWa.Game.Vector2 vout;
RoWa.Game.Vector2.TryParse("5/5", out vout); //Tries to create a Vector2 value with x and y values from a string to vout and returns true if it could parse it or false if not
//Vector3
RoWa.Game.Vector3 v31 = RoWa.Game.Vector3(); //Creates an empty Vector3 value
RoWa.Game.Vector3 v32 = RoWa.Game.Vector3(5,5,5); //Creates a Vector3 value with x, y and z values
RoWa.Game.Vector3.Compare(v31,v32); //Returns a Vector3 value with the difference between v31 and v32
RoWa.game.Vector3.Distance(v31,v32); //Returns a float with the distance between v31 and v32
RoWa.Game.Vector3.Parse("5/5/5"); //Creates a Vector2 value with x, y and z values from a string
RoWa.Game.Vector3 vout;
RoWa.Game.Vector3.TryParse("5/5/5", out vout); //Tries to create a Vector3 value with x, y and z values from a string to vout and returns true if it could parse it or false if not
RoWa.Game.GameTime gt1 = new RoWa.Game.GameTime(); //Creates a default gametime with 1 second per tick
RoWa.Game.GameTime gt2 = new RoWa.Game.GameTime(500,false); //Creates a default gametime with 1 second per tick, an interval of 500ms and it won't autostart
RoWa.Game.GameTime gt3 = new RoWa.Game.GameTime(0,0,0,1,1,1,500); //Creates a default gametime with 1 second per tick and it starts with 0 hours, minutes seconds and 1 day, month and year and an interval of 500ms
RoWa.Game.GameTime gt4 = new RoWa.Game.GameTime(0,0,0,1,1,1,0,5,0,0,0,0,500); //Creates a gametime with 5 minutes per tick and it starts with 0 hours, minutes seconds and 1 day, month and year and an interval of 500ms
gt2.Start(); //Starts the gametime if it's not started already
gt2.Stop(); //Stops the gametime if it's not stopped already
gt2.ToString("d.m.yyyy h:m:s"); //Gets the time with the format 'd.m.yyyy h:m:s
gt2.Tick(5); //Manually ticks 5 seconds
RoWa.Game.SaveHandler.SaveDirectory = "Savefiles" //Sets the directory of the savefiles
RoWa.Game.SaveHandler.SaveExtension = ".save" //Sets the extension of the savefiles
RoWa.Game.SaveHandler.SaveFile sf1 = new RoWa.Game.SaveHandler.SaveFile("game1"); //Loads or creates a new savefile
RoWa.Game.SaveHandler.SaveFile sf2 = new RoWa.Game.SaveHandler.SaveFile("game1","savename"); //Loads or creates a new savefile with a custom name 'savename'
RoWa.Game.SaveHandler.SaveFile sf3 = new RoWa.Game.SaveHandler.SaveFile("game1","",false); //Creates a new savefile but doesn't load it
sf3.Load(); //Manually loads the savefile
sf1.Add("player_points",1000); //Adds a value to the Savefile data
sf1.Get("player_points"); //Returns a value from the Savefile data
sf1.Remove("player_points"); //Removes a value from the Savefile data
RoWa.Game.Vector2 v = new RoWa.Game.Vector2(5,5);
sf2.Add("player_position",v); //Adds a special object to the Savefile data. (Vector2 and Vector3 are supported)
sf2.Save(); //Saves the data to the savefile
- Download bootstrap.min.css and copy it into your Assets/bootstrap folder.
- Create a custom.css file inside your Assets/bootstrap folder.
- TODO
//TODO