NxrVuforiaSwitchEditor.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. namespace Nxr.Internal
  5. {
  6. // <category android:name="com.nibiru.intent.category.NAR_VUFORIA" />
  7. // 和vuforia混用时加入这个标签
  8. // <category android:name="com.nibiru.intent.category.NAR_VUFORIA_SPLASH" />
  9. // 启动画面系统控制
  10. public class NxrVuforiaSwitchEditor : MonoBehaviour
  11. {
  12. #region Public Attributes
  13. const string path = "NibiruXR/Vuforia Mode (Experimental)";
  14. #endregion
  15. // [MenuItem(path, false, 90)]
  16. public static void MenuCheckVuforiaMode()
  17. {
  18. bool flag = Menu.GetChecked(path);
  19. flag = !flag;
  20. Menu.SetChecked(path, flag);
  21. string data = NxrPluginEditor.Read("AndroidManifest.xml");
  22. string[] lines = data.Split('\n');
  23. string newdata = "";
  24. for (int i = 0, l = lines.Length; i < l; i++)
  25. {
  26. string lineContent = lines[i];
  27. if (flag && lineContent.Contains("category.NVR"))
  28. {
  29. lineContent = lineContent + "\n " + "<category android:name=\"com.nibiru.intent.category.NAR_VUFORIA\" />";
  30. lineContent = lineContent + "\n " + "<category android:name=\"com.nibiru.intent.category.NAR_VUFORIA_SPLASH\" />";
  31. } else if(!flag && lineContent.Contains("NAR_VUFORIA"))
  32. {
  33. lineContent = "";
  34. }
  35. if(flag && lineContent.Contains("NIBIRU_PLUGIN_IDS"))
  36. {
  37. lineContent = " <meta-data android:value=\"\" android:name=\"NIBIRU_PLUGIN_IDS\"/>";
  38. }
  39. newdata = newdata + lineContent + "\n";
  40. }
  41. NxrPluginEditor.Write("AndroidManifest.xml", newdata);
  42. }
  43. [MenuItem(path, true)]
  44. public static bool MenuCheckBefore()
  45. {
  46. string data = NxrPluginEditor.Read("AndroidManifest.xml");
  47. string[] lines = data.Split('\n');
  48. bool isChecked = false;
  49. for (int i = 0, l = lines.Length; i < l; i++)
  50. {
  51. string lineContent = lines[i];
  52. if (lineContent.Contains("NAR_VUFORIA"))
  53. {
  54. isChecked = true;
  55. break;
  56. }
  57. }
  58. Menu.SetChecked(path, isChecked);
  59. return true;
  60. }
  61. }
  62. }