Ejemplo n.º 1
0
    public static void Process()
    {
        string[] selections = Selection.assetGUIDs;

        string outpath = System.IO.Path.Combine(Application.dataPath, "_out");

        Directory.CreateDirectory(outpath);

        foreach (string selection in selections)
        {
            string uuid = selection;
            Directory.CreateDirectory(Path.Combine(outpath, uuid));

            string selectPath = AssetDatabase.GUIDToAssetPath(selection);

            string mfPath = string.Format("Assets/_out/{0}/_manifest.asset", uuid);
            ABPack pack   = ScriptableObject.CreateInstance <ABPack>();
            pack.uuid = uuid;
            pack.path = "";
            AssetDatabase.CreateAsset(pack, mfPath);

            string filePath = string.Format("Assets/_out/{0}/{1}", uuid, Path.GetFileName(selectPath));
            AssetDatabase.MoveAsset(selectPath, filePath);
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Ejemplo n.º 2
0
    public static void New()
    {
        string[] selection = Selection.assetGUIDs;
        if (selection.Length > 1)
        {
            return;
        }

        string selectPath = AssetDatabase.GUIDToAssetPath(selection[0]);

        string uuid  = System.Guid.NewGuid().ToString().Replace("-", "");
        string group = selectPath.Replace("Assets/Packages/", "");

        Directory.CreateDirectory(Path.Combine(selectPath, uuid));

        ABPack pack = ScriptableObject.CreateInstance <ABPack>();

        pack.uuid = uuid;
        pack.path = group;
        string mfPath = string.Format("Assets/Packages/{0}/{1}/_manifest.asset", group, uuid);

        AssetDatabase.CreateAsset(pack, mfPath);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Ejemplo n.º 3
0
    private static void exportManifests()
    {
        string path = System.IO.Path.Combine(Application.dataPath, "Packages");

        DirectoryInfo test = new DirectoryInfo(path);

        if (test.Exists)
        {
            foreach (string group in Directory.GetDirectories(path))
            {
                string groupname = Path.GetFileName(group);
                foreach (string package in Directory.GetDirectories(group))
                {
                    string packagename = Path.GetFileName(package);

                    foreach (string file in Directory.GetFiles(package))
                    {
                        string filename = Path.GetFileName(file);

                        if (!Path.GetFileName(file).Equals("_manifest.asset"))
                        {
                            continue;
                        }

                        string mfPath = string.Format("Assets/Packages/{0}/{1}/{2}", groupname, packagename, filename);
                        ABPack pack   = AssetDatabase.LoadAssetAtPath <ABPack>(mfPath);
                        if (null == pack)
                        {
                            continue;
                        }

                        string outPath = Path.Combine(outpath_manifest, packagename + ".mf");
                        string json    = JsonUtility.ToJson(pack, true);
                        File.WriteAllText(outPath, json);
                        Debug.Log(string.Format("Write {0}.mf to {1}", packagename, outPath));
                    }
                }
            }
        }
        else
        {
            Debug.Log("Without this directory...");
        }
    }
Ejemplo n.º 4
0
    private static void refresh()
    {
        string path = System.IO.Path.Combine(Application.dataPath, "Packages");

        DirectoryInfo test = new DirectoryInfo(path);

        if (test.Exists)
        {
            foreach (string group in Directory.GetDirectories(path))
            {
                string groupname = Path.GetFileName(group);

                foreach (string package in Directory.GetDirectories(group))
                {
                    string packagename = Path.GetFileName(package);

                    List <string> files = new List <string>();
                    ABPack        pack  = null;

                    string mfPath  = Path.Combine(package, "_manifest.asset");
                    string mfAsset = string.Format("Assets/Packages/{0}/{1}/_manifest.asset", groupname, packagename);
                    if (!File.Exists(mfPath))
                    {
                        pack      = ScriptableObject.CreateInstance <ABPack>();
                        pack.uuid = packagename;
                        pack.path = groupname;
                        AssetDatabase.CreateAsset(pack, mfAsset);
                    }
                    else
                    {
                        pack      = AssetDatabase.LoadAssetAtPath <ABPack>(mfAsset);
                        pack.uuid = packagename;
                        pack.path = groupname;
                    }

                    foreach (string file in Directory.GetFiles(package))
                    {
                        string filename = Path.GetFileName(file);

                        //ignore unity's meta file
                        if (file.EndsWith(".meta"))
                        {
                            continue;
                        }

                        if (Path.GetFileName(file).Equals("_manifest.asset"))
                        {
                            continue;
                        }

                        string assetPath = string.Format("Assets/Packages/{0}/{1}/{2}", groupname, packagename, filename);
                        AssetImporter.GetAtPath(assetPath).SetAssetBundleNameAndVariant(packagename, "");
                        files.Add(Path.GetFileName(file));
                    }

                    if (null == pack)
                    {
                        continue;
                    }

                    Dictionary <string, ABFile> abFiles = new Dictionary <string, ABFile>();
                    foreach (ABFile abFile in pack.files)
                    {
                        abFiles.Add(abFile.name, abFile);
                    }
                    pack.files.Clear();

                    foreach (string file in files)
                    {
                        ABFile abFile = new ABFile();
                        abFile.name = Path.GetFileNameWithoutExtension(file);
                        abFile.code = ToUUID(string.Format("{0}.{1}", packagename, abFile.name));
                        if (abFiles.ContainsKey(abFile.name))
                        {
                            abFile.alias = abFiles[abFile.name].alias;
                        }
                        pack.files.Add(abFile);
                    }
                }
            }
        }
        else
        {
            Debug.Log("Without this directory...");
        }

        AssetDatabase.RemoveUnusedAssetBundleNames();
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        Debug.Log("refresh finish");
    }