PostProcessBuild_WT.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEditor;
  7. using UnityEditor.Callbacks;
  8. namespace Imagine.WebAR.Editor
  9. {
  10. public class PostProcessBuild_WT : MonoBehaviour
  11. {
  12. [PostProcessBuild]
  13. public static void OnPostProcessBuild(BuildTarget target, string buildPath)
  14. {
  15. string html = File.ReadAllText(buildPath + "/index.html");
  16. var geolocSceneCount = WorldTrackerGlobalSettings.Instance.geolocationScenes.Count;
  17. var includedSceneCount = 0;
  18. foreach( var scenePath in WorldTrackerGlobalSettings.Instance.geolocationScenes){
  19. foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
  20. {
  21. if (scene.path == scenePath)
  22. {
  23. includedSceneCount++;
  24. continue;
  25. }
  26. }
  27. }
  28. if(includedSceneCount > 0){
  29. //we enable GPS in the template
  30. Debug.Log("Enabling geolocation - used by " + geolocSceneCount + " scenes");
  31. html = html.Replace("//Call Start GPS here --> StartGPS();", "StartGPS()");
  32. File.WriteAllText(buildPath + "/index.html", html);
  33. }
  34. }
  35. }
  36. }