Advertisement
apieceoffruit

XdFileWrapperInspector

Apr 6th, 2021
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3. using static XdFileReimport;
  4.  
  5. [CustomEditor(typeof(XdFileWrapper))]
  6. public class XdFileWrapperInspector : Editor
  7. {
  8.     public override void OnInspectorGUI()
  9.     {
  10.         XdFileWrapper Target = (XdFileWrapper)target;
  11.         Object targetObject = AssetDatabase.LoadAssetAtPath(Target.fileName, typeof(Object));
  12.         if (Target.fileName != null)
  13.         {
  14.             if(targetObject != null) EditorGUILayout.InspectorTitlebar(false, targetObject);
  15.             GUILayout.Label("AdobeXd file path: " + Target.fileName);
  16.            
  17.             if (Target.CurrentDate > Target.LastImportedDate && Target.imported)
  18.             {
  19.                 EditorGUILayout.HelpBox("File has been updated since last import.", MessageType.Info);
  20.              
  21.             }
  22.             EditorGUILayout.BeginHorizontal();
  23.             if (Target.CurrentDate > Target.LastImportedDate && Target.imported)
  24.             {
  25.                 if (GUILayout.Button("Update", GUILayout.Width(90)))
  26.                 {
  27.                     if (EditorUtility.DisplayDialog("Reload imported file?",
  28.                                   "Do you want to reload? All changes made in Unity will be lost.",
  29.                                   "Reload", "Keep current version"))
  30.                     {
  31.                         Reimport(Target.fileName);
  32.                     }
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 if (Target.imported)
  38.                 {
  39.  
  40.                     if (GUILayout.Button("Reimport", GUILayout.Width(90)))
  41.                     {
  42.                         if (EditorUtility.DisplayDialog("Reload imported file?",
  43.                                       "Do you want to reload? All changes made in Unity will be lost.",
  44.                                       "Reload", "Keep current version"))
  45.                         {
  46.                             Reimport(Target.fileName);
  47.                         }
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     if (GUILayout.Button("Import", GUILayout.Width(80)))
  53.                     {
  54.                         Import(Target.fileName);
  55.  
  56.                     }
  57.                 }  
  58.             }
  59.            
  60.             GUILayout.FlexibleSpace();
  61.             if (GUILayout.Button("Open", GUILayout.Width(60)))
  62.             {
  63.                 AssetDatabase.OpenAsset(targetObject);
  64.  
  65.             }
  66.             EditorGUILayout.EndHorizontal();
  67.         }
  68.        
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement