Exemplo n.º 1
0
        public static void BundleTreeItem_ChangesBundleName_AfterRename()
        {
            string bundle1Name = "bundle1";
            string bundle2Name = "bundle2";

            BundleInfo     b        = new BundleDataInfo(bundle1Name, ABModelUtil.Root);
            BundleTreeItem treeItem = new BundleTreeItem(b, 0, ABModelUtil.FakeTexture2D);

            Model.HandleBundleRename(treeItem, bundle2Name);
            Assert.AreEqual(bundle2Name, treeItem.bundle.m_Name.bundleName);
        }
Exemplo n.º 2
0
    public void HandleBundleReparent_MovesBundleDataInfoBundles_ToTheCorrectParent()
    {
        BundleDataInfo           dataInfo       = new BundleDataInfo("bundle1", ABModelUtil.Root);
        BundleFolderConcreteInfo concreteFolder = new BundleFolderConcreteInfo("folder1", ABModelUtil.Root);

        ABModelUtil.Root.AddChild(dataInfo);
        ABModelUtil.Root.AddChild(concreteFolder);

        Model.HandleBundleReparent(new BundleInfo[] { dataInfo }, concreteFolder);

        Assert.AreEqual(dataInfo.parent.m_Name.bundleName, concreteFolder.m_Name.bundleName);
    }
Exemplo n.º 3
0
    public static void GetDirectory(string path)
    {
        DirectoryInfo folder = new DirectoryInfo(path);

        if (folder != null)
        {
            //Recurse child folder
            foreach (var childFolder in folder.GetDirectories())
            {
                GetDirectory(childFolder.FullName);
            }

            //Set BundleInfo for every file
            foreach (var file in folder.GetFileSystemInfos())
            {
                if (file is DirectoryInfo ||
                    file.Name.EndsWith(".meta") ||
                    file.Name.EndsWith(".lua") ||
                    file.Name.EndsWith(".json") ||
                    file.Name.EndsWith(".cs"))
                {
                    continue;
                }
#if UNITY_EDITOR_WIN
                string assetPath = @"Assets" + file.FullName.Replace(Application.dataPath.Replace("/", "\\"), "").Replace("\\", "/");
#else
                string assetPath = @"Assets" + file.FullName.Replace(Application.dataPath, "");
#endif
                //set GUID as BundleName
                string        GUID = AssetDatabase.AssetPathToGUID(assetPath);
                AssetImporter ai   = AssetImporter.GetAtPath(assetPath);
                ai.assetBundleName = GUID;

                if (!bundleDataMap.ContainsKey(GUID))
                {
                    BundleDataInfo info = new BundleDataInfo(GUID, assetPath.Replace("Assets/ResourcesAssets/", ""));
                    bundleDataMap.Add(info.bundlePath, info);
                }

                //Get Dependency
                string[] dps = AssetDatabase.GetDependencies(assetPath);
                foreach (var dpPath in dps)
                {
                    if (dpPath == assetPath || dpPath.EndsWith(".cs"))
                    {
                        continue;
                    }
                    AddRefCount(AssetDatabase.AssetPathToGUID(dpPath), dpPath);
                }
            }
        }
    }
Exemplo n.º 4
0
    public void HandleBundleRename_RenamesTo_CorrectAssetBundleName()
    {
        string bundleDataInfoName    = "bundledatainfo";
        string newBundleDataInfoName = "newbundledatainfo";

        BundleDataInfo dataInfo = new BundleDataInfo(bundleDataInfoName, ABModelUtil.Root);
        BundleTreeItem treeItem = new BundleTreeItem(dataInfo, 0, ABModelUtil.FakeTexture2D);

        bool handleBundle = Model.HandleBundleRename(treeItem, newBundleDataInfoName);

        Assert.IsTrue(handleBundle);
        Assert.AreEqual(treeItem.bundle.m_Name.bundleName, newBundleDataInfoName);
    }
Exemplo n.º 5
0
    public void HandleBundleReparent_MovesBundle_IntoCorrectVariantFolder()
    {
        string variantFolderName = "variantfolder";
        string bundleName        = "bundle1";

        BundleVariantFolderInfo bundleVariantFolderRoot = new BundleVariantFolderInfo(variantFolderName, ABModelUtil.Root);
        BundleDataInfo          bundleDataInfo          = new BundleDataInfo(bundleName, ABModelUtil.Root);

        ABModelUtil.Root.AddChild(bundleVariantFolderRoot);
        ABModelUtil.Root.AddChild(bundleDataInfo);

        Model.HandleBundleReparent(new BundleInfo[] { bundleDataInfo }, bundleVariantFolderRoot);

        Assert.AreEqual(variantFolderName + "/" + bundleName, bundleDataInfo.m_Name.bundleName);
    }
Exemplo n.º 6
0
    public static void BuildAssetBundle(BuildTarget target)
    {
        //set bundlename for asset which is refed more than once
        foreach (var pair in assetsRefCountMap)
        {
            if (pair.Value > 1)
            {
                string        path = assetsPathMap[pair.Key];
                AssetImporter ai   = AssetImporter.GetAtPath(path);
                ai.assetBundleName = pair.Key;
                if (!bundleDataMap.ContainsKey(pair.Key))
                {
                    BundleDataInfo info = new BundleDataInfo(pair.Key, path.Replace("Assets/ResourcesAssets/", ""));
                    bundleDataMap.Add(info.bundlePath, info);
                }
            }
        }
        AssetDatabase.RemoveUnusedAssetBundleNames();

        //set bundle options
        BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle;
        //set output path
        string outputPath = bundleOutputPath;

        if (target == BuildTarget.StandaloneWindows64)
        {
            outputPath = bundleOutputPath + "/Windows/" + version;
        }
        else if (target == BuildTarget.Android)
        {
            outputPath = bundleOutputPath + "/Android/" + version;
        }
        else if (target == BuildTarget.iOS)
        {
            outputPath = bundleOutputPath + "/IOS/" + version;
        }

        if (!Directory.Exists(outputPath))
        {
            Directory.CreateDirectory(outputPath);
        }
        BuildPipeline.BuildAssetBundles(outputPath, options, target);
        BuildBundleInfoProtoFile(outputPath);
        AssetDatabase.Refresh();
        Debug.Log("AssetBundle Create Finished");
    }
Exemplo n.º 7
0
    public void HandleBundleDelete_Deletes_BundleDataInfo()
    {
        BundleDataInfo bundleDataInfo1 = new BundleDataInfo("bundle1", ABModelUtil.Root);
        BundleDataInfo bundleDataInfo2 = new BundleDataInfo("bundle2", ABModelUtil.Root);
        BundleDataInfo bundleDataInfo3 = new BundleDataInfo("bundle3", ABModelUtil.Root);

        ABModelUtil.Root.AddChild(bundleDataInfo1);
        ABModelUtil.Root.AddChild(bundleDataInfo2);
        ABModelUtil.Root.AddChild(bundleDataInfo3);

        Model.HandleBundleDelete(new BundleInfo[] { bundleDataInfo1, bundleDataInfo2, bundleDataInfo3 });

        FieldInfo numberOfChildrenFieldInfo = typeof(BundleFolderConcreteInfo).GetField("m_Children", BindingFlags.NonPublic | BindingFlags.Instance);
        Dictionary <string, BundleInfo> numberOfConcreteFolderChildren =
            numberOfChildrenFieldInfo.GetValue(ABModelUtil.Root) as Dictionary <string, BundleInfo>;

        Assert.AreEqual(0, numberOfConcreteFolderChildren.Keys.Count);
    }
Exemplo n.º 8
0
    public void AssetBundleName_GetsRenamed_WhenBundleIsRenamed()
    {
        List <string> listOfPrefabs = new List <string>();

        string bundle1Name = "bundle1";
        string bundle2Name = "bundle2";

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, String.Empty));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            BundleInfo b            = new BundleDataInfo(bundle1Name, ABModelUtil.Root);
            BundleTreeItem treeItem = new BundleTreeItem(b, 0, ABModelUtil.FakeTexture2D);

            Model.HandleBundleRename(treeItem, bundle2Name);

            Assert.AreEqual(bundle2Name, AssetImporter.GetAtPath(listOfPrefabs[0]).assetBundleName);
        }, listOfPrefabs);
    }
Exemplo n.º 9
0
    /// <summary>
    /// 创建AssetBundle索引文件,使用protobuf序列化
    /// </summary>
    public static void BuildBundleInfoProtoFile(string outputPath)
    {
        //TODO
        outputPath = outputPath + "/ProtoBundleInfos.dat";
        ProtoBundleInfos protoBundleInfos = new ProtoBundleInfos();

        foreach (var pair in bundleDataMap)
        {
            BundleDataInfo info = pair.Value;
            protoBundleInfos.BundleInfos.Add(new ProtoBundleInfo {
                BundlePath = info.bundlePath,
                AssetPath  = info.assetPath,
                Version    = version,
            });
        }
        //Create File
        using (var output = File.Create(outputPath))
        {
            protoBundleInfos.WriteTo(output);
        }
    }
Exemplo n.º 10
0
    public void BundleFolderInfo_ChildrenTable_UpdatesWhenBundleIsRenamed()
    {
        List <string> listOfPrefabs = new List <string>();

        string bundle1Name = "bundle1";
        string bundle2Name = "bundle2";

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, String.Empty));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            BundleInfo b = new BundleDataInfo(bundle1Name, ABModelUtil.Root);
            ABModelUtil.Root.AddChild(b);
            BundleTreeItem treeItem = new BundleTreeItem(b, 0, ABModelUtil.FakeTexture2D);
            Model.ExecuteAssetMove();

            Assert.AreEqual(bundle1Name, ABModelUtil.Root.GetChildList().ElementAt(0).m_Name.bundleName);
            Model.HandleBundleRename(treeItem, bundle2Name);
            Assert.AreEqual(bundle2Name, ABModelUtil.Root.GetChildList().ElementAt(0).m_Name.bundleName);
        }, listOfPrefabs);
    }
Exemplo n.º 11
0
    public void HandleDedupeBundles_MovesDuplicatedAssets_ToNewBundle()
    {
        string bundle1PrefabInstanceName = "Bundle1Prefab";
        string bundle2PrefabInstanceName = "Bundle2Prefab";

        string bundle1Name = "bundle1";
        string bundle2Name = "bundle2";

        List <string> listOfAssets = new List <string>();

        listOfAssets.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, "", bundle1PrefabInstanceName));
        listOfAssets.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, "", bundle2PrefabInstanceName));

        BundleDataInfo bundle1DataInfo = new BundleDataInfo(bundle1Name, ABModelUtil.Root);
        BundleDataInfo bundle2DataInfo = new BundleDataInfo(bundle2Name, ABModelUtil.Root);

        ABModelUtil.Root.AddChild(bundle1DataInfo);
        ABModelUtil.Root.AddChild(bundle2DataInfo);

        bundle1DataInfo.RefreshAssetList();
        bundle2DataInfo.RefreshAssetList();

        //Need a material with no assigned bundle so it'll be pulled into both bundles
        string   materialPath = "Assets/material.mat";
        Material mat          = new Material(Shader.Find("Diffuse"));

        AssetDatabase.CreateAsset(mat, materialPath);
        listOfAssets.Add(materialPath);
        //

        Model.Refresh();

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            AddMaterialsToMultipleObjects(new string[] { bundle1PrefabInstanceName, bundle2PrefabInstanceName }, listOfAssets, mat);
            Model.HandleDedupeBundles(new BundleInfo[] { bundle1DataInfo, bundle2DataInfo }, false);
            //This checks to make sure that a newbundle was automatically created since we dont' set this up anywhere else.
            Assert.IsTrue(AssetDatabase.GetAllAssetBundleNames().Contains("newbundle"));
        }, listOfAssets);
    }
Exemplo n.º 12
0
        public static void HandleBundleDelete_Deletes_BundleDataInfo()
        {
            // Account for existing asset bundles
            var numChilren = ABModelUtil.Root.GetChildList().Count;

            var bundleDataInfo1 = new BundleDataInfo("bundle1", ABModelUtil.Root);
            var bundleDataInfo2 = new BundleDataInfo("bundle2", ABModelUtil.Root);
            var bundleDataInfo3 = new BundleDataInfo("bundle3", ABModelUtil.Root);

            ABModelUtil.Root.AddChild(bundleDataInfo1);
            ABModelUtil.Root.AddChild(bundleDataInfo2);
            ABModelUtil.Root.AddChild(bundleDataInfo3);

            Model.HandleBundleDelete(new BundleInfo[] { bundleDataInfo1, bundleDataInfo2, bundleDataInfo3 });

            var numberOfChildrenFieldInfo =
                typeof(BundleFolderConcreteInfo).GetField("m_Children", BindingFlags.NonPublic | BindingFlags.Instance);
            var numberOfConcreteFolderChildren =
                numberOfChildrenFieldInfo.GetValue(ABModelUtil.Root) as Dictionary <string, BundleInfo>;

            Assert.AreEqual(numChilren, numberOfConcreteFolderChildren.Keys.Count);
        }
Exemplo n.º 13
0
        public static void HandleBundleDelete_Deletes_AllChildrenOfConcreteFolder()
        {
            var concreteFolder = new BundleFolderConcreteInfo("concreteFolder", ABModelUtil.Root);

            ABModelUtil.Root.AddChild(concreteFolder);

            var bundleDataInfo1 = new BundleDataInfo("bundle1", concreteFolder);
            var bundleDataInfo2 = new BundleDataInfo("bundle2", concreteFolder);
            var bundleDataInfo3 = new BundleDataInfo("bundle3", concreteFolder);

            concreteFolder.AddChild(bundleDataInfo1);
            concreteFolder.AddChild(bundleDataInfo2);
            concreteFolder.AddChild(bundleDataInfo3);

            Model.HandleBundleDelete(new BundleInfo[] { concreteFolder });

            var numberOfChildrenFieldInfo =
                typeof(BundleFolderConcreteInfo).GetField("m_Children", BindingFlags.NonPublic | BindingFlags.Instance);
            var numberOfConcreteFolderChildren =
                numberOfChildrenFieldInfo.GetValue(concreteFolder) as Dictionary <string, BundleInfo>;

            Assert.AreEqual(0, numberOfConcreteFolderChildren.Keys.Count);
        }
Exemplo n.º 14
0
    public void HandleBundleMerge_Merges_BundlesCorrectly()
    {
        // Account for existing bundles
        int numBundles = AssetDatabase.GetAllAssetBundleNames().Length;

        string bundle1Name = "bundle1";
        string bundle2Name = "bundle2";

        BundleDataInfo bundle1DataInfo = Model.CreateEmptyBundle() as BundleDataInfo;

        Model.HandleBundleRename(new BundleTreeItem(bundle1DataInfo, 0, ABModelUtil.FakeTexture2D), bundle1Name);

        BundleDataInfo bundle2DataInfo = Model.CreateEmptyBundle() as BundleDataInfo;

        Model.HandleBundleRename(new BundleTreeItem(bundle2DataInfo, 0, ABModelUtil.FakeTexture2D), bundle2Name);

        List <string> listOfPrefabs = new List <string>();

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            Model.HandleBundleMerge(new BundleInfo[] { bundle2DataInfo }, bundle1DataInfo);

            string[] bundleNames = AssetDatabase.GetAllAssetBundleNames();
            Assert.AreEqual(numBundles + 1, bundleNames.Length);
            Assert.IsTrue(bundleNames.Contains(bundle1Name));

            //Make sure every asset now has bundle1 as the bundle name
            foreach (string prefab in listOfPrefabs)
            {
                Assert.AreEqual(bundle1Name, AssetImporter.GetAtPath(prefab).assetBundleName);
            }
        }, listOfPrefabs);
    }
Exemplo n.º 15
0
    public void HandleBundleMerge_Merges_BundlesWithChildrenCorrectly()
    {
        // Account for existing bundles
        int numBundles = AssetDatabase.GetAllAssetBundleNames().Length;

        string folderName  = "folder";
        string bundle1Name = "bundle1";
        string bundle2Name = folderName + "/bundle2";

        BundleFolderConcreteInfo concrete        = new BundleFolderConcreteInfo(folderName, ABModelUtil.Root);
        BundleDataInfo           bundle1DataInfo = new BundleDataInfo(bundle1Name, ABModelUtil.Root);
        BundleDataInfo           bundle2DataInfo = new BundleDataInfo(bundle2Name, concrete);

        concrete.AddChild(bundle2DataInfo);

        List <string> listOfPrefabs = new List <string>();

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            Model.HandleBundleMerge(new BundleInfo[] { bundle1DataInfo }, bundle2DataInfo);

            string[] bundleNames = AssetDatabase.GetAllAssetBundleNames();
            Assert.AreEqual(numBundles + 1, bundleNames.Length, GetAllElementsAsString(bundleNames));
            Assert.IsTrue(bundleNames.Contains(bundle2Name));

            //Make sure every asset now has bundle1 as the bundle name
            foreach (string prefab in listOfPrefabs)
            {
                Assert.AreEqual(bundle2Name, AssetImporter.GetAtPath(prefab).assetBundleName);
            }
        }, listOfPrefabs);
    }
        internal static TreeViewItem AppendBundleToTree(BundleDataInfo bundle)
        {
            var itemName = bundle.m_Name.fullNativeName;
            var bunRoot  = new TreeViewItem(itemName.GetHashCode(), 0, itemName);

            var str = itemName + k_SizeHeader;
            var sz  = new TreeViewItem(str.GetHashCode(), 1, k_SizeHeader + bundle.TotalSize());

            str = itemName + k_DependencyHeader;
            var dependency = new TreeViewItem(str.GetHashCode(), 1, k_DependencyEmpty);
            var depList    = bundle.GetBundleDependencies();

            if (depList.Count > 0)
            {
                dependency.displayName = k_DependencyHeader + string.Format(" - [ {0} ]", depList.Count);
                foreach (var dep in depList)
                {
                    str = itemName + dep.m_BundleName;
                    TreeViewItem newItem = new TreeViewItem(str.GetHashCode(), 2, dep.m_BundleName);
                    newItem.icon = Model.GetBundleIcon();
                    dependency.AddChild(newItem);

                    var toAssetItems = new Dictionary <string, TogglePathTreeViewItem>();

                    for (int i = 0; i < dep.m_FromAssets.Count; ++i)
                    {
                        TogglePathTreeViewItem item = null;

                        if (!toAssetItems.TryGetValue(dep.m_ToAssets[i].fullAssetName, out item))
                        {
                            str       = itemName + dep.m_BundleName + dep.m_ToAssets[i].displayName;
                            item      = new TogglePathTreeViewItem(str.GetHashCode(), 3, "/" + dep.m_ToAssets[i].displayName, "/" + dep.m_ToAssets[i].fullAssetName);
                            item.icon = AssetDatabase.GetCachedIcon(dep.m_ToAssets[i].fullAssetName) as Texture2D;
                            newItem.AddChild(item);
                            toAssetItems.Add(dep.m_ToAssets[i].fullAssetName, item);
                        }

                        str = str + dep.m_FromAssets[i].displayName;
                        TreeViewItem refItem = new TogglePathTreeViewItem(str.GetHashCode(), 4, k_ReferencedPrefix,
                                                                          dep.m_FromAssets[i].displayName, dep.m_FromAssets[i].fullAssetName);
                        refItem.icon = AssetDatabase.GetCachedIcon(dep.m_FromAssets[i].fullAssetName) as Texture2D;
                        item.AddChild(refItem);
                    }
                }
            }

            str = itemName + k_MessageHeader;
            var msg = new TreeViewItem(str.GetHashCode(), 1, k_MessageEmpty);

            if (bundle.HasMessages())
            {
                msg.displayName = k_MessageHeader;
                var currMessages = bundle.GetMessages();

                foreach (var currMsg in currMessages)
                {
                    str = itemName + currMsg.message;
                    msg.AddChild(new BundleDetailItem(str.GetHashCode(), 2, currMsg.message, currMsg.severity));
                }
            }


            bunRoot.AddChild(sz);
            bunRoot.AddChild(dependency);
            bunRoot.AddChild(msg);

            return(bunRoot);
        }