PDFAssetEditor.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. http://www.cgsoso.com/forum-211-1.html
  3. CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
  4. CGSOSO 主打游戏开发,影视设计等CG资源素材。
  5. 插件如若商用,请务必官网购买!
  6. daily assets update for try.
  7. U should buy the asset from home store if u use it in your project!
  8. */
  9. using System.IO;
  10. using UnityEditor;
  11. using UnityEngine;
  12. namespace Paroxe.PdfRenderer.Internal
  13. {
  14. [CustomEditor(typeof (PDFAsset), true)]
  15. public class PDFAssetEditor : Editor
  16. {
  17. GUIStyle m_Background1;
  18. GUIStyle m_Background2;
  19. GUIStyle m_Background3;
  20. Texture2D m_Logo;
  21. PDFAsset pdfAsset = null;
  22. public override void OnInspectorGUI()
  23. {
  24. Undo.RecordObject(pdfAsset, "PDFAsset");
  25. if (m_Logo != null)
  26. {
  27. Rect rect = GUILayoutUtility.GetRect(m_Logo.width, m_Logo.height);
  28. GUI.DrawTexture(rect, m_Logo, ScaleMode.ScaleToFit);
  29. }
  30. GUILayout.BeginVertical("Box");
  31. GUILayout.Label("Password Options", EditorStyles.boldLabel);
  32. EditorGUI.indentLevel++;
  33. pdfAsset.Password = EditorGUILayout.PasswordField("Password", pdfAsset.Password);
  34. EditorGUI.indentLevel--;
  35. GUILayout.Space(10.0f);
  36. GUILayout.EndVertical();
  37. if (GUI.changed)
  38. {
  39. EditorUtility.SetDirty(target);
  40. }
  41. }
  42. protected virtual void OnDisable()
  43. {
  44. DestroyImmediate(m_Background1.normal.background);
  45. DestroyImmediate(m_Background2.normal.background);
  46. DestroyImmediate(m_Background3.normal.background);
  47. }
  48. protected virtual void OnEnable()
  49. {
  50. pdfAsset = (PDFAsset) target;
  51. m_Background1 = new GUIStyle();
  52. m_Background1.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f));
  53. m_Background2 = new GUIStyle();
  54. m_Background2.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.0f));
  55. m_Background3 = new GUIStyle();
  56. m_Background3.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.05f));
  57. MonoScript script = MonoScript.FromScriptableObject(this);
  58. string path = AssetDatabase.GetAssetPath(script);
  59. string logoPath = Path.GetDirectoryName(path) + "/logo_pa.png";
  60. m_Logo = (Texture2D) AssetDatabase.LoadAssetAtPath(logoPath, typeof (Texture2D));
  61. }
  62. private Texture2D MakeTex(int width, int height, Color col)
  63. {
  64. Color[] pix = new Color[width*height];
  65. for (int i = 0; i < pix.Length; i++)
  66. {
  67. pix[i] = col;
  68. }
  69. Texture2D result = new Texture2D(width, height);
  70. result.hideFlags = HideFlags.HideAndDontSave;
  71. result.SetPixels(pix);
  72. result.Apply();
  73. return result;
  74. }
  75. }
  76. }