Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void OnPreprocessAsset()
- {
- metaData = assetImporter.userData;
- filename = Path.GetFileNameWithoutExtension(assetPath);
- fileWithExt = Path.GetFileName(assetPath);
- assetsFolder = Application.dataPath;
- projectFolder = Directory.GetParent(assetsFolder);
- importFilePath = assetImporter.assetPath;
- fileCurrentTimestamp = WithoutMS(File.GetLastWriteTime(importFilePath));
- if (!EditorApplication.isPlaying)
- {
- if (assetPath.Contains(".xd"))
- {
- if (!metaData.Contains("alreadyImported: true"))
- {
- if (EditorUtility.DisplayDialog("Parse Adobe Xd file to Unity?",
- "Do you want to convert " + fileWithExt + " to Unity scenes?",
- "Convert", "Add file to project as is"))
- {
- CoreImporter();
- }
- }
- else if (metaData.Contains("alreadyImported: true"))
- {
- string dateOf = "dateOfModification: ";
- int from = metaData.IndexOf(dateOf) + dateOf.Length;
- if (metaData.LastIndexOf("~;") > 0) fileLastTimeStamp = WithoutMS(DateTime.Parse(metaData.Substring(from, metaData.LastIndexOf("~;") - from)));
- if (metaData.Contains("reimport: true;"))
- {
- ReimportAsset();
- Selection.activeObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
- }
- else if (fileCurrentTimestamp > fileLastTimeStamp && !metaData.Contains("reimport: true;"))
- {
- if (EditorUtility.DisplayDialog("Reload imported file?",
- "File " + fileWithExt + " has changed. Do you want to reload? All changes made in Unity will be lost.",
- "Reload", "Keep current version"))
- {
- ReimportAsset();
- Selection.activeObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
- }
- }
- }
- }
- }
- else
- Debug.LogWarning("Can't import Xd files in playmode");
- }
- public void ReimportAsset()
- {
- if (Directory.Exists(projectFolder + "/~Temp-" + filename)) Directory.Delete(projectFolder + "/~Temp-" + filename, true);
- if (Directory.Exists("Assets/Resources/[AdobeXd]-" + filename)) Directory.Delete("Assets/Resources/[AdobeXd]-" + filename, true);
- CoreImporter();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement