Пример #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);
                }
            }
        }
    }
Пример #2
0
    public void Shuffle(FileStream stream, Progressor prog)
    {
        int byteCount = pointCount * CloudStream.pointRecSize;
        byte[] wholeThing = new byte[byteCount];

        Progressor subProg = prog.Sub(0f, 0.1f);
        subProg.Progress(0.01f, "Reading into memory...");
        stream.Seek(0, SeekOrigin.Begin);
        stream.Read( wholeThing, 0, byteCount );
        subProg.Progress(1f, "Reading into memory... done");

        byte[] tmp = new byte[CloudStream.pointRecSize];

        subProg = prog.Sub(0.1f, 0.9f);
        ShuffleUtility.WithSwap(pointCount, (i, j) =>
        {
            /*
             * This is the fastest way I found to swap 16-byte long chunks in memory (tried MemoryStream and
             * byte-by-byte swap loop).
             */
            System.Buffer.BlockCopy(wholeThing, i * CloudStream.pointRecSize, tmp, 0, CloudStream.pointRecSize);
            System.Buffer.BlockCopy(wholeThing, j * CloudStream.pointRecSize, wholeThing, i * CloudStream.pointRecSize, CloudStream.pointRecSize);
            System.Buffer.BlockCopy(tmp, 0, wholeThing, j * CloudStream.pointRecSize, CloudStream.pointRecSize);
            // 'i' runs backwards from pointCount-1 to 0
            subProg.Progress((float)(pointCount - i) / pointCount, "Shuffling '{0}' in memory. ETA: {eta}", name);
        });

        subProg = prog.Sub(0.9f, 1f);
        subProg.Progress(0.01f, "Writing to disk...");
        stream.Seek(0, SeekOrigin.Begin);
        stream.Write( wholeThing, 0, byteCount );
        subProg.Progress(1f, "Writing to disk... done");
    }