Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this attempts to get the info from Application.projectSettings (Product Name & Company Name) at runtime
- public static void GetProjectInfo() {
- // persistent path usually contains both company name and project name
- string path = Application.persistentDataPath;
- string[] dirs = path.Split(Path.DirectorySeparatorChar);
- // make sure the path was split properly
- if (dirs.Length < 2) {
- dirs = path.Split(Path.AltDirectorySeparatorChar);
- // see if it worked that time
- if (dirs.Length < 2) {
- // still not getting a full path for some reason
- Debug.LogWarning(string.Format("Can't parse Company or Product name for some reason.\n{0}", path));
- return;
- }
- }
- // use temporary strings so we can easily change the real ones later
- string pName;
- string cName;
- #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX
- // path will be something like [persistentPath]/CompanyName/GameName
- pName = dirs[dirs.Length - 1];
- cName = dirs[dirs.Length - 2];
- #elif UNITY_ANDROID
- // path will be something like data/data/com.CompanyName.ProductName/files
- dirs = dirs[dirs.Length - 2].Split('.');
- pName = dirs[2];
- cName = dirs[1];
- #endif
- // don't overwrite company name if it was manually set elsewhere
- if (string.IsNullOrEmpty(_companyName)) { _companyName = cName; }
- // don't overwrite product name if it was manually set elsewhere
- if (string.IsNullOrEmpty(_productName)) { _productName = pName; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement