PDFAssetEditor.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Paroxe.PdfRenderer.Internal
  5. {
  6. [CustomEditor(typeof(PDFAsset), true)]
  7. public class PDFAssetEditor : Editor
  8. {
  9. GUIStyle m_Background1;
  10. GUIStyle m_Background2;
  11. GUIStyle m_Background3;
  12. Texture2D m_Logo;
  13. PDFAsset pdfAsset = null;
  14. public override void OnInspectorGUI()
  15. {
  16. Undo.RecordObject(pdfAsset, "PDFAsset");
  17. if (m_Logo != null)
  18. {
  19. Rect rect = GUILayoutUtility.GetRect(m_Logo.width, m_Logo.height);
  20. GUI.DrawTexture(rect, m_Logo, ScaleMode.ScaleToFit);
  21. }
  22. GUILayout.BeginVertical("Box");
  23. GUILayout.Label("Password Options", EditorStyles.boldLabel);
  24. EditorGUI.indentLevel++;
  25. pdfAsset.Password = EditorGUILayout.PasswordField("Password", pdfAsset.Password);
  26. EditorGUI.indentLevel--;
  27. GUILayout.Space(10.0f);
  28. GUILayout.EndVertical();
  29. if (GUI.changed)
  30. {
  31. EditorUtility.SetDirty(target);
  32. }
  33. }
  34. protected virtual void OnDisable()
  35. {
  36. DestroyImmediate(m_Background1.normal.background);
  37. DestroyImmediate(m_Background2.normal.background);
  38. DestroyImmediate(m_Background3.normal.background);
  39. }
  40. protected virtual void OnEnable()
  41. {
  42. pdfAsset = (PDFAsset)target;
  43. m_Background1 = new GUIStyle();
  44. m_Background1.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f));
  45. m_Background2 = new GUIStyle();
  46. m_Background2.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.0f));
  47. m_Background3 = new GUIStyle();
  48. m_Background3.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.05f));
  49. MonoScript script = MonoScript.FromScriptableObject(this);
  50. string path = AssetDatabase.GetAssetPath(script);
  51. string logoPath = Path.GetDirectoryName(path) + "/Icons/logo_pa.png";
  52. m_Logo = (Texture2D)AssetDatabase.LoadAssetAtPath(logoPath, typeof(Texture2D));
  53. }
  54. private Texture2D MakeTex(int width, int height, Color col)
  55. {
  56. Color[] pix = new Color[width * height];
  57. for (int i = 0; i < pix.Length; i++)
  58. {
  59. pix[i] = col;
  60. }
  61. Texture2D result = new Texture2D(width, height);
  62. result.hideFlags = HideFlags.HideAndDontSave;
  63. result.SetPixels(pix);
  64. result.Apply();
  65. return result;
  66. }
  67. }
  68. }