Exemple #1
0
    public void SaveScenery()
    {
        appStateManager.currentOutputMessage = $"Saving Scenery data to cloud...";
        SceneryItemContainerDTO sceneryItemContainer = MapSceneryGameobjectsToDTO();

        string sceneryItemContainerJson = JsonUtility.ToJson(sceneryItemContainer);

        StartCoroutine(PostSceneryDataJsonToApi(sceneryItemContainerJson));
    }
Exemple #2
0
    private void RePopulateGameItemsFromData(SceneryItemContainerDTO sceneryItemContainerDTO)
    {
        appStateManager.DestroyAllSceneryInCollection(); // clear out any existing objects

        foreach (SceneryItemDTO sceneryItemData in sceneryItemContainerDTO.sceneryItems)
        {
            GameObject sceneryObject = sceneryUtil.SpawnNewScenery(sceneryItemData.sceneryTypeEnum);
            SerialiseTransformUtil.UpdateTransform(ref sceneryObject, sceneryItemData.sceneryTransformComponent); // apply the positioning and rotation info, that was saved to the cloud.  note this is the "local" version only, meaning they are relative to the parent (the spatial anchor prefab)
        }
        appStateManager.currentOutputMessage = $"Restored Scenery data from cloud OK.";
    }
Exemple #3
0
    IEnumerator GetSceneryDataFromApi(Action <SceneryItemContainerDTO> onSuccessSceneryDataFromAPI)
    {
        appStateManager.currentOutputMessage = $"Getting Scenery data from cloud...";

        using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(generalConfiguration.apiUrl_SceneData))
        {
            yield return(unityWebRequest.SendWebRequest());

            while (!unityWebRequest.isDone)
            {
                yield return(null);
            }

            byte[] sceneryItemContainerResult            = unityWebRequest.downloadHandler.data;
            string sceneryItemContainerJSON              = System.Text.Encoding.Default.GetString(sceneryItemContainerResult);
            SceneryItemContainerDTO sceneryItemContainer = JsonUtility.FromJson <SceneryItemContainerDTO>(sceneryItemContainerJSON);

            onSuccessSceneryDataFromAPI(sceneryItemContainer);
        }
    }
Exemple #4
0
    private SceneryItemContainerDTO MapSceneryGameobjectsToDTO()
    {
        SceneryItemContainerDTO sceneryItemContainer = new SceneryItemContainerDTO();

        appStateManager.SetAnchorAndContainerIfNull();

        foreach (Transform item in appStateManager.currentSceneryContainer.transform)
        {
            GameObject currentSceneryItemObject = item.gameObject;
            Scenery    currentSceneryItem       = currentSceneryItemObject.GetComponent <Scenery>();

            SceneryItemDTO sceneryItemDTO = new SceneryItemDTO();

            sceneryItemDTO.sceneryTypeEnum           = currentSceneryItem.sceneryTypeEnum;
            sceneryItemDTO.sceneryTransformComponent = new TransformComponentDTO(currentSceneryItemObject.transform);

            sceneryItemContainer.sceneryItems.Add(sceneryItemDTO);
        }
        return(sceneryItemContainer);
    }