public static ResourceList MergeResourceLists(ResourceList local, ResourceList remote) { if (local == null) { return(remote); } if (remote == null) { return(local); } var resourceList = new ResourceList(); resourceList.m_Merged = true; var resourceDictionary = resourceList.m_ResourceDictionary; var bundleDictionary = resourceList.m_BundleDictionary; foreach (var kvp in local.m_ResourceDictionary) { resourceDictionary[kvp.Key] = kvp.Value; } foreach (var kvp in local.m_BundleDictionary) { bundleDictionary[kvp.Key] = kvp.Value; } foreach (var kvp in remote.m_ResourceDictionary) { var key = kvp.Key; if (resourceDictionary.TryGetValue(key, out var resource)) { resource.cloudVersion = kvp.Value; } else { resourceDictionary[key] = kvp.Value; } } foreach (var kvp in remote.m_BundleDictionary) { var key = kvp.Key; if (bundleDictionary.TryGetValue(key, out var group)) { group.cloudVersion = kvp.Value; } else { bundleDictionary[key] = kvp.Value; } } return(resourceList); }
internal static void AddOrUpdateResource(this IUsesCloudStorage storageUser, CompanionProject project, string resourceFolder, string key, string name, ResourceType type, long fileSize, bool hasBundle, Stack <RequestHandle> requests, Action <bool, ResourceList> callback = null) { var localResourceList = GetLocalResourceList(project, resourceFolder) ?? new ResourceList(); var resource = localResourceList.AddOrUpdateResource(key, name, type, fileSize, hasBundle); WriteLocalResourceList(project, resourceFolder, localResourceList); void LocalOnlyUpdate(bool success, ResourceList resourceList) { resourceList = ResourceList.MergeResourceLists(localResourceList, resourceList); ResourceListChanged?.Invoke(false, resourceList); callback?.Invoke(success, resourceList); } if (!project.linked) { LocalOnlyUpdate(true, new ResourceList()); return; } // Get the latest list to make sure we don't lose scenes in case of stale data requests.Push(storageUser.GetCloudResourceList(project, resourceFolder, (getListSuccess, cloudResourceList) => { if (getListSuccess) { cloudResourceList.AddOrOverwriteExistingResource(resource); requests.Push(storageUser.WriteCloudResourceList(project, resourceFolder, cloudResourceList, writeListSuccess => { if (writeListSuccess) { #if UNITY_EDITOR CloudResourceListChanged?.Invoke(cloudResourceList); #endif WriteFallbackCloudResourceList(project, resourceFolder, cloudResourceList); cloudResourceList = ResourceList.MergeResourceLists(localResourceList, cloudResourceList); ResourceListChanged?.Invoke(true, cloudResourceList); callback?.Invoke(true, cloudResourceList); } else { LocalOnlyUpdate(false, cloudResourceList); } })); } else { LocalOnlyUpdate(false, cloudResourceList); } })); }
public void Process(ResourceList resourceList, List <AssetBundleBuild> builds, Dictionary <string, AssetImporter> importers, Stack <RequestHandle> requests) { switch (m_State) { case State.NotUploaded: if (m_Bundle == null) { return; } resourceList.RemoveAssetBundle(m_Resource.key, m_Platform.ToString()); requests.Push(m_StorageUser.CloudSaveAsync(m_Bundle.Key, string.Empty)); return; case State.Uploaded: if (m_Bundle != null) { return; } BuildAssetBundle(builds, importers); return; case State.Update: if (m_Bundle == null) { throw new Exception("Button is in update state but BundleResource is null"); } if (m_Bundle.Timestamp > m_Resource.timestamp) { return; } BuildAssetBundle(builds, importers); return; } }
internal static void OnCloudResourceListChanged(ResourceList resourceList) { CloudResourceListChanged?.Invoke(resourceList); }
internal static void ImportResource(this IUsesCloudStorage storageUser, CompanionProject project, CompanionResource resource, string platform, ResourceList resourceList, GameObject simulatedPlanePrefab, Material simulatedPlaneMaterial, Post postPrefab, MeshFilter meshPrefab, GameObject simulatedLightingPrefab, Stack <RequestHandle> requests, Action <UnityObject> callback) { string path; string cloudGuid; var resourceKey = resource.key; switch (resource.type) { case ResourceType.Scene: if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return; } void ImportSceneCallback(bool bundleSuccess, AssetPack assetPack) { storageUser.GetScene(project, resource, (success, jsonText) => { if (success) { CompanionSceneUtils.SplitSceneKey(resourceKey, out _, out cloudGuid); var sceneGuid = CompanionResourceSync.instance.GetAssetGuid(cloudGuid); var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid); // GUIDToAssetPath will return a path if the asset was recently deleted if (AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath) == null) { scenePath = null; } if (!string.IsNullOrEmpty(sceneGuid) && string.IsNullOrEmpty(scenePath)) { Debug.LogWarningFormat("Could not find scene with guid {0}. Falling back to new scene", sceneGuid); } var sceneName = CompanionSceneUtils.GetSceneName(resource.name); ImportScene(sceneName, jsonText, assetPack, scenePath); // Store cloud ID in temp scene object if original scene not found if (string.IsNullOrEmpty(scenePath)) { var cloudIdObject = new GameObject("__Temp"); cloudIdObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.DontSaveInBuild; var cloudIdSaver = cloudIdObject.AddComponent <CloudGuidSaver>(); cloudIdSaver.CloudGuid = cloudGuid; } } }); } if (resourceList.TryGetAssetBundleKey(resource.key, platform, out var assetBundleKey)) { requests.Push(storageUser.GetAssetPack(project, assetBundleKey, ImportSceneCallback)); } else { ImportSceneCallback(true, null); } return; case ResourceType.Environment: requests.Push(storageUser.CloudLoadAsync(resourceKey, (success, responseCode, response) => { if (success) { var environmentName = resource.name; path = EditorUtility.SaveFilePanelInProject(k_SaveEnvironmentDialogTitle, environmentName, k_PrefabExtension, string.Empty); if (string.IsNullOrEmpty(path)) { return; } ImportEnvironment(environmentName, response, path, simulatedPlanePrefab, simulatedPlaneMaterial, postPrefab, meshPrefab, simulatedLightingPrefab, callback); var resourceSync = CompanionResourceSync.instance; CompanionEnvironmentUtils.SplitEnvironmentKey(resourceKey, out _, out cloudGuid); resourceSync.SetAssetGuid(AssetDatabase.AssetPathToGUID(path), cloudGuid); } })); return; case ResourceType.Recording: path = EditorUtility.SaveFilePanelInProject(k_SaveRecordingDialogTitle, resource.name, k_RecordingExtension, string.Empty); if (string.IsNullOrEmpty(path)) { return; } requests.Push(storageUser.CloudLoadAsync(resourceKey, (success, responseCode, response) => { if (success) { CoroutineUtils.StartCoroutine(storageUser.ImportDataRecording(path, resourceKey, resource.name, response, requests, callback)); } })); return; case ResourceType.Marker: path = EditorUtility.SaveFilePanelInProject(k_SaveImageDialogTitle, resource.name, k_ImageExtension, string.Empty); if (string.IsNullOrEmpty(path)) { return; } var markerKey = resourceKey; requests.Push(storageUser.CloudLoadAsync(markerKey, (success, responseCode, response) => { if (success) { requests.Push(storageUser.ImportMarker(path, markerKey, response, callback)); } })); return; case ResourceType.Prefab: requests.Push(storageUser.GetPrefabAsset(project, resourceKey, platform, (bundleSuccess, prefab) => { UnityObject.Instantiate(prefab); })); return; } }