2
0

SteamVR_Editor.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Custom inspector display for SteamVR_Camera
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using UnityEditor;
  8. using System.IO;
  9. using Valve.VR;
  10. [CustomEditor(typeof(SteamVR_Camera)), CanEditMultipleObjects]
  11. public class SteamVR_Editor : Editor
  12. {
  13. int bannerHeight = 150;
  14. Texture logo;
  15. SerializedProperty script, wireframe;
  16. string GetResourcePath()
  17. {
  18. var ms = MonoScript.FromScriptableObject(this);
  19. var path = AssetDatabase.GetAssetPath(ms);
  20. path = Path.GetDirectoryName(path);
  21. return path.Substring(0, path.Length - "Editor".Length) + "Textures/";
  22. }
  23. void OnEnable()
  24. {
  25. var resourcePath = GetResourcePath();
  26. logo = AssetDatabase.LoadAssetAtPath<Texture2D>(resourcePath + "logo.png");
  27. script = serializedObject.FindProperty("m_Script");
  28. wireframe = serializedObject.FindProperty("wireframe");
  29. foreach (SteamVR_Camera target in targets)
  30. target.ForceLast();
  31. }
  32. public override void OnInspectorGUI()
  33. {
  34. serializedObject.Update();
  35. var rect = GUILayoutUtility.GetRect(Screen.width - 38, bannerHeight, GUI.skin.box);
  36. if (logo)
  37. GUI.DrawTexture(rect, logo, ScaleMode.ScaleToFit);
  38. if (!Application.isPlaying)
  39. {
  40. var expand = false;
  41. var collapse = false;
  42. foreach (SteamVR_Camera target in targets)
  43. {
  44. if (AssetDatabase.Contains(target))
  45. continue;
  46. if (target.isExpanded)
  47. collapse = true;
  48. else
  49. expand = true;
  50. }
  51. if (expand)
  52. {
  53. GUILayout.BeginHorizontal();
  54. if (GUILayout.Button("Expand"))
  55. {
  56. foreach (SteamVR_Camera target in targets)
  57. {
  58. if (AssetDatabase.Contains(target))
  59. continue;
  60. if (!target.isExpanded)
  61. {
  62. target.Expand();
  63. EditorUtility.SetDirty(target);
  64. }
  65. }
  66. }
  67. GUILayout.Space(18);
  68. GUILayout.EndHorizontal();
  69. }
  70. if (collapse)
  71. {
  72. GUILayout.BeginHorizontal();
  73. if (GUILayout.Button("Collapse"))
  74. {
  75. foreach (SteamVR_Camera target in targets)
  76. {
  77. if (AssetDatabase.Contains(target))
  78. continue;
  79. if (target.isExpanded)
  80. {
  81. target.Collapse();
  82. EditorUtility.SetDirty(target);
  83. }
  84. }
  85. }
  86. GUILayout.Space(18);
  87. GUILayout.EndHorizontal();
  88. }
  89. }
  90. EditorGUILayout.PropertyField(script);
  91. EditorGUILayout.PropertyField(wireframe);
  92. serializedObject.ApplyModifiedProperties();
  93. }
  94. public static void ExportPackage()
  95. {
  96. AssetDatabase.ExportPackage(new string[] {
  97. "Assets/SteamVR",
  98. "Assets/Plugins/openvr_api.cs",
  99. "Assets/Plugins/openvr_api.bundle",
  100. "Assets/Plugins/x86/openvr_api.dll",
  101. "Assets/Plugins/x86/steam_api.dll",
  102. "Assets/Plugins/x86/libsteam_api.so",
  103. "Assets/Plugins/x86_64/openvr_api.dll",
  104. "Assets/Plugins/x86_64/steam_api.dll",
  105. "Assets/Plugins/x86_64/libsteam_api.so",
  106. "Assets/Plugins/x86_64/libopenvr_api.so",
  107. }, "steamvr.unitypackage", ExportPackageOptions.Recurse);
  108. EditorApplication.Exit(0);
  109. }
  110. }