Hot answers tagged

28

There's a class named TextAssets which is used for text file reading. http://docs.unity3d.com/Manual/class-TextAsset.html Here you can find the supported file format. So if you want to read the text file, the script would be like this: class YourClassName : MonoBehaviour{ public TextAsset textFile; // drop your file here in inspector void ...


18

I'm using GitHub for Windows which generates a nice gitignore ignoring most extraneous files like log files or files specific to VS that don't need to be shared. From what I can gather from this page in the Unreal docs, you can probably ignore these directories: DerivedDataCache Intermediate Saved I'm not going to ignore Binaries, if only because I'm ...


14

I don’t know the differences between the public version of UE4 and mine, but here is the .gitignore file I have been using: Engine/Binaries/ Engine/DerivedDataCache/ Engine/Intermediate/ Engine/Plugins/*/*/Binaries/ Engine/Plugins/*/*/Intermediate/ Engine/Programs/UnrealHeaderTool/ Engine/Programs/UnrealPak/ Engine/Saved/ Engine/Shaders/Binaries/ Engine/...


9

Libgdx has built in decoding and encoding functionality. Gustavo Steigert has written a nice article about this on his blog: http://steigert.blogspot.be/2012/03/5-libgdx-tutorial-files.html. Scroll down a bit to the section "2. Persist Profile operation". In this blogpost, he explains that by using the class com.badlogic.gdx.utils.Base64Coder you can ...


8

C# Version. using System.IO; void readTextFile(string file_path) { StreamReader inp_stm = new StreamReader(file_path); while(!inp_stm.EndOfStream) { string inp_ln = inp_stm.ReadLine( ); // Do Something with the input. } inp_stm.Close( ); } EDIT: (Fixed an error on line 9; changed "stm.ReadLine();" to "inp_stm.ReadLine();")...


5

You can do this in the same way you would in .NET string word = File.ReadAllText(txtFilePath); This code snippet can be used in any location you wish then.


5

I think the obj file format is what you need. OBJ is pretty commonly used in 3D graphics, and it's a text file. You will need to walk through your mesh properties and write your own file. Then you'll be able to load and display it.


5

To be able to play .mp3 files on desktop, you'll need help from an external library to convert it first to another format. You can use NAudio (docs) to convert the audio from MP3 to WAV before playing it. You must set the API Compatiblity Level to .NET 2.0 (Edit->Project Settings->Player) Put NAudio.dll in /Assets/Plugins Create a new C# Script, name it "...


5

There's no single "best" way to do this, it depends on the needs of your game. Here are some options: Hard Coded Both the easiest and probably least flexible approach. No reason you can't just make a static class with static fields for each of the levels. Actually, this isn't a bad way to prototype, so you can move it into some other approach later. If ...


5

You can compress images individually, then align all of those into your own data file images.big, with a header index so that you can find each compressed image at runtime. The index will have the start point of each individual image file location and store names/ids if those as well. When you need to load "Image.png" from images.big, the index will tell ...


4

Here is a resource on what @""-style string literals are. Basically they turn off escaping. So, for example, you only need @"\", instead of "\\" to get the \ character. Another example: @"\t" gives you \t, whereas "\t" (no at symbol) gives you a tab character. Internally XNA handles the difference between path separator characters. You can use \ or / (or ...


4

Every time you call readLine() it moves ahead in your file. So on every loop you're actually reading 4 to 8 lines instead of 1. Once you run out of lines to read, readLine() returns null which causes the NullPointerException. change your loop to: while(true) { String str = bf.readLine(); if(str == null) { break; } if(str.contains(...


4

I don't think placing game related files in My Documents/My Games/ annoys users, it's pretty much standard to put it there so why don't you do it? Each user can have it's own save games, skins and mods this way and it's easy accessible/mod-able. However, for larger assets you do want to consider to share them amongst user accounts. I think you have two ...


3

This code is working fine for me to read the content in the text file import System.IO; var filename="data.txt"; function Start () { var sourse=new StreamReader(Application.dataPath+"/" + filename); var fileContents=sourse.ReadToEnd(); sourse.Close(); var lines=fileContents.Split("\n"[0]); for(line in lines) { print(line); }...


3

Yes, this can be solved with multithreading. Either explicitly by creating a new thread which reads and interprets a file, or implicitly by using an asynchronous file access API which calls a callback function when a file finished loading. The biggest problem with loading assets on demand is what to do when an asset is needed immediately, but it hasn't ...


3

It sounds like using a "preference" is what you need to do. It allows you to save small bits of data (like a high score, or other settings) which persist when the game is shut down. And it's a lot easier than trying to write to a file; you don't really have to concern yourself where the file is. See: http://code.google.com/p/libgdx/wiki/Preferences On ...


3

You're getting this message because the pipeline doesn't contain a content importer for a .txt file. Plain-text files generally don't require any special processing, and don't need to be converted to a binary format (which is what the content pipeline is for). There's an option in the MonoGame Pipeline Tool to set the Build Action to "Copy" instead of "...


3

You can split a string into substrings with String.Split. When you don't have any whitepsaces in that textfile but line breaks (as in no words with spaces in them) you can use string[] words = yourTextAsset.text.Split(); When you do have whitespaces, use the solution from this stackoverflow question: string[] words = yourTextAsset.text.Split( new[] { ...


2

Planning on making these map files by hand? You have 409,599 more lines to write if you want to fill a 640x640 tiled map. You should store the map in a binary format. An easy way to do that is to serialize the data structure you're storing the map with in RAM. It would be far easier to write a simple visual editor that allowed you to place tiles and ...


2

If you want to keep it with your current system, you should make a Sprite class with an array of frames (SDL_Surface/etc) that you load at the beginning of the game. Have the renderer choose the correct image based on time or some other constraint. Also, I'd advise you use sprite sheets as there is less overhead and they are generally easier to work with (...


2

So I figured out how to do this efficiently. What I do is every X minutes write all the data to a stream and delete the data file. This causes the data to not take up so much disc space. Then on application quit I write all that data from the stream to a compressed archive. I end up getting roughly 1 megabyte a minute from the Profiler, rather than 1 ...


2

If you just want to use the built in Media Player in Android, you can't play AVI files. See the list of all supported formats. If for some reason you can't convert the video to any of the supported formats, you will have to implement your own media player which has codecs etc. You can take a look at FFmpeg. It is possible to compile for Android.


2

If storage size is your main concern, using vector<bool> is probably actually your best bet. This is because vector<bool> is optimized to use one bit per bool instead of one byte (see reference here). From there for file read/write just make sure to write the capacity of the vector<bool> to file then use the same one bit per bool/spell (...


2

If you're concerned about performance, there's no reason to add additional operations to your setup. Especially operations containing hard disk read/writes as those are some of the slowest operations you can perform. Additionally, since it's running fine now, there's nothing to fix yet. You should start worrying about performance, when there's a performance ...


2

You most definitely want to use something like XML or JSON if a plist if what you're familiar with. Take a look at some of the available libraries you can use to parse either and store your data like that. A simple XML file might look like this: <Data> <NumberOfEnemies>20</NumberOfEnemies> <SpawnSpeed>60</SpawnSpeed> &...


2

Yes you can, but you're using wrong folder. The Resources folder is not copied with your build; rather, it is compressed into a single file cotaining all assets from the folder. To actually copy some files into your app, use StreamingAssets folder (http://docs.unity3d.com/Documentation/ScriptReference/Application-streamingAssetsPath.html). This folder is ...


2

risk of crashing if someone edits the file incorrectly If the configuration is invalid, then it should not work. You should verify if the data on the file is valid (e.g., It has all the fields, it does not have letters where numbers are expected, etc...) and either notify the user, load default settings or whatever is appropriate for your game. so what ...


2

Well you want to store any game assets in a place that people won't usually mess with. Putting them in the documents folder will make it likely that someone comes across them, doesn't recognise them and deletes them. Storing them in the executable file itself will result in the executable getting extremely large as you add more game assets, this isn't a ...


2

Your file is not a binary file. It contains ASCII text, starting "1e"... The value of which is 65 31 in Hex (Little endian encoded), Or 25905 in Decimal. 1e44(ascii)= 34 34 65 31 (hex) = 875849009 (dec)


Only top voted, non community-wiki answers of a minimum length are eligible