AllIn1ShaderScriptEditor.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CustomEditor(typeof(AllIn1Shader)), CanEditMultipleObjects]
  4. public class AllIn1ShaderScriptEditor : Editor
  5. {
  6. public override void OnInspectorGUI()
  7. {
  8. Texture2D imageInspector = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/AllIn1SpriteShader/Textures/CustomEditorImage.png", typeof(Texture2D));
  9. if (imageInspector)
  10. {
  11. Rect rect;
  12. float imageHeight = imageInspector.height;
  13. float imageWidth = imageInspector.width;
  14. float aspectRatio = imageHeight / imageWidth;
  15. rect = GUILayoutUtility.GetRect(imageHeight, aspectRatio * Screen.width);
  16. EditorGUI.DrawTextureTransparent(rect, imageInspector);
  17. }
  18. AllIn1Shader myScript = (AllIn1Shader)target;
  19. if (GUILayout.Button("Deactivate All Effects"))
  20. {
  21. for (int i = 0; i < targets.Length; i++)
  22. {
  23. (targets[i] as AllIn1Shader).ClearAllKeywords();
  24. }
  25. }
  26. if (GUILayout.Button("New Clean Material"))
  27. {
  28. for (int i = 0; i < targets.Length; i++)
  29. {
  30. (targets[i] as AllIn1Shader).TryCreateNew();
  31. }
  32. }
  33. if (GUILayout.Button("Create New Material With Same Properties (SEE DOC)"))
  34. {
  35. for (int i = 0; i < targets.Length; i++)
  36. {
  37. (targets[i] as AllIn1Shader).MakeCopy();
  38. }
  39. }
  40. if (GUILayout.Button("Save Material To Folder (SEE DOC)"))
  41. {
  42. for (int i = 0; i < targets.Length; i++)
  43. {
  44. (targets[i] as AllIn1Shader).SaveMaterial();
  45. }
  46. }
  47. EditorGUILayout.Space();
  48. if (GUILayout.Button("Sprite Atlas Auto Setup"))
  49. {
  50. for (int i = 0; i < targets.Length; i++)
  51. {
  52. (targets[i] as AllIn1Shader).ToggleSetAtlasUvs(true);
  53. }
  54. }
  55. if (GUILayout.Button("Remove Sprite Atlas Configuration"))
  56. {
  57. for (int i = 0; i < targets.Length; i++)
  58. {
  59. (targets[i] as AllIn1Shader).ToggleSetAtlasUvs(false);
  60. }
  61. }
  62. EditorGUILayout.Space();
  63. if (GUILayout.Button("REMOVE COMPONENT AND MATERIAL"))
  64. {
  65. for (int i = 0; i < targets.Length; i++)
  66. {
  67. (targets[i] as AllIn1Shader).CleanMaterial();
  68. }
  69. for (int i = targets.Length - 1; i >= 0; i--)
  70. {
  71. DestroyImmediate(targets[i] as AllIn1Shader);
  72. }
  73. }
  74. }
  75. }