示例#1
0
        private static void CompressBundleImpl(string unity3DFilePath, bool randomizeCab)
        {
            using (var parser = Plugins.OpenUnity3d(unity3DFilePath))
                using (var editor = new Unity3dEditor(parser, false))
                {
                    // GetAssetNames does more than the name suggests, needs to stay
                    var _ = editor.GetAssetNames(true);

                    if (randomizeCab)
                    {
                        if (parser.FileInfos != null && parser.FileInfos.Count > 1)
                        {
                            Console.WriteLine("Could not randomize CAB string because the bundle contains multiple cabinets. Path: " + unity3DFilePath);
                        }
                        else
                        {
                            var rnbuf = new byte[16];
                            rng.GetBytes(rnbuf);
                            var newCab = "CAB-" + string.Concat(rnbuf.Select((x) => ((int)x).ToString("X2")).ToArray()).ToLower();
                            editor.RenameCabinet(0, newCab);
                        }
                    }

                    editor.SaveUnity3d(false, ".unit-y3d", false, true, -1, 2, 262144);
                }
        }
示例#2
0
 public static void OpenUnity3dEditor()
 {
     if (e == null)
     {
         e = EditorWindow.GetWindow <Unity3dEditor>("Unity3dEditor");
     }
     e.Show();
 }
示例#3
0
    public static void copyAsset()
    {
        string guid = Selection.assetGUIDs[0];

        Debug.Log("guid=" + guid);
        AssetBundle ab = Unity3dEditor.GetAB(guid);

        if (ab == null)
        {
            Debug.Log("No AB");
            return;
        }

        Object[] os = ab.LoadAllAssets();
        foreach (Object go in os)
        {
            Debug.Log(go);
            Debug.Log(go.name + " is " + go.GetType());
            if (go is GameObject)
            {
                GameObject m = GameObject.Instantiate(go, null) as GameObject;
                m.name += "_x";
                PrefabUtility.CreatePrefab("Assets/00/" + m.name + ".prefab", m);
            }
            else if (go is Material)
            {
                Material m = new Material(go as Material);
                m.name += "_x";
                AssetDatabase.CreateAsset(m, "Assets/" + m.name + ".mat");
            }
            else if (go is AnimationClip)
            {
                AnimationClip m = Object.Instantiate(go) as AnimationClip;
                m.name += "_x";
                AssetDatabase.AddObjectToAsset(m, "Assets/" + m.name + ".anim");
            }
            else if (go is TextAsset)
            {
                TextAsset m = Object.Instantiate(go) as TextAsset;
                m.name += "_x";
                AssetDatabase.CreateAsset(m, "Assets/" + m.name + ".txt");
            }
        }
    }
示例#4
0
        private static void CompressBundleImpl(string unity3DFilePath, bool randomizeCab)
        {
            using (var parser = Plugins.OpenUnity3d(unity3DFilePath))
                using (var editor = new Unity3dEditor(parser, false))
                {
                    // GetAssetNames does more than the name suggests, needs to stay
                    var _ = editor.GetAssetNames(true);

                    if (randomizeCab)
                    {
                        var rnbuf = new byte[16];
                        rng.GetBytes(rnbuf);
                        var newCab = "CAB-" + string.Concat(rnbuf.Select((x) => ((int)x).ToString("X2")).ToArray()).ToLower();
                        editor.RenameCabinet(0, newCab);
                    }

                    editor.SaveUnity3d(false, ".unit-y3d", false, true, -1, 2, 262144);
                }
        }
示例#5
0
        private static int HashFileContentsImpl(string unity3DFilePath)
        {
            using (var parser = Plugins.OpenUnity3d(unity3DFilePath))
                using (var editor = new Unity3dEditor(parser, false))
                {
                    var sbResult = new StringBuilder();
                    var names    = editor.GetAssetNames(false);
                    for (var i = 0; i < names.Length; i++)
                    {
                        var asset = editor.Parser.Cabinet.Components[i];
                        sbResult.AppendFormat(CultureInfo.InvariantCulture, "{0}\0{1}\0{2}\0{3}\n", asset.pathID, asset.classID1, asset.classID2, names[i]);
                        //Console.WriteLine("PathID=" + asset.pathID.ToString("D") + " id1=" + (int)asset.classID1 + "/" + asset.classID1 + " id2=" + asset.classID2 + " " + names[i]);
                        if (asset is NotLoaded notLoaded)
                        {
                            sbResult.AppendFormat(CultureInfo.InvariantCulture, "{0}\0{1}\n", notLoaded.offset, notLoaded.size);
                        }
                    }

                    return(GetStableHashCode(sbResult));
                }
        }