EditorPathUtils.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System.IO;
  15. using UnityEditor;
  16. using UnityEngine;
  17. /*
  18. * EditorPathUtils class finds and processes the AssetPath for
  19. * EditorPathUtils.cs within unity asset database.
  20. */
  21. namespace GoogleMobileAds.Editor {
  22. public class EditorPathUtils : ScriptableObject {
  23. /*
  24. * Returns the asset path of EditorPathUtils.cs
  25. */
  26. private string GetFilePath() {
  27. return AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this));
  28. }
  29. /*
  30. * Returns the asset directory path of EditorPathUtils.cs
  31. */
  32. public string GetDirectoryAssetPath() {
  33. return Path.GetDirectoryName(GetFilePath());
  34. }
  35. /*
  36. * Returns the parent asset directory path of EditorPathUtils.cs
  37. */
  38. public string GetParentDirectoryAssetPath() {
  39. return Path.GetDirectoryName(GetDirectoryAssetPath());
  40. }
  41. /*
  42. * Returns true if GMA import is done via unity package manager,
  43. * false otherwise.
  44. */
  45. public bool IsPackageRootPath() {
  46. return GetFilePath().StartsWith("Packages");
  47. }
  48. }
  49. }