Saving And Loading Entire Scenes In Unity C# [duplicate] - c#

This question already has answers here:
Save and load entire scene in Unity
(3 answers)
Closed last year.
I am making a game where you can build stuff while playing, im trying to figure out how to save a entire scene and load it, like with a json file or saving data of blocks placed in a array with playerprefs. thanks

You ideally want to place all of the data you are looking to save into a struct, then save via JSON. You can then read the JSON and then reinstate what was build previously.

Related

How to turn have a .json file as a string in C# [duplicate]

This question already has answers here:
How to read an entire file to a string using C#?
(17 answers)
Closed 5 years ago.
So I have this .json file: temp_file.json
Now all I need to do is get whatever is in this .json file, and put it in a string using C# in Visual Studio 2017.
That's it.
I don't want it to be turned into a object of a certain class or whatever. Just get whatsever in the file, right into a string.
A lot of other questions/answers I have stumbled upon are about desirializing and serializing etc. I don't need that. Just turn the .json file in to a string. No need to write it to a console or whatsoever.
Somewhy I just cant lay my finger on it. It sounds simple to do...
You dont get any simpler than
var contents = File.ReadAllText(#"drive:\path\to\yourfile.json");

Best practice to store images in xml? [duplicate]

This question already has answers here:
Convert Image to Bytes and save in Xml
(2 answers)
Closed 5 years ago.
I am writing a single exe file application that can load and save data files (txt, csv, xml and json), the user can choose a custom image, save it in a data file and send the file to another user who should then be able to open it and see the image.
Since I want the application to be user friendly and easy to use (I know that's repetition :) ) I want it to work with a single data file, instead of having user1 send all his images to user2 so that user2 can see them, so the way I see it - storing the image in the file is innevitable. Here comes the question what would be the best practice of storing the image?
I'm guessing a byte array is better than a string?
I would use a base64 encoded string, since it uses less space then hex encoding. Almost every programming language should have a library to convert from a stream or byte array to base64 and the other way around

trying to create leader board and save locally to phone [duplicate]

This question already has answers here:
What is the best way to save game state?
(2 answers)
Closed 5 years ago.
Im making a game in unity and need a leader board that displays highscores and the name they provide at the end of the game.
How do I save these and keep them for later use (even after closing and reopening the game) and then apply them to a leaderboard.
Assuming the people who play are on different computers you'll need to persist the high score data on a machine somewhere. (If they're not on different computers you could just store it in a text file locally on that single machine.) A good choice for persisting would be a database. You'll probably want to secure the database so that people don't mess with it so you may need a web or HTTP front-end that your Unity app interfaces with. You can use WWW in Unity to call your front-end.

Out-of-the-box JSON equivalent for C# and Unity 3D [duplicate]

This question already has answers here:
Need a JSON parser for Unity3d
(2 answers)
Serialize and Deserialize Json and Json Array in Unity
(9 answers)
Closed 5 years ago.
I'm building a game and I need to store multiple data about levels:
A list of strings for dialogs
An int for the countdown time of each level
A float for right answer
Strings for dynamically loaded asset names.
probably some other data..
Coming from a web background, the most obvious path is to make this with JSON, but Unity 3D does not provide JSON support out of the box.. so I thought of XML, but still, no native support.. then I thought about multidimentional array, but there are limitations, such as the data types must be the same.
As a student, I want to do things according to the development pattern of the engine without external libraries, and my question is How do Unity Game Developers store data like this? What is the best way to deal with this problem?

Reading appended line from bottom of logfile [duplicate]

This question already has answers here:
Read last line of text file
(6 answers)
Closed 8 years ago.
Scenario is the following:
A (weather) service dumps sensor data into a log file/text file.
The new readings are appended to the bottom of a given (existing) file
New data is added at regular intervals (interval may or may not be known)
I need to parse the new information/line and send it off to another service.
I don't want to read the whole file every time, unless I have to.
EDIT: Sorry for the bad wording. "unless I have to" should be understood as if there is no other way around. I have seen the post/answer referenced and it seems a little extensive.
Framework is 4.5.x.
Thank you.
To get the the last line of a text file you can use this
File.ReadLines(myFileName).Last();
This is the simplest method, but is inefficient. You can write your own parser as show here

Categories