Exemplo n.º 1
0
    private AssetBundleManifest GetOldManifest()
    {
        var jsonSerializer = new JsonSerializer(new JsonSerializerSettings
        {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        AssetBundleManifest manifest = null;

        var filePath = Path.Combine(_serverBundlesFolder, _manifestFileName + ".json");

        Debug.Log(string.Format("Loading old manifest by path {0}", filePath));

        if (File.Exists(filePath))
        {
            var manifestContent = File.ReadAllText(filePath);
            manifest = jsonSerializer.DeserializeString <AssetBundleManifest>(manifestContent);
            Debug.Log("Old manifest loaded succesfully.");
        }
        else
        {
            Debug.Log("Old manifest loading failed.");
        }

        return(manifest);
    }
Exemplo n.º 2
0
    private void ProcessingAssetInfos(BuildTarget target, List <AssetReference> assetInfos, Dictionary <string, string> assetsToBundleMap,
                                      CustomManifest manifest)
    {
        foreach (var assetReference in assetInfos)
        {
            if (assetReference.extension == ".manifest" && !_ignoreList.Contains(assetReference.fileNameAndExtension))
            {
                var bundleInfo = new BundleInfo();
                bundleInfo.Name = assetReference.fileName;
                bundleInfo.CRC  = GetCRCFromManifest(assetReference.path);
                bundleInfo.Hash = GetHashFromManifest(assetReference.path);

                foreach (var assetPath in GetAssetPathesFromManifest(target, assetReference.path))
                {
                    bundleInfo.AssetInfos.Add(assetPath);

                    if (assetsToBundleMap.ContainsKey(assetPath))
                    {
                        Debug.LogError(string.Format(" Asset: {0} used in two or more bundles!!", assetPath));
                    }

                    assetsToBundleMap.Add(assetPath, assetReference.fileName);
                }

                manifest.BundleInfos.Add(bundleInfo.Name, bundleInfo);
            }
        }
    }
Exemplo n.º 3
0
    private void CreateBundleInfos(List <AssetReference> assetInfos, AssetBundleManifest manifest, PerformGraph.AssetGroups incomigGroups)
    {
        foreach (var assetReference in assetInfos)
        {
            if (IsUnityManifest(assetReference))
            {
                var unityManifest = assetReference;
                var bundleInfo    = new BundleInfo
                {
                    Name = unityManifest.fileName,
                    CRC  = GetCRCFromManifest(unityManifest.path)
                };

                var rawAssetPathesFromManifest = GetRawAssetPathesFromManifest(unityManifest.path);

                if (rawAssetPathesFromManifest.Any())
                {
                    // ���� � ���������� ���� "������" - ������� � ������ ����� ����� �� �������� ������
                    // ���� �����, �� �������� ������ ����� ��������� ��� ���������� ������, � ������� �����
                    // ���� �����.
                    var rawAssetPath = rawAssetPathesFromManifest[0];
                    rawAssetPath = RemoveAssetsFolderFromPath(rawAssetPath);

                    foreach (var incomigGroup in incomigGroups.assetGroups)
                    {
                        var groupFound = false;

                        foreach (var reference in incomigGroup.Value)
                        {
                            if (reference.path.Contains(rawAssetPath))
                            {
                                groupFound = true;
                                bundleInfo.CustomInfo.Add("GroupName", incomigGroup.Key);
                                break;
                            }
                        }

                        if (groupFound)
                        {
                            break;
                        }
                    }
                }

                foreach (var rawAssetPath in rawAssetPathesFromManifest)
                {
                    var pathWithoutAssetFolder = RemoveAssetsFolderFromPath(rawAssetPath);
                    var trunkatedAssetPath     = TruncatePathFromManifest(pathWithoutAssetFolder);
                    bundleInfo.AssetInfos.Add(trunkatedAssetPath);
                }

                Debug.Log(string.Format("Bundle {0} with {1} assets added to manifest.", bundleInfo.Name, bundleInfo.AssetInfos.Count));
                manifest.BundleInfos.Add(bundleInfo.Name, bundleInfo);
            }
        }
    }
Exemplo n.º 4
0
    public override void Build(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming,
                               IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output outputFunc,
                               Action <Model.NodeData, string, float> progressFunc)
    {
        var customManifest    = new CustomManifest();
        var assetsToBundleMap = new Dictionary <string, string>();

        foreach (var assetGroups in incoming)
        {
            foreach (var ag in assetGroups.assetGroups)
            {
                var assetInfos = ag.Value;
                ProcessingAssetInfos(target, assetInfos, assetsToBundleMap, customManifest);
            }
        }

        foreach (var assetToBundle in assetsToBundleMap)
        {
            var assetInfo = new AssetInBundleInfo();
            assetInfo.Name             = assetToBundle.Key;
            assetInfo.GameAssetTypeTag = GetAssetType(assetToBundle.Key).ToString();

            foreach (var assetDependency in AssetDatabase.GetDependencies(assetToBundle.Key))
            {
                if (assetDependency == assetToBundle.Key)
                {
                    continue;
                }

                if (assetsToBundleMap.ContainsKey(assetDependency))
                {
                    var bundleDep = assetsToBundleMap[assetDependency];

                    if (!assetInfo.Dependencies.Contains(bundleDep) && bundleDep != assetToBundle.Value)
                    {
                        assetInfo.Dependencies.Add(bundleDep);
                    }
                }
            }

            customManifest.AssetInfos.Add(assetInfo.Name, assetInfo);
        }

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.SerializeString(customManifest);

        var path = GetCustomManifestPath(target, node);

        File.WriteAllText(path, manifestAsJson);
    }
Exemplo n.º 5
0
    private AssetBundleManifest CreateManifest(IEnumerable <PerformGraph.AssetGroups> incoming)
    {
        var incommingAssets = incoming.First();
        var incomigGroups   = incoming.Last(); // ���������� ������
        var customManifest  = new AssetBundleManifest();

        foreach (var ag in incommingAssets.assetGroups)
        {
            var assetInfo = ag.Value;
            CreateBundleInfos(assetInfo, customManifest, incomigGroups);
            CreateAssetInfos(assetInfo, customManifest);
        }

        CreateNotBundlesAssetsInfos(customManifest);

        return(customManifest);
    }
Exemplo n.º 6
0
    private void CopyManifest(AssetBundleManifest manifest)
    {
        if (_manifestCachePath == null)
        {
            throw new Exception("ManifestCachePath is null");
        }

        var jsonSerializer = new JsonSerializer(new JsonSerializerSettings
        {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.SerializeString(manifest);

        var pathToCopy = Path.Combine(Directory.GetParent(Application.dataPath).ToString(), _manifestCachePath.path);

        File.WriteAllText(pathToCopy, manifestAsJson);
    }
Exemplo n.º 7
0
    private void CreateNotBundlesAssetsInfos(AssetBundleManifest customManifest)
    {
        var resourcesDirectory = Application.dataPath + "/Resources";
        var resources          = new List <string>();

        GetAllResources(resourcesDirectory, ref resources);
        var assetsPath = Application.dataPath;

        foreach (var resource in resources)
        {
            var resourceNormalizedPath = resource;
            var resourceExtension      = Path.GetExtension(resourceNormalizedPath);

            // �������� ������ ���� �� �������
            if (resourceNormalizedPath.StartsWith(assetsPath))
            {
                resourceNormalizedPath = resource.Remove(0, assetsPath.Length + 1);
            }

            resourceNormalizedPath = resourceNormalizedPath.Replace("\\", "/");
            var trunkatedAssetPath = TruncatePathFromManifest(resourceNormalizedPath);

            if (!customManifest.AssetInfos.ContainsKey(trunkatedAssetPath))
            {
                var assetInfo = new AssetInfo();
                assetInfo.Name             = trunkatedAssetPath;
                assetInfo.GameAssetTypeTag = GetAssetType(trunkatedAssetPath).ToString();

                // �������� ���������� �� ����
                var nameInResources = trunkatedAssetPath;
                if (!string.IsNullOrEmpty(resourceExtension))
                {
                    nameInResources = nameInResources.Replace(resourceExtension, "");
                }

                assetInfo.CustomInfo.Add("nameInResources", nameInResources);

                customManifest.AssetInfos.Add(assetInfo.Name, assetInfo);
            }
        }
    }
Exemplo n.º 8
0
    private void CopyFiles(List <AssetReference> assetInfos)
    {
        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var customManifest = new CustomManifest();

        foreach (var assetReference in assetInfos)
        {
            if (assetReference.extension == ".json")
            {
                var manifestContent = File.ReadAllText(assetReference.absolutePath);
                customManifest = jsonSerializer.DeserializeString <CustomManifest>(manifestContent);
            }
        }

        foreach (var assetReference in assetInfos)
        {
            var apendToName = "";
            if (assetReference.extension != ".json")
            {
                var crc32 = "";
                foreach (KeyValuePair <string, BundleInfo> bundleInfo in customManifest.BundleInfos)
                {
                    if (bundleInfo.Value.Name == assetReference.fileName)
                    {
                        crc32 = bundleInfo.Value.CRC;
                    }
                }
                apendToName = "_" + crc32;
            }

            var newPath = Path.Combine(_exportDirectory, assetReference.fileName + apendToName + assetReference.extension);
            if (!File.Exists(newPath))
            {
                File.Copy(assetReference.absolutePath, newPath);
            }
        }
    }
Exemplo n.º 9
0
    private void UpdateBundlesUx(AssetBundleManifest newManifest, AssetBundleManifest oldManifest)
    {
        Debug.Log("Updating bundles UX");
        if (oldManifest == null)
        {
            Debug.Log("OldManifest was not found. Cant update UXs");
            return;
        }

        foreach (var bundleInfo in newManifest.BundleInfos)
        {
            BundleInfo oldBundleInfo = null;
            if (oldManifest.BundleInfos.TryGetValue(bundleInfo.Key, out oldBundleInfo))
            {
                if (bundleInfo.Value.CRC != oldBundleInfo.CRC || !bundleInfo.Value.CustomInfo.Equals(oldBundleInfo.CustomInfo))
                {
                    Debug.Log(string.Format("Updating {0} bundle UX from {1} to {2}", bundleInfo.Value.Name, bundleInfo.Value.Ux, bundleInfo.Value.Ux + 1));
                    bundleInfo.Value.Ux = oldBundleInfo.Ux + 1;
                }
            }
        }
    }
Exemplo n.º 10
0
    private void CreateAssetInfos(List <AssetReference> assetInfos, AssetBundleManifest manifest)
    {
        foreach (var assetReference in assetInfos)
        {
            if (IsUnityManifest(assetReference))
            {
                var unityManifest = assetReference;
                var rawAssetPathesFromManifest = GetRawAssetPathesFromManifest(unityManifest.path);

                foreach (var rawAssetPath in rawAssetPathesFromManifest)
                {
                    var pathWithoutAssetFolder = RemoveAssetsFolderFromPath(rawAssetPath);
                    var trunkatedAssetPath     = TruncatePathFromManifest(pathWithoutAssetFolder);

                    var assetInfo = new AssetInfo();
                    assetInfo.Name             = trunkatedAssetPath;
                    assetInfo.GameAssetTypeTag = GetAssetType(trunkatedAssetPath).ToString();
                    assetInfo.CustomInfo.Add("nameInBundle", rawAssetPath);

                    BundleInfo bundleInfoWithAsset = null;

                    foreach (var bundleInfo in manifest.BundleInfos)
                    {
                        if (bundleInfo.Value.AssetInfos.Contains(assetInfo.Name))
                        {
                            bundleInfoWithAsset = bundleInfo.Value;
                            Debug.Log(string.Format("Asset {0} containing in bundle {1}", assetInfo.Name, bundleInfoWithAsset.Name));
                            break;
                        }
                    }

                    var deps = AssetDatabase.GetDependencies(rawAssetPath);
                    Debug.Log(string.Format("Asset {0} ({2}) has {1} dependencies:", assetInfo.Name, deps.Length, rawAssetPath));

                    foreach (var assetDependency in deps)
                    {
                        Debug.Log("Asset Dependency: " + assetDependency);

                        // � ����������� �������� � ��� �����, ����������� ������� �� ����
                        if (assetDependency == rawAssetPath)
                        {
                            continue;
                        }

                        var trunkatedAssetDependencyPath = NormalizePathFromManifest(assetDependency);
                        trunkatedAssetDependencyPath = RemoveAssetsFolderFromPath(trunkatedAssetDependencyPath);
                        trunkatedAssetDependencyPath = TruncatePathFromManifest(trunkatedAssetDependencyPath);

                        foreach (var bundleInfo in manifest.BundleInfos)
                        {
                            if (bundleInfo.Value.AssetInfos.Contains(trunkatedAssetDependencyPath))
                            {
                                var dependentBundleName = bundleInfo.Value.Name;
                                Debug.Log(string.Format("Asset dependency {0} was found in {1} bundle", assetDependency, dependentBundleName));

                                // �� ���������� � ����������� �����, ������� ��� �������� ���� �����. � �������.
                                if (!assetInfo.Dependencies.Contains(dependentBundleName) && bundleInfoWithAsset != bundleInfo.Value)
                                {
                                    Debug.Log(string.Format("Asset dependency added: {0}", dependentBundleName));
                                    assetInfo.Dependencies.Add(dependentBundleName);
                                }
                            }
                        }
                    }

                    Debug.Log(string.Format("Asset {0} with {1} dependencies added to Manifest", assetInfo.Name, assetInfo.Dependencies.Count));
                    manifest.AssetInfos.Add(assetInfo.Name, assetInfo);
                }
            }
        }
    }
Exemplo n.º 11
0
 public void AddManifestPart(AssetBundleManifest manifestPart, bool allowOverrides = false)
 {
     AddManifestPart(manifestPart.BundleInfos, manifestPart.AssetInfos, allowOverrides);
 }