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);
    }
示例#2
0
    IEnumerator WorkProcess()
    {
        var manifestRequest = resourceStorage.LoadResource <string>(this, manifestURL);

        yield return(manifestRequest);

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifestRequest.Resource);

        //Set loaded bundles manifest
        resourceStorage.GetResourceLoader <LocalFolderBundlesLoader>().Manifest.AddManifestPart(manifestAsJson);
        //For server bundle loader
        //resourceStorage.GetResourceLoader<WebRequestBundlesLoader>().Manifest.AddManifestPart(manifestAsJson);

        var sceneBundleRequest = resourceStorage.LoadResource <AssetBundle>(this, bundleName);

        yield return(sceneBundleRequest);

        if (sceneBundleRequest.Resource.isStreamedSceneAssetBundle)
        {
            string[] scenePaths = sceneBundleRequest.Resource.GetAllScenePaths();
            string   sceneName  = System.IO.Path.GetFileNameWithoutExtension(scenePaths[0]);
            SceneManager.LoadScene(sceneName);
        }
    }
    private IEnumerator WorkProcess()
    {
        string manifestPath = String.Empty;
        string bundlesPath  = String.Empty;

#if UNITY_EDITOR
        foreach (var findAsset in AssetDatabase.FindAssets(manifestName))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json"))
            {
                manifestPath = AssetDatabase.GUIDToAssetPath(findAsset);
                break;
            }
        }

        foreach (var findAsset in AssetDatabase.FindAssets(bundlesFolderPath))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".u3d"))
            {
                bundlesPath = AssetDatabase.GUIDToAssetPath(findAsset).Replace(bundlesFolderPath + ".u3d", "");

                bundlesPath = Application.dataPath.Replace("/Assets", "/") + bundlesPath;
                break;
            }
        }

        resourceStorage = new ResourceStorage(100);

        UnityResourceFromBundleLoader resFromBundlesLoader = new UnityResourceFromBundleLoader(coroutineManager);
        LocalFolderBundlesLoader      bundlesLoader        = new LocalFolderBundlesLoader(bundlesPath, coroutineManager);

        resourceStorage.RegisterResourceLoader(resFromBundlesLoader);
        resourceStorage.RegisterResourceLoader(bundlesLoader);


        var manifest = AssetDatabase.LoadAssetAtPath <TextAsset>(manifestPath);

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifest.text);
        bundlesLoader.Manifest.AddManifestPart(manifestAsJson);
#endif

        var loadPrefab = resourceStorage.LoadResource <GameObject>(this, resourceName);
        yield return(loadPrefab);

        Instantiate(loadPrefab.Resource);

        //Del me
        resourceStorage.ReleaseFromCache(this, resourceName);

        loadPrefab = resourceStorage.LoadResource <GameObject>(this, resourceName);
        yield return(loadPrefab);

        Instantiate(loadPrefab.Resource);
    }
示例#4
0
    private void Awake()
    {
        discCacheFolderPath = Application.dataPath + discCacheFolderPath;
        GameObject         timeProvidersGo           = new GameObject("-TimeProvider");
        SimpleTimeProvider mainCoroutineTimeProvider = timeProvidersGo.AddComponent <SimpleTimeProvider>();

        coroutineManager = new CoroutineManager();
        coroutineManager.TimeProvider = mainCoroutineTimeProvider;

#if UNITY_EDITOR
        foreach (var findAsset in AssetDatabase.FindAssets(manifestName))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json") && AssetDatabase.GUIDToAssetPath(findAsset).Contains("/Sources/"))
            {
                serverUrl = Application.dataPath.Replace("/Assets", "/") + AssetDatabase.GUIDToAssetPath(findAsset).Replace(manifestName + ".json", "");
                break;
            }
        }

        discCacheFolderPath = serverUrl.Replace("/Sources/", "/FileCacheForExample");


        foreach (var findAsset in AssetDatabase.FindAssets(manifestName))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json"))
            {
                manifestPath = AssetDatabase.GUIDToAssetPath(findAsset);
                break;
            }
        }
#endif
        resourceStorage = new ResourceStorage(100);

        var textureCreator = new TextureDataCreator();

        var versionedResourceLoader = new VersionedDiskCachedResourceLoader(discCacheFolderPath, "file://" + serverUrl, coroutineManager);
        versionedResourceLoader.RegisterResourceCreator(textureCreator);
        resourceStorage.RegisterResourceLoader(versionedResourceLoader);

        loaderPrefix = versionedResourceLoader.SupportsMask;
        TextAsset manifest = null;
#if UNITY_EDITOR
        manifest = AssetDatabase.LoadAssetAtPath <TextAsset>(manifestPath);
#endif

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.DeserializeString <AssetFilesManifest>(manifest.text);

        versionedResourceLoader.Manifest.AddManifestPart(manifestAsJson);

        _loadImageVersion1.onClick.AddListener(() => { coroutineManager.StartCoroutine(this, LoadImageVer1Process()); });

        _loadImageVersion2.onClick.AddListener(() => { coroutineManager.StartCoroutine(this, LoadImageVer2Process()); });
    }
示例#5
0
    public List <Dictionary <string, List <AssetReference> > > ParceFile(BuildTarget target)
    {
        var rawJson        = File.ReadAllBytes(_inputDir[target] + _fileName[target] + ".json");
        var jsonSerializer = new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var deserialized = jsonSerializer.Deserialize <List <Dictionary <string, List <AssetReference> > > >(rawJson);

        return(deserialized);
    }
示例#6
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);
    }
    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);
    }
示例#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);
            }
        }
    }
    private IEnumerator InitProcess()
    {
        Debug.Log("Start Init process");

        resourceStorage = new ResourceStorage(100);

        var manifestLoader = new WebRequestLoader(coroutineManager);

        manifestLoader.RegisterResourceCreator(new StringDataCreator());

        UnityResourceFromBundleLoader resFromBundlesLoader = new UnityResourceFromBundleLoader(coroutineManager);
        WebRequestBundlesLoader       bundlesLoader        = new WebRequestBundlesLoader(serverStaticPath, coroutineManager);

        resourceStorage.RegisterResourceLoader(manifestLoader);
        resourceStorage.RegisterResourceLoader(resFromBundlesLoader);
        resourceStorage.RegisterResourceLoader(bundlesLoader);


        //Load Manifest
        ManifestResourceHolder manifestHolder = new ManifestResourceHolder();
        var manifestLoadingOperation          = resourceStorage.LoadResource <string>(manifestHolder, Path.Combine(serverStaticPath, manifestName));

        yield return(manifestLoadingOperation);

        Debug.Log("Manifest loaded: " + manifestLoadingOperation.Resource);

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifestLoadingOperation.Resource);

        bundlesLoader.Manifest.AddManifestPart(manifestAsJson);

        resourceStorage.ReleaseAllOwnerResourcesFromCache(manifestHolder);

        _prefabsResourceHolder = new PrefabsResourceHolder();
        Debug.Log("Init process pass");
    }
    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 AssetsManifest <AssetInfo>();

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

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

        var rootFolder = Path.Combine(Directory.GetParent(Application.dataPath).ToString(),
                                      _manifestDirectoryInternalRelative);

        if (!Directory.Exists(rootFolder))
        {
            Directory.CreateDirectory(rootFolder);
        }

        if (_copyManifestExternal && !String.IsNullOrEmpty(_manifestDirectoryExport))
        {
            File.WriteAllText(GetCustomManifestPath(_manifestDirectoryExport), manifestAsJson);
            Process.Start(_manifestDirectoryExport);
        }
        else
        {
            File.WriteAllText(GetCustomManifestPath(rootFolder), manifestAsJson);
        }
    }
    /**
     * Build is called when Unity builds assets with AssetBundle Graph.
     */
    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)
    {
        List <Dictionary <string, List <AssetReference> > > groups = new List <Dictionary <string, List <AssetReference> > >();

        foreach (var assetGroups in incoming)
        {
            groups.Add(assetGroups.assetGroups);
        }

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

        var path = PrepareOutputDirectory(target, node, false, true);

        File.WriteAllText(path + _fileName[target] + ".json", jsonSerializer.SerializeString(groups));
    }