Ejemplo n.º 1
0
    static void CheckFile(string fileName, string filePath, string bundlePath)
    {
        SimpleAssetBundle sab = LoadFromFile(bundlePath);

        if (sab == null)
        {
            Console.WriteLine("Bundle 包不存在");
            return;
        }
        if (sab.isExists(fileName))
        {
            Console.WriteLine("文件存在");
            using (BinaryWriter bw = new BinaryWriter(File.Open(filePath, FileMode.Create)))
            {
                int    len   = sab.FileLength(fileName);
                byte[] bytes = new byte[len];//sab.GetData(fileName);
                sab.Read(fileName, bytes, 0, len);
                bw.Write(bytes);
            }
        }
        else
        {
            Console.WriteLine("文件不存在");
        }
    }
Ejemplo n.º 2
0
        public IEnumerator SceneTest()
        {
            var outputPathScene = Application.streamingAssetsPath + "/InitTestAssetBundle/scene";

            Assert.AreEqual(0, SimpleAssetBundle.GetAllAssetNames(outputPathScene).Length);
            Assert.AreEqual(3, SimpleAssetBundle.GetAllScenePaths(outputPathScene).Length);
            yield return(null);
        }
Ejemplo n.º 3
0
        public static void BuildAssetBundle()
        {
            const string bundleName = "sound1";
            const string assetPath1 = "Assets/UniTool.Sample/SampleSound1.mp3";
            const string assetPath2 = "Assets/UniTool.Sample/SampleSound2.mp3";
            const string outputPath = "Temp/SampleSound";

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            var assets = new SimpleAssets(bundleName, new[] { assetPath1, assetPath2 });

            SimpleAssetBundle.Build(outputPath, new[] { assets });
        }
Ejemplo n.º 4
0
    void TestLoadAsset()
    {
        SimpleAssetBundle sab = LoadFromFile(bundlePath);

        if (sab.isExists(fileName))
        {
            Debug.LogError("文件存在");
            using (BinaryWriter bw = new BinaryWriter(File.Open(filePath, FileMode.Create)))
            {
                int    len   = sab.FileLength(fileName);
                byte[] bytes = new byte[len];
                sab.Read(fileName, bytes, 0, len);
                bw.Write(bytes);
            }
        }
    }
Ejemplo n.º 5
0
    static SimpleAssetBundle LoadBundleAtPath(string bundlePath)
    {
        if (!File.Exists(bundlePath))
        {
            Console.WriteLine("LoadBundleAtPath failed, no such a path");
            return(null);
        }

        FileStream fs = File.OpenRead(bundlePath);

        byte[] headLengthByte = new byte[4];
        fs.Seek(0, SeekOrigin.Begin);
        fs.Read(headLengthByte, 0, 4);

        if (!BitConverter.IsLittleEndian)
        {
            Array.Reverse(headLengthByte);
        }

        int bundleInfoLength = BitConverter.ToInt32(headLengthByte, 0);

        byte[] bundleInfoByte = new byte[bundleInfoLength];
        fs.Seek(4, SeekOrigin.Begin);
        fs.Read(bundleInfoByte, 0, bundleInfoLength);

        SimpleAssetBundle assetBundle = new SimpleAssetBundle();

        assetBundle.contentStream       = fs;
        assetBundle.contentStreamOffset = 4 + bundleInfoLength;

        string bundleInfoStr = Encoding.UTF8.GetString(bundleInfoByte);

        string[] bundleInfos = bundleInfoStr.Split('|');
        foreach (string info in bundleInfos)
        {
            if (!info.Contains(","))
            {
                continue;
            }

            string[]       bundleItemInfo = info.Split(',');
            BundleItemInfo itemInfo       = new BundleItemInfo(Convert.ToUInt32(bundleItemInfo[0]), Convert.ToUInt32(bundleItemInfo[1]), Convert.ToInt32(bundleItemInfo[2]), Convert.ToInt32(bundleItemInfo[3]));
            assetBundle.FileNameLookupMap.Add(itemInfo.fileHashID, itemInfo);
            assetBundle.FullNameLookupMap.Add(itemInfo.pathHashID, itemInfo);
        }
        return(assetBundle);
    }
Ejemplo n.º 6
0
 public static SimpleAssetBundle GetBundleAtPath(string filePath)
 {
     lock (lockObj) {
         if (LoadedBundle.ContainsKey(filePath))
         {
             return(LoadedBundle[filePath]);
         }
         else
         {
             SimpleAssetBundle sab = LoadBundleAtPath(filePath);
             if (sab == null)
             {
                 return(null);
             }
             LoadedBundle.Add(filePath, sab);
             return(sab);
         }
     }
 }
Ejemplo n.º 7
0
        public IEnumerator SoundTest()
        {
            var outputPathSound = Application.streamingAssetsPath + "/InitTestAssetBundle/sound";

            Assert.AreEqual(2, SimpleAssetBundle.GetAllAssetNames(outputPathSound).Length);
            Assert.AreEqual(0, SimpleAssetBundle.GetAllScenePaths(outputPathSound).Length);

            Debug.Log(string.Join(Environment.NewLine, SimpleAssetBundle.GetAllAssetNames(outputPathSound)));

            var audioClip1 = SimpleAssetBundle.Load <AudioClip>(outputPathSound, SimpleAssetBundle.GetAllAssetNames(outputPathSound)[0]);

            yield return(null);

            Assert.AreEqual(1, SimpleAssetBundle.GetRefCount(outputPathSound));
            Assert.AreNotEqual(null, audioClip1);

            var audioClip2 = SimpleAssetBundle.Load <AudioClip>(outputPathSound, SimpleAssetBundle.GetAllAssetNames(outputPathSound)[1]);

            yield return(null);

            Assert.AreEqual(2, SimpleAssetBundle.GetRefCount(outputPathSound));
            Assert.AreNotEqual(null, audioClip2);

            SimpleAssetBundle.Unload(outputPathSound);
            yield return(null);

            Assert.AreEqual(1, SimpleAssetBundle.GetRefCount(outputPathSound));
            Assert.AreNotEqual(null, audioClip1);
            Assert.AreNotEqual(null, audioClip2);

            SimpleAssetBundle.Unload(outputPathSound);
            yield return(null);

            Assert.AreEqual(null, SimpleAssetBundle.GetRefCount(outputPathSound));

            SimpleAssetBundle.Unload(outputPathSound);
            yield return(null);

            Assert.AreEqual(null, SimpleAssetBundle.GetRefCount(outputPathSound));
        }
Ejemplo n.º 8
0
        public void FixTargetTest()
        {
            var actual1 = SimpleAssetBundle.FixTarget(RuntimePlatform.OSXEditor, BuildTarget.NoTarget);

            Assert.AreEqual(BuildTarget.StandaloneOSX, actual1);

            var actual2 = SimpleAssetBundle.FixTarget(RuntimePlatform.WindowsEditor, BuildTarget.NoTarget);

            Assert.AreEqual(BuildTarget.StandaloneWindows, actual2);

            var actual3 = SimpleAssetBundle.FixTarget(RuntimePlatform.LinuxEditor, BuildTarget.NoTarget);

            Assert.AreEqual(BuildTarget.StandaloneLinux64, actual3);

            var actual4 = SimpleAssetBundle.FixTarget(RuntimePlatform.OSXPlayer, BuildTarget.NoTarget);

            Assert.AreEqual(BuildTarget.NoTarget, actual4);

            var actual5 = SimpleAssetBundle.FixTarget(RuntimePlatform.OSXEditor, BuildTarget.Android);

            Assert.AreEqual(BuildTarget.Android, actual5);
        }
Ejemplo n.º 9
0
        private void ReloadBilingualAssets()
        {
            var assets = Bundle.Assets.ToArray();

            ReloadBilingualRowData(assets, a => a.TransPairs);
            Name = Bundle.Name;

            // Take care of Alt.
            AltLoader        = null;
            AltOriginsLoader = null;
            if (assets.Any(a => a.AltPairs?.Any() == true))
            {
                AltLoader = delegate(string[] origins)
                {
                    var alt_assets   = Bundle.Assets.ToArray();
                    var alt_name     = string.Format("Alt TM {0}", Name);
                    var alt_bundle   = new SimpleAssetBundle(alt_assets, alt_name);
                    var alt_instance = new TableController(Renderer.Clone(), alt_bundle);
                    alt_instance.ReloadBilingualRowData(alt_assets, CreateFilteredAltPairsGetter(origins));
                    alt_instance.Name = alt_name;
                    return(alt_instance);
                };

                AltOriginsLoader = delegate()
                {
                    var origins = new HashSet <string>();
                    foreach (var asset in Bundle.Assets)
                    {
                        var origin = asset.Properties.ToList().FindIndex(prop => prop.Key == "origin");
                        if (origin >= 0)
                        {
                            origins.UnionWith(asset.AltPairs.Select(pair => pair[origin]));
                        }
                    }
                    origins.Remove(null); // XXX
                    return(origins.AsEnumerable());
                };
            }
        }
Ejemplo n.º 10
0
    public static SimpleAssetBundle LoadFromFile(string filePath)
    {
        lock (lockObj)
        {
            SimpleAssetBundle ab = null;
            if (LoadedBundles.TryGetValue(filePath, out ab))
            {
                return(ab);
            }

            if (File.Exists(filePath))
            {
                ab = SimpleAssetBundle.GetBundleAtPath(filePath);
                if (ab == null)
                {
                    return(null);
                }
                LoadedBundles.Add(filePath, ab);
                return(ab);
            }
        }
        return(null);
    }
Ejemplo n.º 11
0
        public void BuildTest()
        {
            const string bundleName1 = "scene";
            const string assetPath1  = "Assets/UniTool.Sample/UnitoolScene1.unity";
            const string assetPath2  = "Assets/UniTool.Sample/UnitoolScene2.unity";
            const string assetPath3  = "Assets/UniTool.Sample/UnitoolScene3.unity";

            const string bundleName2 = "sound";
            const string assetPath4  = "Assets/UniTool.Sample/UnitoolSampleSound1.mp3";
            const string assetPath5  = "Assets/UniTool.Sample/UnitoolSampleSound2.mp3";

            const string outputPath = "Assets/StreamingAssets/InitTestAssetBundle";

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            var assets1  = new SimpleAssets(bundleName1, new[] { assetPath1, assetPath2, assetPath3 });
            var assets2  = new SimpleAssets(bundleName2, new[] { assetPath4, assetPath5 });
            var manifest = SimpleAssetBundle.Build(outputPath, new[] { assets1, assets2 });

            Assert.AreEqual("scene", manifest.GetAllAssetBundles()[0]);
            Assert.AreEqual("sound", manifest.GetAllAssetBundles()[1]);
        }
Ejemplo n.º 12
0
 public static void Pack(string path, params string[] filesPath)
 {
     SimpleAssetBundle.GenerateBundle(path, filesPath);
 }