示例#1
0
        public static void RebuildAll(string path, UABConfig config = null, int version = 0)
        {
            if (config == null)
            {
                config = Builder.GetDefaultConfig(required: true);
            }

            // Clean up all resources
            var resourcesPath = string.Format("Assets/{0}", config.UAB_RESOURCES_PATH);

            if (Directory.Exists(resourcesPath) == false)
            {
                throw new UnityException("Resources path `" + resourcesPath + "` was not found in the project.");
            }

            var files = System.IO.Directory.GetFiles(resourcesPath);

            foreach (var file in files)
            {
                if (file.Contains("/.") == true)
                {
                    continue;
                }

                UnityEditor.AssetDatabase.DeleteAsset(file);
            }

            // Build
            Builder.BuildAll(path, config, version);
        }
示例#2
0
        public static GameObject[] Unpack(byte[] bytes, UABConfig config = null, List <ISerializer> serializers = null)
        {
            var unzipped         = Zipper.UnzipString(bytes);
            var dataDeserialized = UABSerializer.DeserializeValueType <UABPackage>(unzipped);

            return(Builder.Unpack(dataDeserialized, config, serializers));
        }
示例#3
0
        public static byte[] PackToBytes(GameObject[] objects, UABConfig config = null, List <ISerializer> serializers = null)
        {
            var package        = Builder.Pack(objects, config, serializers);
            var dataSerialized = UABSerializer.SerializeValueType(package);
            var zipped         = Zipper.ZipString(dataSerialized);

            return(zipped);
        }
        public void Free()
        {
            this.currentBundleName = null;

            if (this.tempReferencesPack != null)
            {
                this.tempReferencesPack.Clear();
            }
            this.tempReferencesPack = null;

            if (this.tempBinariesPack != null)
            {
                this.tempBinariesPack.Clear();
            }
            this.tempBinariesPack = null;

            this.config = null;
        }
                #pragma warning restore

        public UABPackage Run(GameObject[] objects, UABConfig config = null, List <ISerializer> serializers = null)
        {
            if (config == null)
            {
                config = Builder.GetDefaultConfig(required: true);
            }
            if (serializers == null)
            {
                serializers = Builder.GetAllSerializers(config);
            }

            this.Free();

            this.tempReferencesPack = new List <TempReferencePack>();
            this.tempBinariesPack   = new List <TempBinaryPack>();
            this.config             = config;

            var result = new UABPackage();

            // Pack GameObjects
            {
                result.objects = new UABGameObject[objects.Length];
                for (int i = 0; i < objects.Length; ++i)
                {
                    this.tempReferencesPack.Clear();

                    var obj = objects[i];
                    this.currentBundleName = BundleImporter.GetBundleName(obj);
                    var uGo = this.Pack(obj, serializers);
                    result.objects[i] = uGo;

                    this.BuildReferences(obj.transform);
                }
            }

            this.BuildBinaries(ref result.binaryHeaders, ref result.binaryData, serializers);

            this.Free();
            return(result);
        }
示例#6
0
        public GameObject[] Run(UABPackage package, UABConfig config = null, List <ISerializer> serializers = null)
        {
            if (this.unpackgedGameObjects != null)
            {
                return(this.unpackgedGameObjects);
            }

            if (config == null)
            {
                config = Builder.GetDefaultConfig(required: true);
            }
            if (serializers == null)
            {
                serializers = Builder.GetAllSerializers(config);
            }

            this.Free();

            this.package = package;
            this.tempReferencesUnpack = new Dictionary <int, Object>();

            var gos = new GameObject[package.objects.Length];

            for (int i = 0; i < package.objects.Length; ++i)
            {
                var go = this.Unpack(package.objects[i], serializers);
                go.hideFlags = HideFlags.HideAndDontSave;
                if (Application.isPlaying == true)
                {
                    GameObject.DontDestroyOnLoad(go);
                }
                gos[i] = go;
            }

            this.unpackgedGameObjects = gos;

            this.Free();
            return(gos);
        }
示例#7
0
        public static List <ISerializer> GetAllSerializers(UABConfig config = null)
        {
            if (config == null)
            {
                config = Builder.GetDefaultConfig(required: true);
            }

            if (config == null)
            {
                throw new Exception("UAB.Config file was not found");
            }

            var output = new List <ISerializer>();

            var @namespace = config.UAB_SERIALIZERS_NAMESPACE;
            var query      = from t in System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
                             where t.IsClass == true && t.IsAbstract == false && t.IsNested == false && t.Namespace == @namespace
                             select t.Name.ToLower();

            foreach (var element in query)
            {
                var instance = System.Activator.CreateInstance(null,
                                                               string.Format("{0}.{1}", @namespace, element.ToLower()),
                                                               true,
                                                               System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.CreateInstance,
                                                               null, null, null, null, null);

                if (instance != null)
                {
                    var module = instance.Unwrap() as ISerializer;
                    if (module != null)
                    {
                        output.Add(module);
                    }
                }
            }

            return(output);
        }
示例#8
0
        public static void BuildAll(string path, UABConfig config = null, int version = 0)
        {
            if (config == null)
            {
                config = Builder.GetDefaultConfig(required: true);
            }

            if (System.IO.Directory.Exists(path) == false)
            {
                System.IO.Directory.CreateDirectory(path);
            }

            var buildingAssets = new Dictionary <string, List <GameObject> >();
            var bundles        = UnityEditor.AssetDatabase.GetAllAssetBundleNames();

            for (int i = 0; i < bundles.Length; ++i)
            {
                buildingAssets.Clear();
                var bundle     = bundles[i];
                var assetsPath = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(bundle);
                for (int j = 0; j < assetsPath.Length; ++j)
                {
                    var assetPath = assetsPath[j];
                    var asset     = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
                    if (asset != null && ME.UAB.Extensions.EditorUtilities.IsPrefab(asset) == true)
                    {
                        List <GameObject> list;
                        if (buildingAssets.TryGetValue(bundle, out list) == true)
                        {
                            buildingAssets[bundle].Add(asset);
                        }
                        else
                        {
                            buildingAssets.Add(bundle, new List <GameObject>()
                            {
                                asset
                            });
                        }
                    }
                }

                var assetBuildPath      = string.Format("{0}/{1}.{2}", path, bundle, config.UAB_EXT);
                var assetBuildPathBytes = string.Format("{0}/bytes/{1}.{2}.bytes", path, bundle, config.UAB_EXT);
                foreach (var asset in buildingAssets)
                {
                    var assets = asset.Value.ToArray();

                    var zipped = Builder.PackToBytes(assets, config);

                    {
                        var dir = System.IO.Path.GetDirectoryName(assetBuildPath);
                        if (System.IO.Directory.Exists(dir) == false)
                        {
                            System.IO.Directory.CreateDirectory(dir);
                        }
                        System.IO.File.WriteAllBytes(assetBuildPath, zipped);
                    }

                    if (config.UAB_BUILD_BYTES == true)
                    {
                        var dir = System.IO.Path.GetDirectoryName(assetBuildPathBytes);
                        if (System.IO.Directory.Exists(dir) == false)
                        {
                            System.IO.Directory.CreateDirectory(dir);
                        }
                        System.IO.File.WriteAllBytes(assetBuildPathBytes, zipped);
                    }

                    Debug.Log(string.Format("Built to `{0}`, size: {1} bytes, version: {2}.", assetBuildPath, zipped.Length, version));

                    if (version > 0)
                    {
                        if (config.UAB_CACHE_TYPE == UABConfig.CacheType.StreamingAssets)
                        {
                            var name        = System.IO.Path.GetFileName(assetBuildPath);
                            var builtinPath = string.Format(config.UAB_CACHE_PATH, Application.streamingAssetsPath, version, name);
                            var builtinDir  = System.IO.Path.GetDirectoryName(builtinPath);
                            if (System.IO.Directory.Exists(builtinDir) == false)
                            {
                                System.IO.Directory.CreateDirectory(builtinDir);
                            }

                            System.IO.File.WriteAllBytes(builtinPath, zipped);
                        }
                        else if (config.UAB_CACHE_TYPE == UABConfig.CacheType.Resources)
                        {
                            var name        = string.Format("{0}.bytes", System.IO.Path.GetFileName(assetBuildPath));
                            var builtinPath = string.Format(config.UAB_CACHE_PATH, string.Format("{0}/Resources", Application.dataPath), version, name);
                            var builtinDir  = System.IO.Path.GetDirectoryName(builtinPath);
                            if (System.IO.Directory.Exists(builtinDir) == false)
                            {
                                System.IO.Directory.CreateDirectory(builtinDir);
                            }

                            System.IO.File.WriteAllBytes(builtinPath, zipped);
                        }
                    }
                }
            }
        }
示例#9
0
 public static UABPackage Pack(GameObject[] objects, UABConfig config = null, List <ISerializer> serializers = null)
 {
     return(new UABPacker().Run(objects, config, serializers));
 }
示例#10
0
 public static GameObject[] Unpack(UABPackage package, UABConfig config = null, List <ISerializer> serializers = null)
 {
     return(new UABUnpacker().Run(package, config, serializers));
 }