Exemplo n.º 1
0
    public static void ImportClouds()
    {
        if (EditorUtility.DisplayDialog("Import clouds",
                                        string.Format(
                                        "Folders are setup in Resources/ExplodedPrefs asset\n\n" +
                                        "Incoming: {0}\n" +
                                        "Imported: {1}", Prefs.IncomingPath, Prefs.ImportedPath ),
                                        "Import",
                                        "Cancel")) {

            // get a list of incoming .cloud files
            string[] clouds = Directory.GetFiles(Prefs.IncomingPath, "*.cloud");
            // see if the list isn't empty
            if (clouds.Length == 0) {
                Debug.LogWarning(string.Format("No cloud files at incoming path: {0}", Prefs.IncomingPath));
                return;
            }

            Progressor prog = new Progressor("Importing clouds");

            using(new AssetEditBatch() ) {
                foreach(string cloud_path in prog.Iterate(clouds )) {
                    // derive .prefab / .bin paths from .cloud path
                    string bin_path = Prefs.IncomingBin(cloud_path);
                    string prefab_path = Prefs.ImportedCloudPrefab(cloud_path);

                    // Sanity check: there should be a corresponding .bin next to the cloud
                    if (!File.Exists(bin_path)) {
                        Debug.LogError(string.Format("No .bin file found for '{0}'", cloud_path));
                        continue;
                    }

                    // Safety: don't overwrite prefabs
                    string[] sentinels = { prefab_path, Prefs.ImportedBin(cloud_path), Prefs.ImportedCloud(cloud_path)};
                    bool hitSentinel = false;
                    foreach(string sentinel in sentinels) {
                        if (File.Exists( sentinel )) {
                            Debug.LogWarning(string.Format("'{0}' is in the way when importing '{1}'", sentinel, cloud_path));
                            hitSentinel = true;
                        }
                    }
                    if (hitSentinel)
                        continue;

                    // ready to import
                    CloudImporter importer = new CloudImporter(prog.Sub());
                    importer.ImportCloud(cloud_path, bin_path, prefab_path);
                }
            }
        }
    }