private void OnOpenButtonClick(string dataBaseOpenPath) { SceneDescriptor sceneDescriptor = SceneDescriptorsHelper.LoadFromFile(dataBaseOpenPath); if (!String.IsNullOrEmpty(sceneDescriptor.sceneName)) { scene = new GameObject(sceneDescriptor.sceneName).transform; } else { scene = new GameObject("Scene").transform; } scene.position = new Vector3(0, 0, 0); SceneComponent sceneComponent = scene.gameObject.AddComponent <SceneComponent>(); sceneComponent.SceneSize = sceneDescriptor.sceneSize; var environmentFolder = new GameObject(SceneDescriptorsHelper.EnvironmentFolderName).transform; environmentFolder.transform.SetParent(scene); SpritesCache cache = new SpritesCache(); SceneDescriptorsHelper.CreateInstances(sceneDescriptor.imagesEnvironment, environmentFolder, cache); SceneDescriptorsHelper.CreateInstances(sceneDescriptor.items, scene, cache); }
private static void SaveScene() { Scene scene = SceneManager.GetActiveScene(); var path = EditorUtility.SaveFilePanel( "Save scene as json", Application.dataPath, scene.name + ".json", "json" ); if (string.IsNullOrWhiteSpace(path)) { EditorUtility.DisplayDialog("Save Scene cancelled", "Saving scene to json cancelled", "Ok"); return; } SceneDescriptor desc = new SceneDescriptor(); List <GameObject> rootObjects = new List <GameObject>(); scene.GetRootGameObjects(rootObjects); foreach (GameObject whoa in rootObjects) { Actor currentAct = SceneReader.GetActor(whoa); desc.RootActors.Add(currentAct); } string sceneAsAWhole = JsonUtility.ToJson(desc); System.IO.File.WriteAllText(path, sceneAsAWhole, System.Text.Encoding.UTF8); EditorUtility.DisplayDialog("Success", "Finished saving scene to json file", "Ok"); }
private static void LoadScene() { var path = EditorUtility.OpenFilePanel( "Select the Scene File", Application.dataPath, "json" ); if (string.IsNullOrWhiteSpace(path)) { EditorUtility.DisplayDialog("Load Scene cancelled", "Loading scene from json cancelled", "Ok"); return; } string sceneDescription = System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8); SceneDescriptor desc = new SceneDescriptor(); try{ desc = JsonUtility.FromJson <SceneDescriptor>(sceneDescription); } catch (Exception ex) { Debug.Log("Error: " + ex.ToString()); EditorUtility.DisplayDialog("Load Scene error", "Error: " + ex.ToString(), "Ok"); return; } Scene scene = SceneManager.GetActiveScene(); List <GameObject> rootObjects = new List <GameObject>(); scene.GetRootGameObjects(rootObjects); if (rootObjects.Count > 0) { if (!EditorUtility.DisplayDialog("Confirm Scene Reset", "Do you really want to do this? All Scene objects will be erased and replaced", "Ok", "Cancel")) { EditorUtility.DisplayDialog("Load Scene cancelled", "Loading scene from json cancelled", "Ok"); return; } } scene.GetRootGameObjects(rootObjects); foreach (GameObject whoa in rootObjects) { DestroyImmediate(whoa); } foreach (Actor ac in desc.RootActors) { SceneInst.InstanceActor(ac, null); } // Rebuild the scene // Says it's okay // Here we'll use FromJsonOverwrite }
private void OnSaveButtonClick(string dataBaseSavePath) { SceneDescriptor sceneDescriptor = new SceneDescriptor(); sceneDescriptor.sceneName = scene.name; sceneDescriptor.sceneSize = scene.GetComponent <SceneComponent>().SceneSize; sceneDescriptor.imagesEnvironment = GetImagesEnvironment(); sceneDescriptor.items = GetItems(); SaveToFile(sceneDescriptor, dataBaseSavePath); }
private IScene LoadScene() { // TODO: load from file var scene = new SceneDescriptor(); scene.Add(new Scene.Objects.Plane(Vector3.Up, 0, new CheckerboardSurface(Parse("A34400")))); scene.Add(new Sphere(new Vector3(0, 2, 0), 2, new SolidColorSurface(Parse("36D215")))); scene.Add(new Sphere(new Vector3(3, 2, 0), 1, new SolidColorSurface(Parse("1F51A7")))); scene.Add(new Sphere(new Vector3(-2, 1.5f, -2), 0.75f, new SolidColorSurface(Parse("FFA86A")))); scene.Add(new Light(new Vector3(0, 5, -3f), 1, Parse("FAFFDB"))); scene.Add(new Light(new Vector3(0, 5, -3f), 1, Parse("FAFFDB"))); return(scene); }
public async Task <SceneDescriptor> AddScene(Scene scene) { var key = await UploadScene(scene, $"scenes/{Guid.NewGuid()}.json").ConfigureAwait(false); if (key == null) { return(null); } var descriptor = new SceneDescriptor { StorageKey = key, Name = scene.Name }; await SceneDescriptorRepository.Add(descriptor); return(descriptor.Id == null ? null : descriptor); }
public Transform CreateSceneFolder(SceneDescriptor sceneDescriptor) { GameObject scene = Instantiate(_buildParams.ScenePrefab); scene.name = sceneDescriptor.sceneName; SceneComponent sceneComponent = scene.GetComponent <SceneComponent>(); if (sceneComponent != null) { sceneComponent.SceneSize = sceneDescriptor.sceneSize; } else { sceneComponent = scene.AddComponent <SceneComponent>(); sceneComponent.SceneSize = sceneDescriptor.sceneSize; } return(scene.transform); }
public BuildResult Build(SceneDescriptor sceneDescriptor) { // in this case scene does not exists // so first need to pick items directly from SceneDescriptor // and then create objects ONLY for picked items SpritesCache cache = new SpritesCache(); // create scene Transform sceneFolder = CreateSceneFolder(sceneDescriptor); // load envinronment images SceneDescriptorsHelper.CreateInstances(sceneDescriptor.imagesEnvironment, sceneFolder, cache); // load items from SceneDescriptor var visibleItems = CreateVisibleItems(shuffle(sceneDescriptor.items).ToList(), sceneFolder, cache, _buildParams); // and make some of them pickable var pickableItems = MakeSomeSceneItemsPickable(visibleItems, _buildParams); return(GetBuildResult(pickableItems)); }
private void SaveToFile(SceneDescriptor sceneDescriptor, string dataBaseSavePath) { string json = JsonUtility.ToJson(sceneDescriptor, true); File.WriteAllText(Application.dataPath + "/" + dataBaseSavePath, json); }
public BuildResult Build(TextAsset textAsset) { SceneDescriptor sceneDescriptor = SceneDescriptorsHelper.CreateFromString(textAsset.text); return(Build(sceneDescriptor)); }
public BuildResult Build(string dataBasePath) { SceneDescriptor sceneDescriptor = SceneDescriptorsHelper.LoadFromFile(dataBasePath); return(Build(sceneDescriptor)); }