Пример #1
0
        public AssetBundleButton(CompanionResource resource, AssetBundleResource bundle, RuntimePlatform platform,
                                 UnityObject asset, IUsesCloudStorage storageUser)
        {
            clicked += OnClicked;

            if (asset == null)
            {
                SetEnabled(false);
            }

            m_Resource    = resource;
            m_Platform    = platform;
            m_Bundle      = bundle;
            m_Asset       = asset;
            m_StorageUser = storageUser;

            name = $"{resource.name} - {platform} bundle button";

            var state = State.NotUploaded;

            if (m_Bundle != null)
            {
                if (m_Bundle.Timestamp >= m_Resource.timestamp)
                {
                    state = State.Uploaded;
                }
                else
                {
                    state = CompanionResourceUI.IsPlatformInstalled(m_Platform) ? State.Update : State.Warn;
                }
            }

            SetState(state);
        }
 internal static RequestHandle GetScene(this IUsesCloudStorage storageUser, CompanionProject project,
                                        CompanionResource resource, Action <bool, string> callback)
 {
     if (callback == null)
     {
         Debug.LogWarning("Callback is null in GetScene");
         return(default);
Пример #3
0
        /// <summary>
        /// Add a new or updated resource the list. The current time will be applied as a timestamp
        /// </summary>
        /// <param name="key">The storage key of the new resource</param>
        /// <param name="name">The name of the new resource</param>
        /// <param name="type">The type of the new resource</param>
        /// <param name="fileSize">The file size of the new resource</param>
        /// <param name="hasBundle">Whether this resource has an associated AssetBundle</param>
        /// <returns>The ResourceListViewData that was created or updated</returns>
        public CompanionResource AddOrUpdateResource(string key, string name, ResourceType type, long fileSize, bool hasBundle)
        {
            if (m_ResourceDictionary.TryGetValue(key, out var resource))
            {
                resource.Update(name, fileSize, hasBundle);
            }
            else
            {
                resource = new CompanionResource(key, name, type, fileSize, hasBundle);
                m_ResourceDictionary[key] = resource;
            }

            return(resource);
        }
        public static void AddCloudResourceToLocalResourceList(CompanionProject project, string resourceFolder, CompanionResource resource)
        {
            var localResourceList = GetLocalResourceList(project, resourceFolder) ?? new ResourceList();

            localResourceList.AddOrOverwriteExistingResource(resource);
            WriteLocalResourceList(project, resourceFolder, localResourceList);
        }
        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;
            }
        }
Пример #6
0
 /// <summary>
 /// Add or overwrite an existing resource. The timestamp in the provided resource will be preserved
 /// </summary>
 /// <param name="resource">The resource to add or write to the list </param>
 public void AddOrOverwriteExistingResource(CompanionResource resource)
 {
     m_ResourceDictionary[resource.key] = resource;
 }
Пример #7
0
 public bool TryGetResource(string key, out CompanionResource resource)
 {
     return(m_ResourceDictionary.TryGetValue(key, out resource));
 }