123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Paroxe.PdfRenderer.Internal.Viewer
- {
- [CustomEditor(typeof(PDFViewer), true)]
- public class PDFViewerEditor : Editor
- {
- private Texture2D m_Logo;
- private SerializedProperty m_FileSource = null;
- private SerializedProperty m_Folder = null;
- private SerializedProperty m_FileName = null;
- private SerializedProperty m_FileURL = null;
- private SerializedProperty m_FilePath = null;
- private SerializedProperty m_BytesSupplierObject = null;
- private SerializedProperty m_BytesSupplierComponent = null;
- private SerializedProperty m_BytesSupplierFunctionName = null;
- private SerializedProperty m_PDFAsset = null;
- private SerializedProperty m_LoadOnEnable = null;
- private SerializedProperty m_UnloadOnDisable = null;
- private SerializedProperty m_Password = null;
- private SerializedProperty m_ZoomFactor = null;
- private SerializedProperty m_ZoomStep = null;
- private SerializedProperty m_PageFitting = null;
- private SerializedProperty m_VerticalMarginBetweenPages = null;
- private SerializedProperty m_MinZoomFactor = null;
- private SerializedProperty m_MaxZoomFactor = null;
- private SerializedProperty m_ScrollSensitivity = null;
- private SerializedProperty m_ShowTopBar = null;
- private SerializedProperty m_ShowVerticalScrollBar = null;
- private SerializedProperty m_ShowBookmarksViewer = null;
- private SerializedProperty m_ShowHorizontalScrollBar = null;
- private SerializedProperty m_ShowThumbnailsViewer = null;
- private SerializedProperty m_ChangeCursorWhenOverURL = null;
- private SerializedProperty m_AllowOpenURL = null;
- private SerializedProperty m_SearchResultColor = null;
- private SerializedProperty m_SearchResultPadding = null;
- private SerializedProperty m_SearchTimeBudgetPerFrame = null;
- private SerializedProperty m_ParagraphZoomFactor = null;
- private SerializedProperty m_ParagraphZoomingEnable = null;
- private SerializedProperty m_ParagraphDetectionThreshold = null;
- private SerializedProperty m_PageTileTexture = null;
- private SerializedProperty m_PageColor = null;
- private SerializedProperty m_MaxZoomFactorTextureQuality = null;
- private SerializedProperty m_RenderSettings = null;
- private SerializedProperty m_RenderAnnotations = null;
- private SerializedProperty m_RenderGrayscale = null;
- protected virtual void OnEnable()
- {
- MonoScript script = MonoScript.FromScriptableObject(this);
- string scriptPath = AssetDatabase.GetAssetPath(script);
- m_Logo = (Texture2D) AssetDatabase.LoadAssetAtPath(Path.GetDirectoryName(scriptPath) + "/Icons/logo_pv.png", typeof(Texture2D));
- GetType().GetMembers(BindingFlags.NonPublic | BindingFlags.Instance)
- .Where(x => x.MemberType == MemberTypes.Field && ((FieldInfo)x).FieldType == typeof(SerializedProperty))
- .Cast<FieldInfo>()
- .ToList().ForEach(prop =>
- {
- SerializedProperty serializedProperty = serializedObject.FindProperty(prop.Name);
- if (serializedProperty != null)
- prop.SetValue(this, serializedProperty);
- });
- m_RenderAnnotations = m_RenderSettings.FindPropertyRelative("renderAnnotations");
- m_RenderGrayscale = m_RenderSettings.FindPropertyRelative("grayscale");
- }
- public override void OnInspectorGUI()
- {
- Undo.RecordObject(target, "PDFViewer");
- serializedObject.Update();
- if (m_Logo != null)
- {
- Rect rect = GUILayoutUtility.GetRect(m_Logo.width, m_Logo.height);
- GUI.DrawTexture(rect, m_Logo, ScaleMode.ScaleToFit);
- }
- InspectLoadSettings();
- InspectSecuritySettings();
- InspectViewerSettings();
- InspectSearchSettings();
- InspectOtherSettings();
- InspectRenderingSettings();
- serializedObject.ApplyModifiedProperties();
- }
- private void InspectLoadSettings()
- {
- PDFViewer viewer = (PDFViewer)target;
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Load Settings", "Paroxe.PdfRenderer.PDFViewer.ShowLoadSettings"))
- {
- EditorGUILayout.PropertyField(m_FileSource);
- PDFViewer.FileSourceType fileSourceType = (PDFViewer.FileSourceType)m_FileSource.enumValueIndex;
- if (fileSourceType == PDFViewer.FileSourceType.Resources
- || fileSourceType == PDFViewer.FileSourceType.StreamingAssets
- || fileSourceType == PDFViewer.FileSourceType.PersistentData)
- {
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(m_Folder);
- EditorGUILayout.PropertyField(m_FileName);
- if (fileSourceType == PDFViewer.FileSourceType.Resources)
- {
- if (File.Exists(Application.dataPath + "/Resources/" + viewer.GetFileLocation())
- && !File.Exists(Application.dataPath + "/Resources/" + viewer.GetFileLocation().Replace(".bytes", "") + ".bytes"))
- {
- EditorGUILayout.HelpBox(
- "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",
- MessageType.Warning);
- }
- }
- EditorGUI.indentLevel--;
- }
- else if (fileSourceType == PDFViewer.FileSourceType.Web)
- {
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(m_FileURL, new GUIContent("Url"));
- EditorGUI.indentLevel--;
- }
- else if (fileSourceType == PDFViewer.FileSourceType.FilePath)
- {
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(m_FilePath);
- EditorGUI.indentLevel--;
- }
- if (fileSourceType != PDFViewer.FileSourceType.Bytes && fileSourceType != PDFViewer.FileSourceType.None)
- {
- #if UNITY_IOS
- if (fileSourceType == PDFViewer.FileSourceType.Web)
- {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PrefixLabel(" ");
- EditorGUILayout.HelpBox(
- "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" +
- "<key>NSAppTransportSecurity</key>\n\r" +
- " <dict>\n\r" +
- " <key>NSAllowsArbitraryLoads</key>\n\r" +
- " <true/>\n\r" +
- "</dict>", MessageType.Info);
- EditorGUILayout.EndHorizontal();
- }
- #endif
- if (fileSourceType == PDFViewer.FileSourceType.StreamingAssets
- || fileSourceType == PDFViewer.FileSourceType.PersistentData
- || fileSourceType == PDFViewer.FileSourceType.Resources
- || fileSourceType == PDFViewer.FileSourceType.FilePath)
- {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PrefixLabel(" ");
- if (GUILayout.Button("Browse"))
- {
- string baseDirectory = "";
- if (fileSourceType == PDFViewer.FileSourceType.PersistentData)
- baseDirectory = Application.persistentDataPath;
- else if (fileSourceType == PDFViewer.FileSourceType.StreamingAssets)
- baseDirectory = Application.streamingAssetsPath;
- else if (fileSourceType == PDFViewer.FileSourceType.Resources)
- baseDirectory = "Assets/Resources";
- else if (fileSourceType == PDFViewer.FileSourceType.FilePath)
- {
- string projectRoot = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, ".."));
- projectRoot = projectRoot.Replace('\\', '/');
- baseDirectory = projectRoot;
- }
- if (!Directory.Exists(baseDirectory))
- {
- Directory.CreateDirectory(baseDirectory);
- AssetDatabase.Refresh();
- }
- string folder = "";
- string fileName = "";
- string filePath = "";
- bool usePersistentData = false;
- bool useStreamingAssets = false;
- bool useResources = false;
- bool useFilePath = false;
- if (Browse(baseDirectory, ref fileName, ref folder, ref filePath, ref useStreamingAssets, ref usePersistentData, ref useResources, ref useFilePath))
- {
- if (useStreamingAssets)
- fileSourceType = PDFViewer.FileSourceType.StreamingAssets;
- else if (usePersistentData)
- fileSourceType = PDFViewer.FileSourceType.PersistentData;
- else if (useResources)
- fileSourceType = PDFViewer.FileSourceType.Resources;
- else if (useFilePath)
- fileSourceType = PDFViewer.FileSourceType.FilePath;
- if (fileSourceType != PDFViewer.FileSourceType.FilePath)
- {
- m_Folder.stringValue = folder;
- m_FileName.stringValue = fileName;
- }
- else
- {
- m_FilePath.stringValue = filePath;
- }
- }
- }
- EditorGUILayout.EndHorizontal();
- }
- #if UNITY_EDITOR_WIN
- if (fileSourceType != PDFViewer.FileSourceType.Asset && fileSourceType != PDFViewer.FileSourceType.DocumentObject)
- {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PrefixLabel(" ");
- using (new EditorGUI.DisabledGroupScope(string.IsNullOrEmpty(m_FileName.stringValue.Trim())))
- {
- if (GUILayout.Button("Reveal File"))
- {
- string filePath = "";
- if (fileSourceType == PDFViewer.FileSourceType.Resources)
- {
- filePath = Application.dataPath + "/Resources/" + viewer.GetFileLocation();
- }
- else
- {
- filePath = viewer.GetFileLocation();
- }
- if (fileSourceType != PDFViewer.FileSourceType.Web)
- {
- if (!File.Exists(filePath))
- {
- if (fileSourceType == PDFViewer.FileSourceType.Resources &&
- File.Exists(filePath + ".bytes"))
- {
- ShowInExplorer(filePath + ".bytes");
- }
- else
- {
- EditorUtility.DisplayDialog("Error",
- "The file path is badly formed, contains invalid characters or doesn't exists:\r\n\r\n" +
- filePath, "Ok");
- }
- }
- else
- {
- ShowInExplorer(filePath);
- }
- }
- else
- {
- try
- {
- System.Diagnostics.Process.Start(filePath);
- }
- catch
- {
- EditorUtility.DisplayDialog("Error",
- "The URL is badly formed or contains invalid characters:\r\n\r\n" + filePath, "Ok");
- }
- }
- }
- }
- EditorGUILayout.EndHorizontal();
- }
- #endif
- }
- if (fileSourceType == PDFViewer.FileSourceType.Bytes)
- {
- EditorGUI.indentLevel++;
- GameObject oldObject = (GameObject)m_BytesSupplierObject.objectReferenceValue;
- EditorGUILayout.PropertyField(m_BytesSupplierObject, new GUIContent("Supplier Object"));
- int selectedIndex = 0;
- if (m_BytesSupplierObject.objectReferenceValue != null)
- {
- try
- {
- List<BytesSupplierInfo> possibleSuppliers = new List<BytesSupplierInfo>();
- possibleSuppliers.Add(new BytesSupplierInfo(null, null, ""));
- Component[] components = ((GameObject)m_BytesSupplierObject.objectReferenceValue).GetComponents(typeof(Component));
- foreach (Component component in components)
- {
- Type type = component.GetType();
- MethodInfo[] methods = type.GetMethods();
- if (methods.Length == 0)
- continue;
- foreach (MethodInfo method in methods)
- {
- if ((method.GetParameters() == null || method.GetParameters().Length == 0)
- && method.ReturnType == typeof(byte[]))
- {
- possibleSuppliers.Add(new BytesSupplierInfo(m_BytesSupplierObject.objectReferenceValue as GameObject, component,
- method.Name));
- if (oldObject == m_BytesSupplierObject.objectReferenceValue
- && method.Name == m_BytesSupplierFunctionName.stringValue
- && component == m_BytesSupplierComponent.objectReferenceValue)
- {
- selectedIndex = possibleSuppliers.Count - 1;
- }
- }
- }
- }
- string[] supplierTitles = new string[possibleSuppliers.Count];
- for (int i = 0; i < supplierTitles.Length; ++i)
- {
- if (i == 0)
- {
- supplierTitles[0] = "No Function";
- continue;
- }
- supplierTitles[i] = possibleSuppliers[i].m_Behaviour.name + "." +
- possibleSuppliers[i].m_MethodName;
- }
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PrefixLabel("Supplier Function");
- var choiceIndex = EditorGUILayout.Popup(selectedIndex, supplierTitles);
- if (choiceIndex == 0)
- {
- m_BytesSupplierComponent.objectReferenceValue = null;
- m_BytesSupplierFunctionName.stringValue = "";
- }
- else
- {
- m_BytesSupplierComponent.objectReferenceValue = possibleSuppliers[choiceIndex].m_Behaviour;
- m_BytesSupplierFunctionName.stringValue = possibleSuppliers[choiceIndex].m_MethodName;
- }
- EditorGUILayout.EndHorizontal();
- }
- catch (Exception)
- {
- m_BytesSupplierComponent.objectReferenceValue = null;
- m_BytesSupplierFunctionName.stringValue = "";
- }
- }
- EditorGUI.indentLevel--;
- }
- if (fileSourceType == PDFViewer.FileSourceType.Asset)
- {
- EditorGUILayout.PropertyField(m_PDFAsset);
- }
- EditorGUILayout.PropertyField(m_LoadOnEnable);
- EditorGUILayout.PropertyField(m_UnloadOnDisable);
- if (fileSourceType == PDFViewer.FileSourceType.Asset)
- {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PrefixLabel("");
- EditorGUILayout.HelpBox("To convert pdf file to .asset right click on pdf and select \"PDF Renderer\\Convert to .asset\"", MessageType.Info);
- EditorGUILayout.EndHorizontal();
- }
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- private void InspectSecuritySettings()
- {
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Security Settings", "Paroxe.PdfRenderer.PDFViewer.ShowPasswordSettings"))
- {
- EditorGUILayout.PropertyField(m_Password);
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- private void InspectViewerSettings()
- {
- PDFViewer viewer = (PDFViewer)target;
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Viewer Settings", "Paroxe.PdfRenderer.PDFViewer.ShowViewerSettings"))
- {
- EditorGUILayout.PropertyField(m_PageFitting);
- PDFViewer.PageFittingType pageFitting = (PDFViewer.PageFittingType)m_PageFitting.enumValueIndex;
- if (pageFitting == PDFViewer.PageFittingType.Zoom || Application.isPlaying)
- {
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(m_ZoomFactor, GUILayout.ExpandWidth(false));
- EditorGUI.indentLevel--;
- }
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.PropertyField(m_VerticalMarginBetweenPages, new GUIContent("Page Margins (px)"), GUILayout.ExpandWidth(false));
- if (EditorGUI.EndChangeCheck())
- {
- if (m_VerticalMarginBetweenPages.floatValue < 0.0f)
- m_VerticalMarginBetweenPages.floatValue = 0.0f;
- }
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.PropertyField(m_MinZoomFactor, GUILayout.ExpandWidth(false));
- if (EditorGUI.EndChangeCheck())
- {
- if (m_MinZoomFactor.floatValue < 0.01f)
- m_MinZoomFactor.floatValue = 0.01f;
- }
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.PropertyField(m_MaxZoomFactor, GUILayout.ExpandWidth(false));
- if (EditorGUI.EndChangeCheck())
- {
- if (m_MaxZoomFactor.floatValue < m_MinZoomFactor.floatValue)
- m_MaxZoomFactor.floatValue = m_MinZoomFactor.floatValue;
- }
- EditorGUILayout.PropertyField(m_ZoomStep, GUILayout.ExpandWidth(false));
- EditorGUILayout.PropertyField(m_ScrollSensitivity, new GUIContent("Scroll Sensitivity (px)"), GUILayout.ExpandWidth(false));
- Rect controlRect = EditorGUILayout.GetControlRect(true);
- GUIContent guiLabel = new GUIContent("Show Top Bar");
- using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowTopBar))
- {
- bool showTopBar = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowTopBar);
- if (showTopBar != viewer.ShowTopBar)
- {
- Undo.SetCurrentGroupName("PDFViewer.ShowTopBar");
- int group = Undo.GetCurrentGroup();
- Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.ShowTopBar");
- viewer.ShowTopBar = showTopBar;
- Undo.CollapseUndoOperations(group);
- m_ShowTopBar.boolValue = viewer.ShowTopBar;
- }
- }
- controlRect = EditorGUILayout.GetControlRect(true);
- guiLabel = new GUIContent("Show VScrollBar");
- using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowVerticalScrollBar))
- {
- bool showVerticalScrollBar = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowVerticalScrollBar);
- if (showVerticalScrollBar != viewer.ShowVerticalScrollBar)
- {
- Undo.SetCurrentGroupName("PDFViewer.VScrollBar");
- int group = Undo.GetCurrentGroup();
- Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.VScrollBar");
- viewer.ShowVerticalScrollBar = showVerticalScrollBar;
- Undo.CollapseUndoOperations(group);
- m_ShowVerticalScrollBar.boolValue = viewer.ShowVerticalScrollBar;
- }
- }
- controlRect = EditorGUILayout.GetControlRect(true);
- guiLabel = new GUIContent("Show HScrollBar");
- using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowHorizontalScrollBar))
- {
- bool showHorizontalScrollBar = EditorGUI.Toggle(controlRect, "Show HScrollBar", viewer.ShowHorizontalScrollBar);
- if (showHorizontalScrollBar != viewer.ShowHorizontalScrollBar)
- {
- Undo.SetCurrentGroupName("PDFViewer.HScrollBar");
- int group = Undo.GetCurrentGroup();
- Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.HScrollBar");
- viewer.ShowHorizontalScrollBar = showHorizontalScrollBar;
- Undo.CollapseUndoOperations(group);
- m_ShowHorizontalScrollBar.boolValue = viewer.ShowHorizontalScrollBar;
- }
- }
- if (viewer.m_Internal.LeftPanel != null)
- {
- controlRect = EditorGUILayout.GetControlRect(true);
- guiLabel = new GUIContent("Show Bookmarks Viewer");
- using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowBookmarksViewer))
- {
- bool showBookmarksViewer = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowBookmarksViewer);
- if (showBookmarksViewer != viewer.ShowBookmarksViewer)
- {
- Undo.SetCurrentGroupName("PDFViewer.ShowBookmarksViewer");
- int group = Undo.GetCurrentGroup();
- Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.ShowBookmarksViewer");
- viewer.ShowBookmarksViewer = showBookmarksViewer;
- Undo.CollapseUndoOperations(group);
- m_ShowBookmarksViewer.boolValue = viewer.ShowBookmarksViewer;
- }
- }
- controlRect = EditorGUILayout.GetControlRect(true);
- guiLabel = new GUIContent("Show Thumbnails Viewer");
- using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_ShowThumbnailsViewer))
- {
- bool showThumbnailsViewer = EditorGUI.Toggle(controlRect, guiLabel, viewer.ShowThumbnailsViewer);
- if (showThumbnailsViewer != viewer.ShowThumbnailsViewer)
- {
- Undo.SetCurrentGroupName("PDFViewer.ShowThumbnailsViewer");
- int group = Undo.GetCurrentGroup();
- Undo.RegisterFullObjectHierarchyUndo(viewer.m_Internal, "PDFViewer.ShowThumbnailsViewer");
- viewer.ShowThumbnailsViewer = showThumbnailsViewer;
- Undo.CollapseUndoOperations(group);
- m_ShowThumbnailsViewer.boolValue = viewer.ShowThumbnailsViewer;
- }
- }
- }
- Color oldColor = viewer.BackgroundColor;
- Color newColor = EditorGUILayout.ColorField("Viewer BG Color", viewer.BackgroundColor);
- if (oldColor != newColor)
- {
- Undo.RecordObject(viewer.m_Internal.Viewport.GetComponent<Image>(), "PDFViewerBackground");
- viewer.BackgroundColor = newColor;
- }
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- private void InspectLinksSettings()
- {
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Links Settings", "Paroxe.PdfRenderer.PDFViewer.ShowLinksSettings"))
- {
- EditorGUILayout.PropertyField(m_ChangeCursorWhenOverURL, new GUIContent("Change Cursor"));
- EditorGUILayout.PropertyField(m_AllowOpenURL, new GUIContent("Allow Open URL"));
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- private void InspectSearchSettings()
- {
- PDFViewer viewer = (PDFViewer)target;
- if (viewer.m_Internal.SearchPanel != null)
- {
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Search Settings", "Paroxe.PdfRenderer.PDFViewer.ShowSearchSettings"))
- {
- EditorGUILayout.PropertyField(m_SearchResultColor, new GUIContent("Result Color"));
- EditorGUILayout.PropertyField(m_SearchResultPadding, new GUIContent("Result Padding"));
- EditorGUILayout.PropertyField(m_SearchTimeBudgetPerFrame, new GUIContent("Time (% per frame)"));
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- }
- private void InspectOtherSettings()
- {
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Other Settings", "Paroxe.PdfRenderer.PDFViewer.ShowOtherSettings"))
- {
- EditorGUILayout.PropertyField(m_ParagraphZoomingEnable, new GUIContent("Paragraph Zooming"), GUILayout.ExpandWidth(false));
- if (m_ParagraphZoomingEnable.boolValue)
- {
- EditorGUILayout.PropertyField(m_ParagraphZoomFactor, new GUIContent(" Zoom Factor"), GUILayout.ExpandWidth(false));
- EditorGUILayout.PropertyField(m_ParagraphDetectionThreshold, new GUIContent(" Detection Threshold (px)"), GUILayout.ExpandWidth(false));
- }
- EditorGUILayout.PropertyField(m_PageTileTexture);
- EditorGUILayout.PropertyField(m_PageColor);
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- private void InspectRenderingSettings()
- {
- PDFViewer viewer = (PDFViewer)target;
- GUILayout.BeginVertical("Box");
- if (EnterGroup("Rendering Settings", "Paroxe.PdfRenderer.PDFViewer.ShowRenderSettings"))
- {
- Rect controlRect = EditorGUILayout.GetControlRect(true);
- GUIContent guiLabel = new GUIContent("Maximum Quality");
- using (new EditorGUI.PropertyScope(controlRect, guiLabel, m_MaxZoomFactorTextureQuality))
- {
- float maxRenderingQuality = EditorGUI.FloatField(controlRect, guiLabel, viewer.MaxZoomFactorTextureQuality);
- if (maxRenderingQuality != viewer.MaxZoomFactorTextureQuality)
- {
- viewer.MaxZoomFactorTextureQuality = maxRenderingQuality;
- m_MaxZoomFactorTextureQuality.floatValue = viewer.MaxZoomFactorTextureQuality;
- }
- }
- EditorGUILayout.PropertyField(m_RenderAnnotations, new GUIContent("Render Annotations"), GUILayout.ExpandWidth(false));
- EditorGUILayout.PropertyField(m_RenderGrayscale, new GUIContent("Render Grayscale"), GUILayout.ExpandWidth(false));
- GUILayout.Space(4.0f);
- }
- GUILayout.EndVertical();
- }
- private static bool EnterGroup(string title, string key)
- {
- bool enterGroup = EditorPrefs.GetBool(key, true);
- if (enterGroup != PRHelper.GroupHeader(title, enterGroup))
- {
- enterGroup = !enterGroup;
- EditorPrefs.SetBool(key, enterGroup);
- }
- return enterGroup;
- }
- private static void ShowInExplorer(string filePath)
- {
- filePath = Path.GetFullPath(filePath.Replace(@"/", @"\"));
- if (File.Exists(filePath))
- System.Diagnostics.Process.Start("explorer.exe", "/select," + filePath);
- }
- 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)
- {
- bool result = false;
- string path = EditorUtility.OpenFilePanel("Browse video file", startPath, "*");
- if (!string.IsNullOrEmpty(path) && !path.EndsWith(".meta"))
- {
- string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
- projectRoot = projectRoot.Replace('\\', '/');
- if (path.StartsWith(projectRoot))
- {
- if (path.StartsWith(Application.streamingAssetsPath))
- {
- path = path.Remove(0, Application.streamingAssetsPath.Length);
- filename = Path.GetFileName(path);
- path = Path.GetDirectoryName(path);
- if (path.StartsWith(Path.DirectorySeparatorChar.ToString()) || path.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
- {
- path = path.Remove(0, 1);
- }
- folder = path;
- isPersistentData = false;
- isStreamingAsset = true;
- isResourcesAsset = false;
- isFilePath = false;
- }
- else if (path.StartsWith(Application.persistentDataPath))
- {
- path = path.Remove(0, Application.persistentDataPath.Length);
- filename = Path.GetFileName(path);
- path = Path.GetDirectoryName(path);
- if (path.StartsWith(Path.DirectorySeparatorChar.ToString()) || path.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
- {
- path = path.Remove(0, 1);
- }
- folder = path;
- isPersistentData = true;
- isStreamingAsset = false;
- isResourcesAsset = false;
- isFilePath = false;
- }
- else if (path.StartsWith(Application.dataPath + "/Resources"))
- {
- path = path.Remove(0, (Application.dataPath + "/Resources").Length);
- filename = Path.GetFileName(path);
- path = Path.GetDirectoryName(path);
- if (path.StartsWith(Path.DirectorySeparatorChar.ToString()) || path.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
- {
- path = path.Remove(0, 1);
- }
- folder = path;
- isPersistentData = false;
- isStreamingAsset = false;
- isResourcesAsset = true;
- isFilePath = false;
- }
- else
- {
- path = path.Remove(0, projectRoot.Length + 1);
- filePath = path;
- isPersistentData = false;
- isStreamingAsset = false;
- isResourcesAsset = false;
- isFilePath = true;
- }
- }
- else
- {
- filePath = path;
- isPersistentData = false;
- isStreamingAsset = false;
- isResourcesAsset = false;
- isFilePath = true;
- }
- result = true;
- }
- return result;
- }
- private Texture2D MakeTex(int width, int height, Color col)
- {
- Color[] pix = new Color[width * height];
- for (int i = 0; i < pix.Length; i++)
- {
- pix[i] = col;
- }
- Texture2D result = new Texture2D(width, height);
- result.hideFlags = HideFlags.HideAndDontSave;
- result.SetPixels(pix);
- result.Apply();
- return result;
- }
- private class BytesSupplierInfo
- {
- public Component m_Behaviour;
- public GameObject m_GameObject;
- public string m_MethodName;
- public BytesSupplierInfo(GameObject gameObject, Component component, string methodName)
- {
- m_GameObject = gameObject;
- m_Behaviour = component;
- m_MethodName = methodName;
- }
- }
- }
- }
|