PDFViewerEditor.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Reflection;
  13. using UnityEditor;
  14. using UnityEngine;
  15. using UnityEngine.UI;
  16. namespace Paroxe.PdfRenderer.Internal.Viewer
  17. {
  18. [CustomEditor(typeof (PDFViewer), true)]
  19. public class PDFViewerEditor : Editor
  20. {
  21. GUIStyle m_Background1;
  22. GUIStyle m_Background2;
  23. GUIStyle m_Background3;
  24. Texture2D m_Logo;
  25. PDFViewer pdfViewer = null;
  26. PRParoxeBanner m_ParoxeBanner;
  27. public override void OnInspectorGUI()
  28. {
  29. if (pdfViewer != null)
  30. {
  31. Undo.RecordObject(pdfViewer, "PDFViewer");
  32. if (pdfViewer.m_Internal != null)
  33. Undo.RecordObject(pdfViewer.m_Internal, "PDFViewer_Internal");
  34. }
  35. if (m_Logo != null)
  36. {
  37. Rect rect = GUILayoutUtility.GetRect(m_Logo.width, m_Logo.height);
  38. GUI.DrawTexture(rect, m_Logo, ScaleMode.ScaleToFit);
  39. }
  40. if (pdfViewer.m_Internal == null && IsPrefabGhost(pdfViewer.transform))
  41. {
  42. return;
  43. }
  44. pdfViewer.m_Internal.m_BannerIsOpened = m_ParoxeBanner.DoOnGUI(pdfViewer.m_Internal.m_BannerIsOpened);
  45. if (pdfViewer.m_Internal == null || pdfViewer.m_Internal.m_Version != PDFLibrary.CurrentVersion)
  46. {
  47. GUILayout.BeginVertical("Box");
  48. GUILayout.Label("UPDATE TO VERSION " + PDFLibrary.CurrentVersion, EditorStyles.boldLabel);
  49. GUILayout.Space(10.0f);
  50. if (pdfViewer.m_Internal != null)
  51. {
  52. EditorGUILayout.HelpBox(
  53. "\n\rThe update process won't overwrite UI customizations made by developpers as long as theses changes are minors. Please make a backup before updating your PDFViewer prefab.\n\r",
  54. MessageType.Info);
  55. string[] newFeatures = PDFViewerBuilder.GetNewFeatures(pdfViewer.gameObject);
  56. foreach (string feature in newFeatures)
  57. {
  58. GUILayout.Label(feature, EditorStyles.boldLabel);
  59. }
  60. GUILayout.Space(10.0f);
  61. }
  62. Color oc = GUI.color;
  63. GUI.color = Color.green;
  64. if (GUILayout.Button("\n\rUPDATE\n\r"))
  65. {
  66. if (pdfViewer.m_Internal == null)
  67. {
  68. string filePath = pdfViewer.FilePath;
  69. string password = pdfViewer.Password;
  70. PDFViewerBuilder.BuildPDFViewerWithin(pdfViewer.gameObject, null);
  71. pdfViewer.FileSource = PDFViewer.FileSourceType.FilePath;
  72. pdfViewer.FilePath = filePath;
  73. pdfViewer.Password = password;
  74. }
  75. else
  76. {
  77. PDFViewerBuilder.UpdateToLatestVersion(pdfViewer.gameObject);
  78. }
  79. }
  80. GUI.color = oc;
  81. GUILayout.Space(10.0f);
  82. GUILayout.EndVertical();
  83. if (pdfViewer.m_Internal == null)
  84. {
  85. return;
  86. }
  87. }
  88. GUILayout.BeginVertical("Box");
  89. pdfViewer.m_Internal.m_UiShowLoadOptions = PRHelper.GroupHeader("Load Options", pdfViewer.m_Internal.m_UiShowLoadOptions);
  90. if (pdfViewer.m_Internal.m_UiShowLoadOptions)
  91. {
  92. pdfViewer.FileSource = (PDFViewer.FileSourceType)EditorGUILayout.EnumPopup("Source", pdfViewer.FileSource);
  93. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Resources
  94. || pdfViewer.FileSource == PDFViewer.FileSourceType.StreamingAssets)
  95. {
  96. EditorGUI.indentLevel++;
  97. pdfViewer.Folder = EditorGUILayout.TextField("Folder", pdfViewer.Folder);
  98. pdfViewer.FileName = EditorGUILayout.TextField("File Name", pdfViewer.FileName);
  99. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Resources)
  100. {
  101. if (File.Exists(Application.dataPath + "/Resources/" + pdfViewer.GetFileLocation())
  102. &&
  103. !File.Exists(Application.dataPath + "/Resources/" +
  104. pdfViewer.GetFileLocation().Replace(".bytes", "") + ".bytes"))
  105. {
  106. EditorGUILayout.HelpBox(
  107. "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",
  108. MessageType.Warning);
  109. GUILayout.Space(10.0f);
  110. }
  111. }
  112. EditorGUI.indentLevel--;
  113. }
  114. else if (pdfViewer.FileSource == PDFViewer.FileSourceType.Web)
  115. {
  116. EditorGUI.indentLevel++;
  117. pdfViewer.FileURL = EditorGUILayout.TextField("Url", pdfViewer.FileURL);
  118. EditorGUI.indentLevel--;
  119. }
  120. else if (pdfViewer.FileSource == PDFViewer.FileSourceType.FilePath)
  121. {
  122. EditorGUI.indentLevel++;
  123. pdfViewer.FilePath = EditorGUILayout.TextField("File Path", pdfViewer.FilePath);
  124. #if ((UNITY_4_6 || UNITY_4_7) && UNITY_WINRT)
  125. EditorGUILayout.HelpBox(
  126. "File Path for Windows Phone 8.1 is only supported on Unity 5+", MessageType.Warning);
  127. #endif
  128. EditorGUI.indentLevel--;
  129. }
  130. if (pdfViewer.FileSource != PDFViewer.FileSourceType.Bytes
  131. && pdfViewer.FileSource != PDFViewer.FileSourceType.None)
  132. {
  133. #if UNITY_IOS
  134. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Web)
  135. {
  136. EditorGUILayout.BeginHorizontal();
  137. EditorGUILayout.PrefixLabel(" ");
  138. EditorGUILayout.HelpBox(
  139. "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" +
  140. "<key>NSAppTransportSecurity</key>\n\r" +
  141. " <dict>\n\r" +
  142. " <key>NSAllowsArbitraryLoads</key>\n\r" +
  143. " <true/>\n\r" +
  144. "</dict>", MessageType.Info);
  145. EditorGUILayout.EndHorizontal();
  146. GUILayout.Space(10.0f);
  147. }
  148. #endif
  149. if (pdfViewer.FileSource == PDFViewer.FileSourceType.StreamingAssets
  150. || pdfViewer.FileSource == PDFViewer.FileSourceType.Resources
  151. || pdfViewer.FileSource == PDFViewer.FileSourceType.FilePath)
  152. {
  153. EditorGUILayout.BeginHorizontal();
  154. EditorGUILayout.PrefixLabel(" ");
  155. GUI.color = Color.green;
  156. if (GUILayout.Button("Browse"))
  157. {
  158. string baseDirectory = Application.streamingAssetsPath;
  159. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Resources)
  160. baseDirectory = "Assets/Resources";
  161. else if (pdfViewer.FileSource == PDFViewer.FileSourceType.FilePath)
  162. {
  163. string projectRoot = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, ".."));
  164. projectRoot = projectRoot.Replace('\\', '/');
  165. baseDirectory = projectRoot;
  166. }
  167. if (!Directory.Exists(baseDirectory))
  168. {
  169. Directory.CreateDirectory(baseDirectory);
  170. AssetDatabase.Refresh();
  171. }
  172. string folder = "";
  173. string fileName = "";
  174. string filePath = "";
  175. bool useStreamingAssets = false;
  176. bool useResources = false;
  177. bool useFilePath = false;
  178. if (Browse(baseDirectory, ref fileName, ref folder, ref filePath, ref useStreamingAssets, ref useResources, ref useFilePath))
  179. {
  180. if (useStreamingAssets)
  181. pdfViewer.FileSource = PDFViewer.FileSourceType.StreamingAssets;
  182. else if (useResources)
  183. pdfViewer.FileSource = PDFViewer.FileSourceType.Resources;
  184. else if (useFilePath)
  185. pdfViewer.FileSource = PDFViewer.FileSourceType.FilePath;
  186. if (pdfViewer.FileSource != PDFViewer.FileSourceType.FilePath)
  187. {
  188. pdfViewer.Folder = folder;
  189. pdfViewer.FileName = fileName;
  190. }
  191. else
  192. {
  193. pdfViewer.FilePath = filePath;
  194. }
  195. }
  196. }
  197. GUI.color = Color.white;
  198. EditorGUILayout.EndHorizontal();
  199. }
  200. #if UNITY_EDITOR_WIN
  201. if (pdfViewer.FileSource != PDFViewer.FileSourceType.Asset && pdfViewer.FileSource != PDFViewer.FileSourceType.DocumentObject)
  202. {
  203. EditorGUILayout.BeginHorizontal();
  204. EditorGUILayout.PrefixLabel(" ");
  205. GUI.color = Color.cyan;
  206. if (GUILayout.Button("Reveal File"))
  207. {
  208. string filePath = "";
  209. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Resources)
  210. {
  211. filePath = Application.dataPath + "/Resources/" + pdfViewer.GetFileLocation();
  212. }
  213. else
  214. {
  215. filePath = pdfViewer.GetFileLocation();
  216. }
  217. if (pdfViewer.FileSource != PDFViewer.FileSourceType.Web)
  218. {
  219. if (!File.Exists(filePath))
  220. {
  221. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Resources &&
  222. File.Exists(filePath + ".bytes"))
  223. {
  224. ShowInExplorer(filePath + ".bytes");
  225. }
  226. else
  227. {
  228. EditorUtility.DisplayDialog("Error",
  229. "The file path is badly formed, contains invalid characters or doesn't exists:\r\n\r\n" +
  230. filePath, "Ok");
  231. }
  232. }
  233. else
  234. {
  235. ShowInExplorer(filePath);
  236. }
  237. }
  238. else
  239. {
  240. try
  241. {
  242. System.Diagnostics.Process.Start(filePath);
  243. }
  244. catch
  245. {
  246. EditorUtility.DisplayDialog("Error",
  247. "The URL is badly formed or contains invalid characters:\r\n\r\n" + filePath, "Ok");
  248. }
  249. }
  250. }
  251. GUI.color = Color.white;
  252. EditorGUILayout.EndHorizontal();
  253. }
  254. #endif
  255. }
  256. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Bytes)
  257. {
  258. EditorGUI.indentLevel++;
  259. serializedObject.Update();
  260. GameObject oldObject = pdfViewer.BytesSupplierObject;
  261. var bytesSupplierObject = serializedObject.FindProperty("m_BytesSupplierObject");
  262. EditorGUILayout.PropertyField(bytesSupplierObject, new GUIContent("Supplier Object"));
  263. serializedObject.ApplyModifiedProperties();
  264. int selectedIndex = 0;
  265. if (pdfViewer.BytesSupplierObject != null)
  266. {
  267. try
  268. {
  269. List<BytesSupplierInfo> possibleSuppliers = new List<BytesSupplierInfo>();
  270. possibleSuppliers.Add(new BytesSupplierInfo(null, null, ""));
  271. Component[] components = pdfViewer.BytesSupplierObject.GetComponents(typeof(Component));
  272. foreach (Component component in components)
  273. {
  274. Type type = component.GetType();
  275. MethodInfo[] methods = type.GetMethods();
  276. if (methods.Length == 0)
  277. {
  278. continue;
  279. }
  280. foreach (MethodInfo method in methods)
  281. {
  282. if ((method.GetParameters() == null || method.GetParameters().Length == 0)
  283. && method.ReturnType == typeof(byte[]))
  284. {
  285. possibleSuppliers.Add(new BytesSupplierInfo(pdfViewer.BytesSupplierObject, component,
  286. method.Name));
  287. if (oldObject == pdfViewer.BytesSupplierObject
  288. && method.Name == pdfViewer.BytesSupplierFunctionName
  289. && component == pdfViewer.BytesSupplierComponent)
  290. {
  291. selectedIndex = possibleSuppliers.Count - 1;
  292. }
  293. }
  294. }
  295. }
  296. string[] supplierTitles = new string[possibleSuppliers.Count];
  297. for (int i = 0; i < supplierTitles.Length; ++i)
  298. {
  299. if (i == 0)
  300. {
  301. supplierTitles[0] = "No Function";
  302. continue;
  303. }
  304. supplierTitles[i] = possibleSuppliers[i].m_Behaviour.name + "." +
  305. possibleSuppliers[i].m_MethodName;
  306. }
  307. EditorGUILayout.BeginHorizontal();
  308. EditorGUILayout.PrefixLabel("Supplier Function");
  309. var choiceIndex = EditorGUILayout.Popup(selectedIndex, supplierTitles);
  310. if (choiceIndex == 0)
  311. {
  312. pdfViewer.BytesSupplierComponent = null;
  313. pdfViewer.BytesSupplierFunctionName = "";
  314. }
  315. else
  316. {
  317. pdfViewer.BytesSupplierComponent = possibleSuppliers[choiceIndex].m_Behaviour;
  318. pdfViewer.BytesSupplierFunctionName = possibleSuppliers[choiceIndex].m_MethodName;
  319. }
  320. EditorGUILayout.EndHorizontal();
  321. }
  322. catch (Exception)
  323. {
  324. pdfViewer.BytesSupplierComponent = null;
  325. pdfViewer.BytesSupplierFunctionName = "";
  326. }
  327. }
  328. #if ((UNITY_4_6 || UNITY_4_7) && UNITY_WINRT)
  329. EditorGUILayout.HelpBox(
  330. "Bytes source for Windows Phone 8.1 is only supported on Unity 5+", MessageType.Warning);
  331. #endif
  332. EditorGUI.indentLevel--;
  333. }
  334. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Asset)
  335. {
  336. pdfViewer.PDFAsset =
  337. (PDFAsset)EditorGUILayout.ObjectField("PDF Asset", pdfViewer.PDFAsset, typeof(PDFAsset), true);
  338. }
  339. //if (pdfViewer.FileSource != PDFViewer.FileSourceType.None)
  340. {
  341. pdfViewer.LoadOnEnable = EditorGUILayout.Toggle("Load On Enable", pdfViewer.LoadOnEnable);
  342. pdfViewer.UnloadOnDisable = EditorGUILayout.Toggle("Unload On Disable", pdfViewer.UnloadOnDisable);
  343. }
  344. if (pdfViewer.FileSource == PDFViewer.FileSourceType.Asset)
  345. {
  346. EditorGUILayout.BeginHorizontal();
  347. EditorGUILayout.PrefixLabel("");
  348. EditorGUILayout.HelpBox(
  349. "To convert pdf file to .asset right click on pdf and select \"PDF Renderer\\Convert to .asset\"",
  350. MessageType.Info);
  351. EditorGUILayout.EndHorizontal();
  352. GUILayout.Space(10.0f);
  353. }
  354. GUILayout.Space(10.0f);
  355. }
  356. GUILayout.EndVertical();
  357. GUILayout.BeginVertical("Box");
  358. pdfViewer.m_Internal.m_UiShowPasswordOptions = PRHelper.GroupHeader("Password Options", pdfViewer.m_Internal.m_UiShowPasswordOptions);
  359. if (pdfViewer.m_Internal.m_UiShowPasswordOptions)
  360. {
  361. EditorGUI.indentLevel++;
  362. pdfViewer.Password = EditorGUILayout.PasswordField("Password", pdfViewer.Password);
  363. EditorGUI.indentLevel--;
  364. GUILayout.Space(10.0f);
  365. }
  366. GUILayout.EndVertical();
  367. GUILayout.BeginVertical("Box");
  368. pdfViewer.m_Internal.m_UiShowViewerSettings = PRHelper.GroupHeader("Viewer Settings", pdfViewer.m_Internal.m_UiShowViewerSettings);
  369. if (pdfViewer.m_Internal.m_UiShowViewerSettings)
  370. {
  371. pdfViewer.PageFitting = (PDFViewer.PageFittingType)EditorGUILayout.EnumPopup("Page Fitting", pdfViewer.PageFitting);
  372. if (pdfViewer.PageFitting == PDFViewer.PageFittingType.Zoom || Application.isPlaying)
  373. {
  374. EditorGUI.indentLevel++;
  375. pdfViewer.ZoomFactor = EditorGUILayout.FloatField("Zoom", pdfViewer.ZoomFactor,
  376. GUILayout.ExpandWidth(false));
  377. EditorGUI.indentLevel--;
  378. }
  379. pdfViewer.VerticalMarginBetweenPages = EditorGUILayout.FloatField("Page Margins (px)",
  380. pdfViewer.VerticalMarginBetweenPages, GUILayout.ExpandWidth(false));
  381. pdfViewer.MinZoomFactor = EditorGUILayout.FloatField("Minimum Zoom", pdfViewer.MinZoomFactor,
  382. GUILayout.ExpandWidth(false));
  383. pdfViewer.MaxZoomFactor = EditorGUILayout.FloatField("Maximum Zoom", pdfViewer.MaxZoomFactor,
  384. GUILayout.ExpandWidth(false));
  385. pdfViewer.ZoomStep = EditorGUILayout.FloatField("Zoom Step", pdfViewer.ZoomStep,
  386. GUILayout.ExpandWidth(false));
  387. pdfViewer.ScrollSensitivity = EditorGUILayout.FloatField("Scroll Sensitivity (px)",
  388. pdfViewer.ScrollSensitivity, GUILayout.ExpandWidth(false));
  389. pdfViewer.ShowTopBar = EditorGUILayout.Toggle("Show Top Bar", pdfViewer.ShowTopBar);
  390. pdfViewer.ShowVerticalScrollBar = EditorGUILayout.Toggle("Show VScrollBar", pdfViewer.ShowVerticalScrollBar);
  391. pdfViewer.ShowHorizontalScrollBar = EditorGUILayout.Toggle("Show HScrollBar",
  392. pdfViewer.ShowHorizontalScrollBar);
  393. if (pdfViewer.m_Internal.m_LeftPanel != null)
  394. {
  395. pdfViewer.ShowBookmarksViewer = EditorGUILayout.Toggle("Show Bookmarks Viewer", pdfViewer.ShowBookmarksViewer);
  396. pdfViewer.ShowThumbnailsViewer = EditorGUILayout.Toggle("Show Thumbnails Viewer", pdfViewer.ShowThumbnailsViewer);
  397. }
  398. pdfViewer.AllowOpenURL = EditorGUILayout.Toggle("Allow Open URL", pdfViewer.AllowOpenURL);
  399. Color oldColor = pdfViewer.BackgroundColor;
  400. pdfViewer.BackgroundColor = EditorGUILayout.ColorField("Viewer BG Color", pdfViewer.BackgroundColor);
  401. if (oldColor != pdfViewer.BackgroundColor)
  402. {
  403. EditorUtility.SetDirty(pdfViewer.m_Internal.m_Viewport.GetComponent<Image>());
  404. }
  405. GUILayout.Space(10.0f);
  406. }
  407. GUILayout.EndVertical();
  408. if (pdfViewer.m_Internal.m_SearchPanel != null)
  409. {
  410. GUILayout.BeginVertical("Box");
  411. pdfViewer.m_Internal.m_UiShowSearchSettings = PRHelper.GroupHeader("Search Settings", pdfViewer.m_Internal.m_UiShowSearchSettings);
  412. if (pdfViewer.m_Internal.m_UiShowSearchSettings)
  413. {
  414. pdfViewer.SearchResultColor = EditorGUILayout.ColorField("Result Color", pdfViewer.SearchResultColor);
  415. pdfViewer.SearchResultPadding = EditorGUILayout.Vector2Field("Result Padding",
  416. pdfViewer.SearchResultPadding);
  417. pdfViewer.SearchTimeBudgetPerFrame = EditorGUILayout.Slider("Time (% per frame)",
  418. pdfViewer.SearchTimeBudgetPerFrame, 0.0f, 1.0f);
  419. GUILayout.Space(10.0f);
  420. }
  421. GUILayout.EndVertical();
  422. }
  423. GUILayout.BeginVertical("Box");
  424. pdfViewer.m_Internal.m_UiShowOtherSettings = PRHelper.GroupHeader("Other Settings", pdfViewer.m_Internal.m_UiShowOtherSettings);
  425. if (pdfViewer.m_Internal.m_UiShowOtherSettings)
  426. {
  427. pdfViewer.ParagraphZoomingEnable = EditorGUILayout.Toggle("Paragraph Zooming", pdfViewer.ParagraphZoomingEnable, GUILayout.ExpandWidth(false));
  428. if (pdfViewer.ParagraphZoomingEnable)
  429. {
  430. pdfViewer.ParagraphZoomFactor = EditorGUILayout.FloatField(" Zoom Factor", pdfViewer.ParagraphZoomFactor, GUILayout.ExpandWidth(false));
  431. pdfViewer.ParagraphDetectionThreshold = EditorGUILayout.FloatField(" Detection Threshold (px)", pdfViewer.ParagraphDetectionThreshold, GUILayout.ExpandWidth(false));
  432. }
  433. pdfViewer.PageTileTexture = (Texture2D)EditorGUILayout.ObjectField("Page Tile Texture", pdfViewer.PageTileTexture, typeof(Texture2D), true);
  434. pdfViewer.PageColor = EditorGUILayout.ColorField("Page Color", pdfViewer.PageColor);
  435. GUILayout.Space(10.0f);
  436. }
  437. GUILayout.EndVertical();
  438. GUILayout.BeginVertical("Box");
  439. pdfViewer.m_Internal.m_UiShowRenderSettings = PRHelper.GroupHeader("Render Settings", pdfViewer.m_Internal.m_UiShowRenderSettings);
  440. if (pdfViewer.m_Internal.m_UiShowRenderSettings)
  441. {
  442. pdfViewer.MaxZoomFactorTextureQuality = EditorGUILayout.FloatField("Maximum Quality",
  443. pdfViewer.MaxZoomFactorTextureQuality, GUILayout.ExpandWidth(false));
  444. pdfViewer.RenderAnnotations = EditorGUILayout.Toggle("Render Annotations", pdfViewer.RenderAnnotations,
  445. GUILayout.ExpandWidth(false));
  446. pdfViewer.RenderGrayscale = EditorGUILayout.Toggle("Render Grayscale", pdfViewer.RenderGrayscale,
  447. GUILayout.ExpandWidth(false));
  448. GUILayout.Space(10.0f);
  449. }
  450. GUILayout.EndVertical();
  451. GUILayout.BeginVertical("Box");
  452. pdfViewer.m_Internal.m_UiShowDebugSettings = PRHelper.GroupHeader("Debug Settings", pdfViewer.m_Internal.m_UiShowDebugSettings);
  453. if (pdfViewer.m_Internal.m_UiShowDebugSettings)
  454. {
  455. pdfViewer.m_Internal.m_DrawDefaultInspector = EditorGUILayout.Toggle("Default Inspector", pdfViewer.m_Internal.m_DrawDefaultInspector);
  456. if (pdfViewer.m_Internal.m_DrawDefaultInspector)
  457. {
  458. GUILayout.Space(10.0f);
  459. DrawDefaultInspector();
  460. }
  461. GUILayout.Space(10.0f);
  462. }
  463. GUILayout.EndVertical();
  464. if (GUI.changed)
  465. {
  466. EditorUtility.SetDirty(pdfViewer);
  467. EditorUtility.SetDirty(pdfViewer.m_Internal);
  468. }
  469. }
  470. protected virtual void OnDisable()
  471. {
  472. DestroyImmediate(m_Background1.normal.background);
  473. DestroyImmediate(m_Background2.normal.background);
  474. DestroyImmediate(m_Background3.normal.background);
  475. }
  476. protected virtual void OnEnable()
  477. {
  478. pdfViewer = (PDFViewer) target;
  479. m_Background1 = new GUIStyle();
  480. m_Background1.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f));
  481. m_Background2 = new GUIStyle();
  482. m_Background2.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.0f));
  483. m_Background3 = new GUIStyle();
  484. m_Background3.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.05f));
  485. MonoScript script = MonoScript.FromScriptableObject(this);
  486. string scriptPath = AssetDatabase.GetAssetPath(script);
  487. m_Logo =
  488. (Texture2D)
  489. AssetDatabase.LoadAssetAtPath(Path.GetDirectoryName(scriptPath) + "/logo_pv.png", typeof (Texture2D));
  490. if (m_ParoxeBanner == null)
  491. m_ParoxeBanner = new PRParoxeBanner(Path.GetDirectoryName(scriptPath));
  492. }
  493. private static bool IsPrefabGhost(Transform This)
  494. {
  495. var TempObject = new GameObject();
  496. try
  497. {
  498. TempObject.transform.parent = This.parent;
  499. var OriginalIndex = This.GetSiblingIndex();
  500. This.SetSiblingIndex(int.MaxValue);
  501. if (This.GetSiblingIndex() == 0)
  502. {
  503. return true;
  504. }
  505. This.SetSiblingIndex(OriginalIndex);
  506. return false;
  507. }
  508. finally
  509. {
  510. UnityEngine.Object.DestroyImmediate(TempObject);
  511. }
  512. }
  513. private static void ShowInExplorer(string filePath)
  514. {
  515. filePath = Path.GetFullPath(filePath.Replace(@"/", @"\"));
  516. if (File.Exists(filePath))
  517. {
  518. System.Diagnostics.Process.Start("explorer.exe", "/select," + filePath);
  519. }
  520. }
  521. private static bool Browse(string startPath, ref string filename, ref string folder, ref string filePath, ref bool isStreamingAsset, ref bool isResourcesAsset, ref bool isFilePath)
  522. {
  523. bool result = false;
  524. string path = UnityEditor.EditorUtility.OpenFilePanel("Browse video file", startPath, "*");
  525. if (!string.IsNullOrEmpty(path) && !path.EndsWith(".meta"))
  526. {
  527. string projectRoot = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, ".."));
  528. projectRoot = projectRoot.Replace('\\', '/');
  529. if (path.StartsWith(projectRoot))
  530. {
  531. if (path.StartsWith(Application.streamingAssetsPath))
  532. {
  533. path = path.Remove(0, Application.streamingAssetsPath.Length);
  534. filename = System.IO.Path.GetFileName(path);
  535. path = System.IO.Path.GetDirectoryName(path);
  536. if (path.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString()) || path.StartsWith(System.IO.Path.AltDirectorySeparatorChar.ToString()))
  537. {
  538. path = path.Remove(0, 1);
  539. }
  540. folder = path;
  541. isStreamingAsset = true;
  542. isResourcesAsset = false;
  543. isFilePath = false;
  544. }
  545. else if (path.StartsWith(Application.dataPath + "/Resources"))
  546. {
  547. path = path.Remove(0, (Application.dataPath + "/Resources").Length);
  548. filename = System.IO.Path.GetFileName(path);
  549. path = System.IO.Path.GetDirectoryName(path);
  550. if (path.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString()) || path.StartsWith(System.IO.Path.AltDirectorySeparatorChar.ToString()))
  551. {
  552. path = path.Remove(0, 1);
  553. }
  554. folder = path;
  555. isStreamingAsset = false;
  556. isResourcesAsset = true;
  557. isFilePath = false;
  558. }
  559. else
  560. {
  561. path = path.Remove(0, projectRoot.Length + 1);
  562. filePath = path;
  563. isStreamingAsset = false;
  564. isResourcesAsset = false;
  565. isFilePath = true;
  566. }
  567. }
  568. else
  569. {
  570. filePath = path;
  571. isStreamingAsset = false;
  572. isResourcesAsset = false;
  573. isFilePath = true;
  574. }
  575. result = true;
  576. }
  577. return result;
  578. }
  579. private Texture2D MakeTex(int width, int height, Color col)
  580. {
  581. Color[] pix = new Color[width*height];
  582. for (int i = 0; i < pix.Length; i++)
  583. {
  584. pix[i] = col;
  585. }
  586. Texture2D result = new Texture2D(width, height);
  587. result.hideFlags = HideFlags.HideAndDontSave;
  588. result.SetPixels(pix);
  589. result.Apply();
  590. return result;
  591. }
  592. private class BytesSupplierInfo
  593. {
  594. public Component m_Behaviour;
  595. public GameObject m_GameObject;
  596. public string m_MethodName;
  597. public BytesSupplierInfo(GameObject gameObject, Component component, string methodName)
  598. {
  599. m_GameObject = gameObject;
  600. m_Behaviour = component;
  601. m_MethodName = methodName;
  602. }
  603. }
  604. }
  605. }