Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
        }