XRSDKConfigEditor.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using FfalconXR;
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace RayNeo.Editor
  6. {
  7. public class XRSDKConfigEditor : MonoBehaviour
  8. {
  9. //[MenuItem("Assets/Ffalcon/Config/Build SDKConfig")]
  10. public static void BuildSDKConfig()
  11. {
  12. BuildConfig<XRSDKConfig>("XRSDKConfig");
  13. }
  14. public static void BuildConfig<T>(string name) where T : ScriptableObject
  15. {
  16. T data = null;
  17. string folderPath = GetSelectedDirAssetsPath();
  18. string spriteDataPath = folderPath + string.Format("/{0}.asset", name);
  19. data = AssetDatabase.LoadAssetAtPath<T>(spriteDataPath);
  20. if (data == null)
  21. {
  22. data = ScriptableObject.CreateInstance<T>();
  23. AssetDatabase.CreateAsset(data, spriteDataPath);
  24. }
  25. Debug.Log("Create Config In Folder:" + spriteDataPath);
  26. EditorUtility.SetDirty(data);
  27. AssetDatabase.SaveAssets();
  28. }
  29. public static string GetSelectedDirAssetsPath()
  30. {
  31. string path = string.Empty;
  32. foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
  33. {
  34. path = AssetDatabase.GetAssetPath(obj);
  35. if (!string.IsNullOrEmpty(path) && File.Exists(path))
  36. {
  37. path = Path.GetDirectoryName(path);
  38. break;
  39. }
  40. }
  41. return path;
  42. }
  43. }
  44. }