Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEngine.UIElements;
  6. using UnityEditor.UIElements;
  7.  
  8. [CustomEditor(typeof(imguiOver))]
  9. public class imguiTest : Editor
  10. {
  11. Texture2D texture, none;
  12. int index;
  13. public override void OnInspectorGUI()
  14. {
  15. texture = AssetDatabase.LoadAssetAtPath<Texture2D>($"Assets/Models/Resources/icon{index}.png");
  16. none = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Models/Resources/none.png");
  17.  
  18. index = EditorGUILayout.IntField(index);
  19. if (texture != null)
  20. {
  21. GUILayout.Box(texture);
  22. GUILayout.Label($"IMGUI Testing, texture {texture.name} is load");
  23. }
  24. else
  25. {
  26. GUILayout.Box(none);
  27. GUILayout.Label("Nothing is loaded");
  28. }
  29.  
  30. }
  31. }
  32.  
  33. [CustomEditor(typeof(monoOverride))]
  34. public class img_testing : Editor
  35. {
  36. Texture2D texture, none;
  37. int index;
  38.  
  39. public override VisualElement CreateInspectorGUI()
  40. {
  41. texture = AssetDatabase.LoadAssetAtPath<Texture2D>($"Assets/Models/Resources/icon{index}.png");
  42. none = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Models/Resources/none.png");
  43. var root = new VisualElement();
  44. var lbl = new Label();
  45. var img = new Image ();
  46. img.scaleMode = ScaleMode.ScaleToFit;
  47. if (texture != null)
  48. {
  49. lbl.text = $"texture {texture.name} is load";
  50. img.image = texture;
  51. }
  52. else
  53. {
  54. lbl.text = "Nothing is loaded";
  55. img.image = none;
  56. }
  57. root.Add(img);
  58. root.Add(lbl);
  59. var intField = new IntegerField();
  60. index = intField.value;
  61. root.Add(intField);
  62. return root;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement