Advertisement
Deozaan

GetProjectInfo function

Sep 17th, 2014
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. // this attempts to get the info from Application.projectSettings (Product Name & Company Name) at runtime
  2. public static void GetProjectInfo() {
  3.     // persistent path usually contains both company name and project name
  4.     string path = Application.persistentDataPath;
  5.  
  6.     string[] dirs = path.Split(Path.DirectorySeparatorChar);
  7.  
  8.     // make sure the path was split properly
  9.     if (dirs.Length < 2) {
  10.         dirs = path.Split(Path.AltDirectorySeparatorChar);
  11.         // see if it worked that time
  12.         if (dirs.Length < 2) {
  13.             // still not getting a full path for some reason
  14.             Debug.LogWarning(string.Format("Can't parse Company or Product name for some reason.\n{0}", path));
  15.             return;
  16.         }
  17.     }
  18.  
  19.     // use temporary strings so we can easily change the real ones later
  20.     string pName;
  21.     string cName;
  22.  
  23. #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX
  24.     // path will be something like [persistentPath]/CompanyName/GameName
  25.     pName = dirs[dirs.Length - 1];
  26.     cName = dirs[dirs.Length - 2];
  27. #elif UNITY_ANDROID
  28.     // path will be something like data/data/com.CompanyName.ProductName/files
  29.     dirs = dirs[dirs.Length - 2].Split('.');
  30.     pName = dirs[2];
  31.     cName = dirs[1];
  32. #endif
  33.  
  34.     // don't overwrite company name if it was manually set elsewhere
  35.     if (string.IsNullOrEmpty(_companyName)) { _companyName = cName; }
  36.     // don't overwrite product name if it was manually set elsewhere
  37.     if (string.IsNullOrEmpty(_productName)) { _productName = pName; }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement