PDFViewerEditor.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using UnityEditor;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace Paroxe.PdfRenderer.Internal.Viewer
  10. {
  11. [CustomEditor(typeof(PDFViewer), true)]
  12. public class PDFViewerEditor : Editor
  13. {
  14. private Texture2D m_Logo;
  15. private SerializedProperty m_FileSource = null;
  16. private SerializedProperty m_Folder = null;
  17. private SerializedProperty m_FileName = null;
  18. private SerializedProperty m_FileURL = null;
  19. private SerializedProperty m_FilePath = null;
  20. private SerializedProperty m_BytesSupplierObject = null;
  21. private SerializedProperty m_BytesSupplierComponent = null;
  22. private SerializedProperty m_BytesSupplierFunctionName = null;
  23. private SerializedProperty m_PDFAsset = null;
  24. private SerializedProperty m_LoadOnEnable = null;
  25. private SerializedProperty m_UnloadOnDisable = null;
  26. private SerializedProperty m_Password = null;
  27. private SerializedProperty m_ZoomFactor = null;
  28. private SerializedProperty m_ZoomStep = null;
  29. private SerializedProperty m_PageFitting = null;
  30. private SerializedProperty m_VerticalMarginBetweenPages = null;
  31. private SerializedProperty m_MinZoomFactor = null;
  32. private SerializedProperty m_MaxZoomFactor = null;
  33. private SerializedProperty m_ScrollSensitivity = null;
  34. private SerializedProperty m_ShowTopBar = null;
  35. private SerializedProperty m_ShowVerticalScrollBar = null;
  36. private SerializedProperty m_ShowBookmarksViewer = null;
  37. private SerializedProperty m_ShowHorizontalScrollBar = null;
  38. private SerializedProperty m_ShowThumbnailsViewer = null;
  39. private SerializedProperty m_ChangeCursorWhenOverURL = null;
  40. private SerializedProperty m_AllowOpenURL = null;
  41. private SerializedProperty m_SearchResultColor = null;
  42. private SerializedProperty m_SearchResultPadding = null;
  43. private SerializedProperty m_SearchTimeBudgetPerFrame = null;
  44. private SerializedProperty m_ParagraphZoomFactor = null;
  45. private SerializedProperty m_ParagraphZoomingEnable = null;
  46. private SerializedProperty m_ParagraphDetectionThreshold = null;
  47. private SerializedProperty m_PageTileTexture = null;
  48. private SerializedProperty m_PageColor = null;
  49. private SerializedProperty m_MaxZoomFactorTextureQuality = null;
  50. private SerializedProperty m_RenderSettings = null;
  51. private SerializedProperty m_RenderAnnotations = null;
  52. private SerializedProperty m_RenderGrayscale = null;
  53. protected virtual void OnEnable()
  54. {
  55. MonoScript script = MonoScript.FromScriptableObject(this);
  56. string scriptPath = AssetDatabase.GetAssetPath(script);
  57. m_Logo = (Texture2D) AssetDatabase.LoadAssetAtPath(Path.GetDirectoryName(scriptPath) + "/Icons/logo_pv.png", typeof(Texture2D));
  58. GetType().GetMembers(BindingFlags.NonPublic | BindingFlags.Instance)
  59. .Where(x => x.MemberType == MemberTypes.Field && ((FieldInfo)x).FieldType == typeof(SerializedProperty))
  60. .Cast<FieldInfo>()
  61. .ToList().ForEach(prop =>
  62. {
  63. SerializedProperty serializedProperty = serializedObject.FindProperty(prop.Name);
  64. if (serializedProperty != null)
  65. prop.SetValue(this, serializedProperty);
  66. });
  67. m_RenderAnnotations = m_RenderSettings.FindPropertyRelative("renderAnnotations");
  68. m_RenderGrayscale = m_RenderSettings.FindPropertyRelative("grayscale");
  69. }
  70. public override void OnInspectorGUI()
  71. {
  72. Undo.RecordObject(target, "PDFViewer");
  73. serializedObject.Update();
  74. if (m_Logo != null)
  75. {
  76. Rect rect = GUILayoutUtility.GetRect(m_Logo.width, m_Logo.height);
  77. GUI.DrawTexture(rect, m_Logo, ScaleMode.ScaleToFit);
  78. }
  79. InspectLoadSettings();
  80. InspectSecuritySettings();
  81. InspectViewerSettings();
  82. InspectSearchSettings();
  83. InspectOtherSettings();
  84. InspectRenderingSettings();
  85. serializedObject.ApplyModifiedProperties();
  86. }
  87. private void InspectLoadSettings()
  88. {
  89. PDFViewer viewer = (PDFViewer)target;
  90. GUILayout.BeginVertical("Box");
  91. if (EnterGroup("Load Settings", "Paroxe.PdfRenderer.PDFViewer.ShowLoadSettings"))
  92. {
  93. EditorGUILayout.PropertyField(m_FileSource);
  94. PDFViewer.FileSourceType fileSourceType = (PDFViewer.FileSourceType)m_FileSource.enumValueIndex;
  95. if (fileSourceType == PDFViewer.FileSourceType.Resources
  96. || fileSourceType == PDFViewer.FileSourceType.StreamingAssets
  97. || fileSourceType == PDFViewer.FileSourceType.PersistentData)
  98. {
  99. EditorGUI.indentLevel++;
  100. EditorGUILayout.PropertyField(m_Folder);
  101. EditorGUILayout.PropertyField(m_FileName);
  102. if (fileSourceType == PDFViewer.FileSourceType.Resources)
  103. {
  104. if (File.Exists(Application.dataPath + "/Resources/" + viewer.GetFileLocation())
  105. && !File.Exists(Application.dataPath + "/Resources/" + viewer.GetFileLocation().Replace(".bytes", "") + ".bytes"))
  106. {
  107. EditorGUILayout.HelpBox(
  108. "PDF file in resources folder need to have .bytes extension to allow PDFViewer to access it correctly. \n\r For example => pdf_sample.pdf.bytes",
  109. MessageType.Warning);
  110. }
  111. }
  112. EditorGUI.indentLevel--;
  113. }
  114. else if (fileSourceType == PDFViewer.FileSourceType.Web)
  115. {
  116. EditorGUI.indentLevel++;
  117. EditorGUILayout.PropertyField(m_FileURL, new GUIContent("Url"));
  118. EditorGUI.indentLevel--;
  119. }
  120. else if (fileSourceType == PDFViewer.FileSourceType.FilePath)
  121. {
  122. EditorGUI.indentLevel++;
  123. EditorGUILayout.PropertyField(m_FilePath);
  124. EditorGUI.indentLevel--;
  125. }
  126. if (fileSourceType != PDFViewer.FileSourceType.Bytes && fileSourceType != PDFViewer.FileSourceType.None)
  127. {
  128. #if UNITY_IOS
  129. if (fileSourceType == PDFViewer.FileSourceType.Web)
  130. {
  131. EditorGUILayout.BeginHorizontal();
  132. EditorGUILayout.PrefixLabel(" ");
  133. EditorGUILayout.HelpBox(
  134. "You may need to add NSAppTransportSecurity entry in info.plist of the XCode project to allow PDFViewer to download pdf from web:\n\r\n\r" +
  135. "<key>NSAppTransportSecurity</key>\n\r" +
  136. " <dict>\n\r" +
  137. " <key>NSAllowsArbitraryLoads</key>\n\r" +
  138. " <true/>\n\r" +
  139. "</dict>", MessageType.Info);
  140. EditorGUILayout.EndHorizontal();
  141. }
  142. #endif
  143. if (fileSourceType == PDFViewer.FileSourceType.StreamingAssets
  144. || fileSourceType == PDFViewer.FileSourceType.PersistentData
  145. || fileSourceType == PDFViewer.FileSourceType.Resources
  146. || fileSourceType == PDFViewer.FileSourceType.FilePath)
  147. {
  148. EditorGUILayout.BeginHorizontal();
  149. EditorGUILayout.PrefixLabel(" ");
  150. if (GUILayout.Button("Browse"))
  151. {
  152. string baseDirectory = "";
  153. if (fileSourceType == PDFViewer.FileSourceType.PersistentData)
  154. baseDirectory = Application.persistentDataPath;
  155. else if (fileSourceType == PDFViewer.FileSourceType.StreamingAssets)
  156. baseDirectory = Application.streamingAssetsPath;
  157. else if (fileSourceType == PDFViewer.FileSourceType.Resources)
  158. baseDirectory = "Assets/Resources";
  159. else if (fileSourceType == PDFViewer.FileSourceType.FilePath)
  160. {
  161. string projectRoot = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, ".."));
  162. projectRoot = projectRoot.Replace('\\', '/');
  163. baseDirectory = projectRoot;
  164. }
  165. if (!Directory.Exists(baseDirectory))
  166. {
  167. Directory.CreateDirectory(baseDirectory);
  168. AssetDatabase.Refresh();
  169. }
  170. string folder = "";
  171. string fileName = "";
  172. string filePath = "";
  173. bool usePersistentData = false;
  174. bool useStreamingAssets = false;
  175. bool useResources = false;
  176. bool useFilePath = false;
  177. if (Browse(baseDirectory, ref fileName, ref folder, ref filePath, ref useStreamingAssets, ref usePersistentData, ref useResources, ref useFilePath))
  178. {
  179. if (useStreamingAssets)
  180. fileSourceType = PDFViewer.FileSourceType.StreamingAssets;
  181. else if (usePersistentData)
  182. fileSourceType = PDFViewer.FileSourceType.PersistentData;
  183. else if (useResources)
  184. fileSourceType = PDFViewer.FileSourceType.Resources;
  185. else if (useFilePath)
  186. fileSourceType = PDFViewer.FileSourceType.FilePath;
  187. if (fileSourceType != PDFViewer.FileSourceType.FilePath)
  188. {
  189. m_Folder.stringValue = folder;
  190. m_FileName.stringValue = fileName;
  191. }
  192. else
  193. {
  194. m_FilePath.stringValue = filePath;
  195. }
  196. }
  197. }
  198. EditorGUILayout.EndHorizontal();
  199. }
  200. #if UNITY_EDITOR_WIN
  201. if (fileSourceType != PDFViewer.FileSourceType.Asset && fileSourceType != PDFViewer.FileSourceType.DocumentObject)
  202. {
  203. EditorGUILayout.BeginHorizontal();
  204. EditorGUILayout.PrefixLabel(" ");
  205. using (new EditorGUI.DisabledGroupScope(string.IsNullOrEmpty(m_FileName.stringValue.Trim())))
  206. {
  207. if (GUILayout.Button("Reveal File"))
  208. {
  209. string filePath = "";
  210. if (fileSourceType == PDFViewer.FileSourceType.Resources)
  211. {
  212. filePath = Application.dataPath + "/Resources/" + viewer.GetFileLocation();
  213. }
  214. else
  215. {
  216. filePath = viewer.GetFileLocation();
  217. }
  218. if (fileSourceType != PDFViewer.FileSourceType.Web)
  219. {
  220. if (!File.Exists(filePath))
  221. {
  222. if (fileSourceType == PDFViewer.FileSourceType.Resources &&
  223. File.Exists(filePath + ".bytes"))
  224. {
  225. ShowInExplorer(filePath + ".bytes");
  226. }
  227. else
  228. {
  229. EditorUtility.DisplayDialog("Error",
  230. "The file path is badly formed, contains invalid characters or doesn't exists:\r\n\r\n" +
  231. filePath, "Ok");
  232. }
  233. }
  234. else
  235. {
  236. ShowInExplorer(filePath);
  237. }
  238. }
  239. else
  240. {
  241. try
  242. {
  243. System.Diagnostics.Process.Start(filePath);
  244. }
  245. catch
  246. {
  247. EditorUtility.DisplayDialog("Error",
  248. "The URL is badly formed or contains invalid characters:\r\n\r\n" + filePath, "Ok");
  249. }
  250. }
  251. }
  252. }
  253. EditorGUILayout.EndHorizontal();
  254. }
  255. #endif
  256. }
  257. if (fileSourceType == PDFViewer.FileSourceType.Bytes)
  258. {
  259. EditorGUI.indentLevel++;
  260. GameObject oldObject = (GameObject)m_BytesSupplierObject.objectReferenceValue;
  261. EditorGUILayout.PropertyField(m_BytesSupplierObject, new GUIContent("Supplier Object"));
  262. int selectedIndex = 0;
  263. if (m_BytesSupplierObject.objectReferenceValue != null)
  264. {
  265. try
  266. {
  267. List<BytesSupplierInfo> possibleSuppliers = new List<BytesSupplierInfo>();
  268. possibleSuppliers.Add(new BytesSupplierInfo(null, null, ""));
  269. Component[] components = ((GameObject)m_BytesSupplierObject.objectReferenceValue).GetComponents(typeof(Component));
  270. foreach (Component component in components)
  271. {
  272. Type type = component.GetType();
  273. MethodInfo[] methods = type.GetMethods();
  274. if (methods.Length == 0)
  275. continue;
  276. foreach (MethodInfo method in methods)
  277. {
  278. if ((method.GetParameters() == null || method.GetParameters().Length == 0)
  279. && method.ReturnType == typeof(byte[]))
  280. {
  281. possibleSuppliers.Add(new BytesSupplierInfo(m_BytesSupplierObject.objectReferenceValue as GameObject, component,
  282. method.Name));
  283. if (oldObject == m_BytesSupplierObject.objectReferenceValue
  284. && method.Name == m_BytesSupplierFunctionName.stringValue
  285. && component == m_BytesSupplierComponent.objectReferenceValue)
  286. {
  287. selectedIndex = possibleSuppliers.Count - 1;
  288. }
  289. }
  290. }
  291. }
  292. string[] supplierTitles = new string[possibleSuppliers.Count];
  293. for (int i = 0; i < supplierTitles.Length; ++i)
  294. {
  295. if (i == 0)
  296. {
  297. supplierTitles[0] = "No Function";
  298. continue;
  299. }
  300. supplierTitles[i] = possibleSuppliers[i].m_Behaviour.name + "." +
  301. possibleSuppliers[i].m_MethodName;
  302. }
  303. EditorGUILayout.BeginHorizontal();
  304. EditorGUILayout.PrefixLabel("Supplier Function");
  305. var choiceIndex = EditorGUILayout.Popup(selectedIndex, supplierTitles);
  306. if (choiceIndex == 0)
  307. {
  308. m_BytesSupplierComponent.objectReferenceValue = null;
  309. m_BytesSupplierFunctionName.stringValue = "";
  310. }
  311. else
  312. {
  313. m_BytesSupplierComponent.objectReferenceValue = possibleSuppliers[choiceIndex].m_Behaviour;
  314. m_BytesSupplierFunctionName.stringValue = possibleSuppliers[choiceIndex].m_MethodName;
  315. }
  316. EditorGUILayout.EndHorizontal();
  317. }
  318. catch (Exception)
  319. {
  320. m_BytesSupplierComponent.objectReferenceValue = null;
  321. m_BytesSupplierFunctionName.stringValue = "";
  322. }
  323. }
  324. EditorGUI.indentLevel--;
  325. }
  326. if (fileSourceType == PDFViewer.FileSourceType.Asset)
  327. {
  328. EditorGUILayout.PropertyField(m_PDFAsset);
  329. }
  330. EditorGUILayout.PropertyField(m_LoadOnEnable);
  331. EditorGUILayout.PropertyField(m_UnloadOnDisable);
  332. if (fileSourceType == PDFViewer.FileSourceType.Asset)
  333. {
  334. EditorGUILayout.BeginHorizontal();
  335. EditorGUILayout.PrefixLabel("");
  336. EditorGUILayout.HelpBox("To convert pdf file to .asset right click on pdf and select \"PDF Renderer\\Convert to .asset\"", MessageType.Info);
  337. EditorGUILayout.EndHorizontal();
  338. }
  339. GUILayout.Space(4.0f);
  340. }
  341. GUILayout.EndVertical();
  342. }
  343. private void InspectSecuritySettings()
  344. {
  345. GUILayout.BeginVertical("Box");
  346. if (EnterGroup("Security Settings", "Paroxe.PdfRenderer.PDFViewer.ShowPasswordSettings"))
  347. {
  348. EditorGUILayout.PropertyField(m_Password);
  349. GUILayout.Space(4.0f);
  350. }
  351. GUILayout.EndVertical();
  352. }
  353. private void InspectViewerSettings()
  354. {
  355. PDFViewer viewer = (PDFViewer)target;
  356. GUILayout.BeginVertical("Box");
  357. if (EnterGroup("Viewer Settings", "Paroxe.PdfRenderer.PDFViewer.ShowViewerSettings"))
  358. {
  359. EditorGUILayout.PropertyField(m_PageFitting);
  360. PDFViewer.PageFittingType pageFitting = (PDFViewer.PageFittingType)m_PageFitting.enumValueIndex;
  361. if (pageFitting == PDFViewer.PageFittingType.Zoom || Application.isPlaying)
  362. {
  363. EditorGUI.indentLevel++;
  364. EditorGUILayout.PropertyField(m_ZoomFactor, GUILayout.ExpandWidth(false));
  365. EditorGUI.indentLevel--;
  366. }
  367. EditorGUI.BeginChangeCheck();
  368. EditorGUILayout.PropertyField(m_VerticalMarginBetweenPages, new GUIContent("Page Margins (px)"), GUILayout.ExpandWidth(false));
  369. if (EditorGUI.EndChangeCheck())
  370. {
  371. if (m_VerticalMarginBetweenPages.floatValue < 0.0f)
  372. m_VerticalMarginBetweenPages.floatValue = 0.0f;
  373. }
  374. EditorGUI.BeginChangeCheck();
  375. EditorGUILayout.PropertyField(m_MinZoomFactor, GUILayout.ExpandWidth(false));
  376. if (EditorGUI.EndChangeCheck())
  377. {
  378. if (m_MinZoomFactor.floatValue < 0.01f)
  379. m_MinZoomFactor.floatValue = 0.01f;
  380. }
  381. EditorGUI.BeginChangeCheck();
  382. EditorGUILayout.PropertyField(m_MaxZoomFactor, GUILayout.ExpandWidth(false));
  383. if (EditorGUI.EndChangeCheck())
  384. {
  385. if (m_MaxZoomFactor.floatValue < m_MinZoomFactor.floatValue)
  386. m_MaxZoomFactor.floatValue = m_MinZoomFactor.floatValue;
  387. }
  388. EditorGUILayout.PropertyField(m_ZoomStep, GUILayout.ExpandWidth(false));
  389. EditorGUILayout.PropertyField(m_ScrollSensitivity, new GUIContent("Scroll Sensitivity (px)"), GUILayout.ExpandWidth(false));
  390. Rect controlRect = EditorGUILayout.GetControlRect(true);
  391. GUIContent guiLabel = new GUIContent("Show Top Bar");
  392. using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowTopBar))
  393. {
  394. bool showTopBar = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowTopBar);
  395. if (showTopBar != viewer.ShowTopBar)
  396. {
  397. Undo.SetCurrentGroupName("PDFViewer.ShowTopBar");
  398. int group = Undo.GetCurrentGroup();
  399. Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.ShowTopBar");
  400. viewer.ShowTopBar = showTopBar;
  401. Undo.CollapseUndoOperations(group);
  402. m_ShowTopBar.boolValue = viewer.ShowTopBar;
  403. }
  404. }
  405. controlRect = EditorGUILayout.GetControlRect(true);
  406. guiLabel = new GUIContent("Show VScrollBar");
  407. using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowVerticalScrollBar))
  408. {
  409. bool showVerticalScrollBar = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowVerticalScrollBar);
  410. if (showVerticalScrollBar != viewer.ShowVerticalScrollBar)
  411. {
  412. Undo.SetCurrentGroupName("PDFViewer.VScrollBar");
  413. int group = Undo.GetCurrentGroup();
  414. Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.VScrollBar");
  415. viewer.ShowVerticalScrollBar = showVerticalScrollBar;
  416. Undo.CollapseUndoOperations(group);
  417. m_ShowVerticalScrollBar.boolValue = viewer.ShowVerticalScrollBar;
  418. }
  419. }
  420. controlRect = EditorGUILayout.GetControlRect(true);
  421. guiLabel = new GUIContent("Show HScrollBar");
  422. using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowHorizontalScrollBar))
  423. {
  424. bool showHorizontalScrollBar = EditorGUI.Toggle(controlRect, "Show HScrollBar", viewer.ShowHorizontalScrollBar);
  425. if (showHorizontalScrollBar != viewer.ShowHorizontalScrollBar)
  426. {
  427. Undo.SetCurrentGroupName("PDFViewer.HScrollBar");
  428. int group = Undo.GetCurrentGroup();
  429. Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.HScrollBar");
  430. viewer.ShowHorizontalScrollBar = showHorizontalScrollBar;
  431. Undo.CollapseUndoOperations(group);
  432. m_ShowHorizontalScrollBar.boolValue = viewer.ShowHorizontalScrollBar;
  433. }
  434. }
  435. if (viewer.m_Internal.LeftPanel != null)
  436. {
  437. controlRect = EditorGUILayout.GetControlRect(true);
  438. guiLabel = new GUIContent("Show Bookmarks Viewer");
  439. using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowBookmarksViewer))
  440. {
  441. bool showBookmarksViewer = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowBookmarksViewer);
  442. if (showBookmarksViewer != viewer.ShowBookmarksViewer)
  443. {
  444. Undo.SetCurrentGroupName("PDFViewer.ShowBookmarksViewer");
  445. int group = Undo.GetCurrentGroup();
  446. Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.ShowBookmarksViewer");
  447. viewer.ShowBookmarksViewer = showBookmarksViewer;
  448. Undo.CollapseUndoOperations(group);
  449. m_ShowBookmarksViewer.boolValue = viewer.ShowBookmarksViewer;
  450. }
  451. }
  452. controlRect = EditorGUILayout.GetControlRect(true);
  453. guiLabel = new GUIContent("Show Thumbnails Viewer");
  454. using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowThumbnailsViewer))
  455. {
  456. bool showThumbnailsViewer = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowThumbnailsViewer);
  457. if (showThumbnailsViewer != viewer.ShowThumbnailsViewer)
  458. {
  459. Undo.SetCurrentGroupName("PDFViewer.ShowThumbnailsViewer");
  460. int group = Undo.GetCurrentGroup();
  461. Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.ShowThumbnailsViewer");
  462. viewer.ShowThumbnailsViewer = showThumbnailsViewer;
  463. Undo.CollapseUndoOperations(group);
  464. m_ShowThumbnailsViewer.boolValue = viewer.ShowThumbnailsViewer;
  465. }
  466. }
  467. }
  468. Color oldColor = viewer.BackgroundColor;
  469. Color newColor = EditorGUILayout.ColorField("Viewer BG Color", viewer.BackgroundColor);
  470. if (oldColor != newColor)
  471. {
  472. Undo.RecordObject(viewer.m_Internal.Viewport.GetComponent<Image>(), "PDFViewerBackground");
  473. viewer.BackgroundColor = newColor;
  474. }
  475. GUILayout.Space(4.0f);
  476. }
  477. GUILayout.EndVertical();
  478. }
  479. private void InspectLinksSettings()
  480. {
  481. GUILayout.BeginVertical("Box");
  482. if (EnterGroup("Links Settings", "Paroxe.PdfRenderer.PDFViewer.ShowLinksSettings"))
  483. {
  484. EditorGUILayout.PropertyField(m_ChangeCursorWhenOverURL, new GUIContent("Change Cursor"));
  485. EditorGUILayout.PropertyField(m_AllowOpenURL, new GUIContent("Allow Open URL"));
  486. GUILayout.Space(4.0f);
  487. }
  488. GUILayout.EndVertical();
  489. }
  490. private void InspectSearchSettings()
  491. {
  492. PDFViewer viewer = (PDFViewer)target;
  493. if (viewer.m_Internal.SearchPanel != null)
  494. {
  495. GUILayout.BeginVertical("Box");
  496. if (EnterGroup("Search Settings", "Paroxe.PdfRenderer.PDFViewer.ShowSearchSettings"))
  497. {
  498. EditorGUILayout.PropertyField(m_SearchResultColor, new GUIContent("Result Color"));
  499. EditorGUILayout.PropertyField(m_SearchResultPadding, new GUIContent("Result Padding"));
  500. EditorGUILayout.PropertyField(m_SearchTimeBudgetPerFrame, new GUIContent("Time (% per frame)"));
  501. GUILayout.Space(4.0f);
  502. }
  503. GUILayout.EndVertical();
  504. }
  505. }
  506. private void InspectOtherSettings()
  507. {
  508. GUILayout.BeginVertical("Box");
  509. if (EnterGroup("Other Settings", "Paroxe.PdfRenderer.PDFViewer.ShowOtherSettings"))
  510. {
  511. EditorGUILayout.PropertyField(m_ParagraphZoomingEnable, new GUIContent("Paragraph Zooming"), GUILayout.ExpandWidth(false));
  512. if (m_ParagraphZoomingEnable.boolValue)
  513. {
  514. EditorGUILayout.PropertyField(m_ParagraphZoomFactor, new GUIContent(" Zoom Factor"), GUILayout.ExpandWidth(false));
  515. EditorGUILayout.PropertyField(m_ParagraphDetectionThreshold, new GUIContent(" Detection Threshold (px)"), GUILayout.ExpandWidth(false));
  516. }
  517. EditorGUILayout.PropertyField(m_PageTileTexture);
  518. EditorGUILayout.PropertyField(m_PageColor);
  519. GUILayout.Space(4.0f);
  520. }
  521. GUILayout.EndVertical();
  522. }
  523. private void InspectRenderingSettings()
  524. {
  525. PDFViewer viewer = (PDFViewer)target;
  526. GUILayout.BeginVertical("Box");
  527. if (EnterGroup("Rendering Settings", "Paroxe.PdfRenderer.PDFViewer.ShowRenderSettings"))
  528. {
  529. Rect controlRect = EditorGUILayout.GetControlRect(true);
  530. GUIContent guiLabel = new GUIContent("Maximum Quality");
  531. using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_MaxZoomFactorTextureQuality))
  532. {
  533. float maxRenderingQuality = EditorGUI.FloatField(controlRect, guiLabel, viewer.MaxZoomFactorTextureQuality);
  534. if (maxRenderingQuality != viewer.MaxZoomFactorTextureQuality)
  535. {
  536. viewer.MaxZoomFactorTextureQuality = maxRenderingQuality;
  537. m_MaxZoomFactorTextureQuality.floatValue = viewer.MaxZoomFactorTextureQuality;
  538. }
  539. }
  540. EditorGUILayout.PropertyField(m_RenderAnnotations, new GUIContent("Render Annotations"), GUILayout.ExpandWidth(false));
  541. EditorGUILayout.PropertyField(m_RenderGrayscale, new GUIContent("Render Grayscale"), GUILayout.ExpandWidth(false));
  542. GUILayout.Space(4.0f);
  543. }
  544. GUILayout.EndVertical();
  545. }
  546. private static bool EnterGroup(string title, string key)
  547. {
  548. bool enterGroup = EditorPrefs.GetBool(key, true);
  549. if (enterGroup != PRHelper.GroupHeader(title, enterGroup))
  550. {
  551. enterGroup = !enterGroup;
  552. EditorPrefs.SetBool(key, enterGroup);
  553. }
  554. return enterGroup;
  555. }
  556. private static void ShowInExplorer(string filePath)
  557. {
  558. filePath = Path.GetFullPath(filePath.Replace(@"/", @"\"));
  559. if (File.Exists(filePath))
  560. System.Diagnostics.Process.Start("explorer.exe", "/select," + filePath);
  561. }
  562. private static bool Browse(string startPath, ref string filename, ref string folder, ref string filePath, ref bool isStreamingAsset, ref bool isPersistentData, ref bool isResourcesAsset, ref bool isFilePath)
  563. {
  564. bool result = false;
  565. string path = EditorUtility.OpenFilePanel("Browse video file", startPath, "*");
  566. if (!string.IsNullOrEmpty(path) && !path.EndsWith(".meta"))
  567. {
  568. string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
  569. projectRoot = projectRoot.Replace('\\', '/');
  570. if (path.StartsWith(projectRoot))
  571. {
  572. if (path.StartsWith(Application.streamingAssetsPath))
  573. {
  574. path = path.Remove(0, Application.streamingAssetsPath.Length);
  575. filename = Path.GetFileName(path);
  576. path = Path.GetDirectoryName(path);
  577. if (path.StartsWith(Path.DirectorySeparatorChar.ToString()) || path.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
  578. {
  579. path = path.Remove(0, 1);
  580. }
  581. folder = path;
  582. isPersistentData = false;
  583. isStreamingAsset = true;
  584. isResourcesAsset = false;
  585. isFilePath = false;
  586. }
  587. else if (path.StartsWith(Application.persistentDataPath))
  588. {
  589. path = path.Remove(0, Application.persistentDataPath.Length);
  590. filename = Path.GetFileName(path);
  591. path = Path.GetDirectoryName(path);
  592. if (path.StartsWith(Path.DirectorySeparatorChar.ToString()) || path.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
  593. {
  594. path = path.Remove(0, 1);
  595. }
  596. folder = path;
  597. isPersistentData = true;
  598. isStreamingAsset = false;
  599. isResourcesAsset = false;
  600. isFilePath = false;
  601. }
  602. else if (path.StartsWith(Application.dataPath + "/Resources"))
  603. {
  604. path = path.Remove(0, (Application.dataPath + "/Resources").Length);
  605. filename = Path.GetFileName(path);
  606. path = Path.GetDirectoryName(path);
  607. if (path.StartsWith(Path.DirectorySeparatorChar.ToString()) || path.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
  608. {
  609. path = path.Remove(0, 1);
  610. }
  611. folder = path;
  612. isPersistentData = false;
  613. isStreamingAsset = false;
  614. isResourcesAsset = true;
  615. isFilePath = false;
  616. }
  617. else
  618. {
  619. path = path.Remove(0, projectRoot.Length + 1);
  620. filePath = path;
  621. isPersistentData = false;
  622. isStreamingAsset = false;
  623. isResourcesAsset = false;
  624. isFilePath = true;
  625. }
  626. }
  627. else
  628. {
  629. filePath = path;
  630. isPersistentData = false;
  631. isStreamingAsset = false;
  632. isResourcesAsset = false;
  633. isFilePath = true;
  634. }
  635. result = true;
  636. }
  637. return result;
  638. }
  639. private Texture2D MakeTex(int width, int height, Color col)
  640. {
  641. Color[] pix = new Color[width * height];
  642. for (int i = 0; i < pix.Length; i++)
  643. {
  644. pix[i] = col;
  645. }
  646. Texture2D result = new Texture2D(width, height);
  647. result.hideFlags = HideFlags.HideAndDontSave;
  648. result.SetPixels(pix);
  649. result.Apply();
  650. return result;
  651. }
  652. private class BytesSupplierInfo
  653. {
  654. public Component m_Behaviour;
  655. public GameObject m_GameObject;
  656. public string m_MethodName;
  657. public BytesSupplierInfo(GameObject gameObject, Component component, string methodName)
  658. {
  659. m_GameObject = gameObject;
  660. m_Behaviour = component;
  661. m_MethodName = methodName;
  662. }
  663. }
  664. }
  665. }