EditorCommon.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. using UnityEngine.Assertions;
  3. using UnityEditor;
  4. using UnityEditorInternal;
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. namespace VoxelImporter
  12. {
  13. public abstract class EditorCommon : Editor
  14. {
  15. protected static void SaveInsideAssetsFolderDisplayDialog()
  16. {
  17. EditorUtility.DisplayDialog("Need to save in the Assets folder", "You need to save the file inside of the project's assets floder", "ok");
  18. }
  19. protected static string GetHelpStrings(List<string> helpList)
  20. {
  21. if (helpList.Count > 0)
  22. {
  23. string text = "";
  24. if (helpList.Count >= 3)
  25. {
  26. int i = 0;
  27. var enu = helpList.GetEnumerator();
  28. while (enu.MoveNext())
  29. {
  30. if (i == helpList.Count - 1)
  31. text += ", and ";
  32. else if (i != 0)
  33. text += ", ";
  34. text += enu.Current;
  35. i++;
  36. }
  37. }
  38. else if (helpList.Count == 2)
  39. {
  40. var enu = helpList.GetEnumerator();
  41. enu.MoveNext();
  42. text += enu.Current;
  43. text += " and ";
  44. enu.MoveNext();
  45. text += enu.Current;
  46. }
  47. else if (helpList.Count == 1)
  48. {
  49. var enu = helpList.GetEnumerator();
  50. enu.MoveNext();
  51. text += enu.Current;
  52. }
  53. return string.Format("If it is not Prefab you need to save the file.\nPlease create a Prefab for this GameObject.\nIf you do not want to Prefab, please save {0}.", text);
  54. }
  55. return null;
  56. }
  57. public static bool IsMainAsset(UnityEngine.Object obj)
  58. {
  59. return (obj != null && AssetDatabase.Contains(obj) && AssetDatabase.IsMainAsset(obj));
  60. }
  61. public static bool IsSubAsset(UnityEngine.Object obj)
  62. {
  63. return (obj != null && AssetDatabase.Contains(obj) && AssetDatabase.IsSubAsset(obj));
  64. }
  65. public static Texture2D EditorGUIUtilityLoadIcon(string name)
  66. {
  67. var mi = typeof(EditorGUIUtility).GetMethod("LoadIcon", BindingFlags.NonPublic | BindingFlags.Static);
  68. return (Texture2D)mi.Invoke(null, new object[] { name });
  69. }
  70. }
  71. }