private static void BuildGame(BuildTargetPlatform targetPlatform)
        {
            EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
            List <string> scenesPath          = new List <string>();

            foreach (EditorBuildSettingsScene scene in scenes)
            {
                if (scene.enabled)
                {
                    scenesPath.Add(scene.path);
                }
            }

            string fullPath  = PlayerPrefs.GetString("BUILD_PATH", "");
            string buildPath = string.IsNullOrEmpty(fullPath) ? "" : Path.GetDirectoryName(fullPath);
            string appName   = Path.GetFileName(fullPath);

            fullPath = EditorUtility.SaveFilePanel("Choose Location of Built Game", buildPath, appName, "");

            if (!string.IsNullOrEmpty(fullPath))
            {
                if (onStartBuilding != null)
                {
                    onStartBuilding();
                }

                //Hide unused assets
                ResourceManager.Hide();


                PlayerPrefs.SetString("BUILD_PATH", fullPath);
                PlayerPrefs.Save();

                #region Save old settings

                string oldBundleId          = PlayerSettings.bundleIdentifier;
                string oldBundleVersion     = PlayerSettings.bundleVersion;
                int    oldBundleVersionCode = PlayerSettings.Android.bundleVersionCode;
                bool   oldSplitApplication  = PlayerSettings.Android.useAPKExpansionFiles;

                #endregion


                #region Change settings

                PlayerSettings.bundleIdentifier             = BuildSettings.bundleId[targetPlatform];
                PlayerSettings.bundleVersion                = BuildSettings.bundleVersion[targetPlatform];
                PlayerSettings.Android.bundleVersionCode    = BuildSettings.bundleVersionCode[targetPlatform];
                PlayerSettings.Android.useAPKExpansionFiles = BuildSettings.splitApplication[targetPlatform];

                #endregion

                try
                {
                    // Build player
                    BuildPipeline.BuildPlayer(scenesPath.ToArray(), fullPath, BuildSettings.buildTarget[targetPlatform], BuildOptions.None);

                    //Rename obb file
                    if (BuildSettings.splitApplication[targetPlatform])
                    {
                        FileInfo apkInfo     = new FileInfo(fullPath);
                        string   obbFilePath = fullPath.Replace(apkInfo.Extension, ".main.obb");

                        FileInfo obbInfo = new FileInfo(obbFilePath);

                        string obbNewPath = string.Format("{0}/main.{1}.{2}.obb", obbInfo.Directory.FullName,
                                                          BuildSettings.bundleVersionCode[targetPlatform],
                                                          BuildSettings.bundleId[targetPlatform]);

                        if (File.Exists(obbNewPath))
                        {
                            File.Delete(obbNewPath);
                        }
                        File.Move(obbFilePath, obbNewPath);
                    }
                }
                finally
                {
                    //Restore unused assets
                    ResourceManager.Restore();
                }

                #region Restore old settings

                PlayerSettings.bundleIdentifier             = oldBundleId;
                PlayerSettings.bundleVersion                = oldBundleVersion;
                PlayerSettings.Android.bundleVersionCode    = oldBundleVersionCode;
                PlayerSettings.Android.useAPKExpansionFiles = oldSplitApplication;

                #endregion


                if (onFinishBuilding != null)
                {
                    onFinishBuilding();
                }
            }
        }
		private static void BuildGame(BuildTargetPlatform targetPlatform)
		{
			EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
			List<string> scenesPath = new List<string>();
			foreach(EditorBuildSettingsScene scene in scenes)
			{
				if (scene.enabled)
				{
					scenesPath.Add(scene.path);
				}
			}
			
			string fullPath = PlayerPrefs.GetString("BUILD_PATH", "");
			string buildPath = string.IsNullOrEmpty(fullPath) ? "" : Path.GetDirectoryName(fullPath);
			string appName = Path.GetFileName(fullPath);
			
			fullPath = EditorUtility.SaveFilePanel("Choose Location of Built Game", buildPath, appName, "");
			
			if (!string.IsNullOrEmpty(fullPath))
			{
				if (onStartBuilding != null)
				{
					onStartBuilding();
				}

				//Hide unused assets
				ResourceManager.Hide();

				
				PlayerPrefs.SetString("BUILD_PATH", fullPath);
				PlayerPrefs.Save();

	#region Save old settings

				string oldBundleId = PlayerSettings.bundleIdentifier;
				string oldBundleVersion = PlayerSettings.bundleVersion;
				int oldBundleVersionCode = PlayerSettings.Android.bundleVersionCode;
				bool oldSplitApplication = PlayerSettings.Android.useAPKExpansionFiles;

	#endregion


	#region Change settings
				
				PlayerSettings.bundleIdentifier = BuildSettings.bundleId[targetPlatform];
				PlayerSettings.bundleVersion = BuildSettings.bundleVersion[targetPlatform];
				PlayerSettings.Android.bundleVersionCode = BuildSettings.bundleVersionCode[targetPlatform];
				PlayerSettings.Android.useAPKExpansionFiles = BuildSettings.splitApplication[targetPlatform];

	#endregion

				try
				{
					// Build player
					BuildPipeline.BuildPlayer(scenesPath.ToArray(), fullPath, BuildSettings.buildTarget[targetPlatform], BuildOptions.None);

					//Rename obb file
					if (BuildSettings.splitApplication[targetPlatform])
					{
						FileInfo apkInfo = new FileInfo(fullPath);
						string obbFilePath = fullPath.Replace(apkInfo.Extension, ".main.obb");

						FileInfo obbInfo = new FileInfo(obbFilePath);

						string obbNewPath = string.Format("{0}/main.{1}.{2}.obb", obbInfo.Directory.FullName, 
						                                  BuildSettings.bundleVersionCode[targetPlatform], 
						                                  BuildSettings.bundleId[targetPlatform]);

						if (File.Exists(obbNewPath))
						{
							File.Delete(obbNewPath);
						}
						File.Move(obbFilePath, obbNewPath);
					}
				}
				finally
				{
					//Restore unused assets
					ResourceManager.Restore();
				}

	#region Restore old settings
				
				PlayerSettings.bundleIdentifier = oldBundleId;
				PlayerSettings.bundleVersion = oldBundleVersion;
				PlayerSettings.Android.bundleVersionCode = oldBundleVersionCode;
				PlayerSettings.Android.useAPKExpansionFiles = oldSplitApplication;

	#endregion


				if (onFinishBuilding != null)
				{
					onFinishBuilding();
				}
			}
		}