AllIn1ShaderWindow.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.IO;
  5. public class AllIn1ShaderWindow : EditorWindow
  6. {
  7. [MenuItem("Window/AllIn1ShaderWindow")]
  8. public static void ShowAllIn1ShaderWindowWindow()
  9. {
  10. GetWindow<AllIn1ShaderWindow>("All In 1 Shader Window");
  11. }
  12. private DefaultAsset materialTargetFolder = null;
  13. private void OnGUI()
  14. {
  15. GUILayout.Label("Through this window you'll be able to set the folder where the asset will save it's Materials",
  16. EditorStyles.boldLabel);
  17. GUILayout.Space(20);
  18. materialTargetFolder = (DefaultAsset)EditorGUILayout.ObjectField(
  19. "New Material Folder",
  20. materialTargetFolder,
  21. typeof(DefaultAsset),
  22. false);
  23. if (materialTargetFolder != null && IsAssetAFolder(materialTargetFolder))
  24. {
  25. string path = AssetDatabase.GetAssetPath(materialTargetFolder);
  26. PlayerPrefs.SetString("All1ShaderMaterials", path);
  27. EditorGUILayout.HelpBox(
  28. "Valid folder! Material save path: " + path,
  29. MessageType.Info,
  30. true);
  31. }
  32. else
  33. {
  34. EditorGUILayout.HelpBox(
  35. "Select the new Material Folder",
  36. MessageType.Warning,
  37. true);
  38. }
  39. }
  40. private static bool IsAssetAFolder(Object obj)
  41. {
  42. string path = "";
  43. if (obj == null) return false;
  44. path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
  45. if (path.Length > 0)
  46. {
  47. if (Directory.Exists(path)) return true;
  48. else return false;
  49. }
  50. return false;
  51. }
  52. }
  53. #endif