PostProcessBuild_ARCam.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_ARCam : MonoBehaviour
  11. {
  12. [PostProcessBuild]
  13. public static void OnPostProcessBuild(BuildTarget target, string buildPath)
  14. {
  15. string[] htmlLines = File.ReadAllLines(buildPath + "/index.html");
  16. var facingMode = ARCameraGlobalSettings.Instance.facingMode;
  17. if(facingMode == ARCameraGlobalSettings.FacingMode.DONT_OVERRIDE)
  18. return;
  19. if(facingMode == ARCameraGlobalSettings.FacingMode.BACK){
  20. htmlLines = ReplaceFacingMode(htmlLines, "environment");
  21. }
  22. else if(facingMode == ARCameraGlobalSettings.FacingMode.FRONT){
  23. htmlLines = ReplaceFacingMode(htmlLines, "user");
  24. }
  25. // else if(facingMode == ARCameraGlobalSettings.FacingMode.BACK_AND_FRONT){
  26. // htmlLines = ReplaceFacingMode(htmlLines, "");
  27. // }
  28. File.WriteAllLines(buildPath + "/index.html", htmlLines);
  29. }
  30. static string[] ReplaceFacingMode(string[] lines, string facingMode){
  31. for(var i = 0; i < lines.Length; i++){
  32. if(lines[i].Contains("window.unityFacingMode = ")){
  33. lines[i] = "\t\twindow.unityFacingMode = \"" + facingMode + "\"";
  34. Debug.Log("Facing Mode: " + lines[i]);
  35. };
  36. }
  37. return lines;
  38. }
  39. }
  40. }