Skip to content

Commit

Permalink
Improves/Fix importer UI
Browse files Browse the repository at this point in the history
  • Loading branch information
AurL committed Dec 21, 2017
1 parent 41ca4d5 commit a7d130a
Showing 1 changed file with 57 additions and 21 deletions.
78 changes: 57 additions & 21 deletions UnityGLTF/Assets/UnityGLTF/Scripts/Sketchfab/SketchfabImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Init()
// Public
public bool _useGLTFMaterial = false;

private string _defaultImportDirectory = "Import";
private string _defaultImportDirectory = "";
private static string _currentSampleName = "Imported";
GLTFEditorImporter _importer;
string _gltfPath = "";
Expand All @@ -32,8 +32,7 @@ static void Init()
bool _isInitialized = false;
GUIStyle _header;
Sketchfab.SketchfabAPI _api;

Vector2 loginSize = new Vector2(603, 450);
Vector2 minimumSize = new Vector2(603, 450);

void setupAPI()
{
Expand All @@ -49,18 +48,16 @@ private void Initialize()
{
SketchfabPlugin.Initialize(); // Load header image
setupAPI();
resizeWindow(loginSize);

_importer = new GLTFEditorImporter(this.Repaint);
_unzippedFiles = new List<string>();
_isInitialized = true;
_unzipDirectory = Application.temporaryCachePath + "/unzip";
_header = new GUIStyle(EditorStyles.boldLabel);
}

void resizeWindow(Vector2 size)
{
this.minSize = size;
_defaultImportDirectory = Application.dataPath + "/Import";

this.minSize = minimumSize;
}

public void displayVersionInfo()
Expand Down Expand Up @@ -149,8 +146,6 @@ private void checkValidity()
{
setupAPI();
}

resizeWindow(loginSize);
}

public void OnDestroy()
Expand Down Expand Up @@ -188,7 +183,11 @@ private void OnGUI()
if (Event.current.type == EventType.DragExited)
{
if(DragAndDrop.paths.Length > 0)
{
_gltfPath = DragAndDrop.paths[0];
string modelfileName = Path.GetFileNameWithoutExtension(_gltfPath);
_projectDirectory = Path.Combine(_defaultImportDirectory, modelfileName);
}
}

showImportUI();
Expand All @@ -210,6 +209,11 @@ private void OnGUI()
showStatus();
}

private string stripProjectDirectory(string directory)
{
return directory.Replace(Application.dataPath, "[PROJECT]");
}

// UI FUNCTIONS
private void showImportUI()
{
Expand All @@ -219,18 +223,24 @@ private void showImportUI()
GUILayout.Label("Import or Drag'n drop glTF asset(gltf, glb, zip supported)", _header);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
if (GUILayout.Button("Import file from disk"))
{
_gltfPath = EditorUtility.OpenFilePanel("Choose glTF to import", Application.dataPath, "*gl*;*zip");
string modeldir = Path.GetFileNameWithoutExtension(_gltfPath);
_projectDirectory = Path.Combine(_defaultImportDirectory, modeldir);
}

GUILayout.Label("Paths");
GUILayout.BeginVertical("Box");
GUILayout.Label("Model to import: " + _gltfPath);
GUILayout.Label("Import directory: " + _projectDirectory);
GUILayout.Label("Import directory: " + stripProjectDirectory(_projectDirectory));

GUILayout.EndVertical();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Import file from disk"))
{
_gltfPath = EditorUtility.OpenFilePanel("Choose glTF to import", Application.dataPath, "glb,gltf,zip");
string modelfileName = Path.GetFileNameWithoutExtension(_gltfPath);
_projectDirectory = Path.Combine(_defaultImportDirectory, modelfileName);
}
if (GUILayout.Button("Change import directory"))
{
changeDirectory();
}
GUILayout.EndHorizontal();
}

private void emptyLines(int nbLines)
Expand All @@ -241,20 +251,46 @@ private void emptyLines(int nbLines)
}
}

private void changeDirectory()
{
_projectDirectory = EditorUtility.OpenFolderPanel("Choose import directory in Project", Application.dataPath, "Assets");

// Discard if selected directory is outside of the project
if (!isDirectoryInProject())
{
Debug.Log("Import directory is outside of project directory. Please select path in Assets/");
_projectDirectory = "";
return;
}
}

private void showOptions()
{
GUILayout.Label("Options", _header);
GUILayout.BeginHorizontal();
GUILayout.Label("Prefab name:");
_currentSampleName = GUILayout.TextField(_currentSampleName, GUILayout.Width(250));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndHorizontal();
}

private bool isDirectoryInProject()
{
return _projectDirectory.Contains(Application.dataPath);
}

private void processImportButton()
{
_projectDirectory = EditorUtility.OpenFolderPanel("Choose import directory in Project", Application.dataPath, "Assets");
Directory.CreateDirectory(_projectDirectory);
if(!isDirectoryInProject())
{
Debug.LogError("Import directory is outside of project directory. Please select path in Assets/");
return;
}

if(!Directory.Exists(_projectDirectory))
{
Directory.CreateDirectory(_projectDirectory);
}

if (Path.GetExtension(_gltfPath) == ".zip")
{
Expand Down

0 comments on commit a7d130a

Please sign in to comment.