Exemplo n.º 1
0
        /// <summary>
        /// Loads the data from souvenir repository and creates souvenirs of the logged-in user.
        /// </summary>
        public void TryPlaceSouvenirs()
        {
            if (souvenirsPlaced && currentUser == LoggedInUser)
            {
                Debug.Log("Souvenirs are already loaded.");
                return;
            }

            if (string.IsNullOrEmpty(LoggedInUser))
            {
                Debug.LogWarning("User ID could not be retrieved.");
                return;
            }

            if (anchorManager == null)
            {
                Debug.LogWarning("World Anchor Manager could not be retrieved.");
                return;
            }

            if (anchorManager.AnchorStore == null)
            {
                Debug.LogWarning("Anchor Store could not be retrieved.");
                return;
            }

#if UNITY_UWP
            if (currentUser != LoggedInUser)
            {
                currentUser = LoggedInUser;

                // Load and cache the user's souvenirs to be placed.
                IUnityContainer container          = UnityDIContainer.Get();
                var             souvenirRepository = container.Resolve <SouvenirRepository>();
                unplacedSouvenirList = souvenirRepository.LoadSouvenirs(LoggedInUser);
            }
#endif

            souvenirsPlaced = true;

            for (int i = 0; i < unplacedSouvenirList.Count; ++i)
            {
                var souvenir = unplacedSouvenirList[i];
                if (WorldAnchorExists(souvenir.Id))
                {
                    CreateSouvenir(souvenir.Id, souvenir.TemplatePrefabPath, souvenir.BundleId, isNewSouvenir: false);

                    unplacedSouvenirList.RemoveAt(i);
                    --i;
                }
                else
                {
                    souvenirsPlaced = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs initialization related to roaming data manager.
        /// </summary>
        private void InitRoamingDataManager()
        {
#if UNITY_UWP
            IUnityContainer container = UnityDIContainer.Get();
            roamingDataManager = container?.Resolve <RoamingDataManager>();
            if (roamingDataManager == null)
            {
                Debug.LogError("Could not resolve an instance of RoamingDataManager in OnboardingMagnet.");
            }
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        /// If a deletion was requested, destroys the souvenir gameobject.
        /// </summary>
        private void CommitRemoving()
        {
            if (removingAsked)
            {
#if UNITY_UWP
                IUnityContainer    container          = UnityDIContainer.Get();
                SouvenirRepository souvenirRepository = container.Resolve <SouvenirRepository>();
                SouvenirManager    souvenirManager    = FindObjectOfType <SouvenirManager>();
                souvenirRepository.RemoveSouvenir(souvenirManager.LoggedInUser, Id);
#endif
                Destroy(gameObject);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a Souvenir instance and binds the selected model to it.
        /// </summary>
        public void CreateSouvenir(string souvenirId, string prefabPath, string bundleId, bool isNewSouvenir = true)
        {
            if (souvenirPrefab == null)
            {
                souvenirPrefab = Resources.Load <GameObject>(Constants.SouvenirPrefab);
                if (souvenirPrefab == null)
                {
                    Debug.LogError("Could not load the Souvenir prefab.");
                    return;
                }
            }

            GameObject souvenirInstance = Instantiate(souvenirPrefab);

            if (souvenirInstance == null)
            {
                Debug.LogError("Could not instantiate the Souvenir prefab.");
                return;
            }
            souvenirInstance.SetActive(false);

            string     modelPrefabPath = Constants.ModelsPrefabFolder + prefabPath;
            GameObject modelPrefab;

            bool isModelLoaded = modelPrefabs.TryGetValue(modelPrefabPath, out modelPrefab);

            if (!isModelLoaded || modelPrefab == null)
            {
                modelPrefab = Resources.Load <GameObject>(modelPrefabPath);
                if (modelPrefab == null)
                {
                    Debug.LogError("Could not load the selected model prefab.");
                    return;
                }

                modelPrefabs.Add(modelPrefabPath, modelPrefab);
            }

            GameObject modelInstance = Instantiate(modelPrefab);

            if (modelInstance == null)
            {
                Debug.LogError("Could not instantiate the selected model prefab.");
                return;
            }
            modelInstance.transform.parent = souvenirInstance.transform;

            var souvenirComponent = souvenirInstance.GetComponent <Souvenir>();

            if (souvenirComponent == null)
            {
                Debug.LogError("Could not find the HSSouvenir component in the souvenir instance.");
                return;
            }
            souvenirComponent.Id = souvenirId;

            var contentProvider = new OneDriveProvider(bundleId);

            souvenirComponent.ContentProvider = contentProvider;

            if (isNewSouvenir)
            {
                souvenirComponent.StartPlacing();
#if UNITY_UWP
                // Adds the data of the new souvenir in the roaming data.
                UnityContainer     container          = UnityDIContainer.Get();
                SouvenirRepository souvenirRepository = container.Resolve <SouvenirRepository>();
                souvenirRepository.AddSouvenir(LoggedInUser, new SouvenirModel(souvenirId, prefabPath, bundleId));
#endif
            }
            else
            {
                if (anchorManager.AnchorStore != null)
                {
                    anchorManager.AnchorStore.Load(souvenirId, souvenirInstance);
                }
                else
                {
                    Debug.Log("The anchor store was called before it was initialized.");
                }
            }

            var carouselPresenterSource = souvenirInstance.AddComponent <CarouselPresenterSource>();
            carouselPresenterSource.Souvenir = souvenirComponent;

            souvenirInstance.SetActive(true);
        }