UXRSDKConfigEditor.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using Rokid.UXR.Config;
  5. namespace Rokid.UXR.Editor
  6. {
  7. public class UXRSDKConfigEditor : MonoBehaviour
  8. {
  9. //[MenuItem("Assets/UXR/Config/Build SDKConfig")]
  10. public static void BuildSDKConfig()
  11. {
  12. BuildConfig<UXRSDKConfig>("UXRSDKConfig");
  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. RKLog.Info("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. }