Hot answers tagged

29

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 ...


19

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/...


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();")...


6

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 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 &...


6

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

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

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

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[] { ...


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 source = new StreamReader(Application.dataPath + "/" + filename); var fileContents = source.ReadToEnd(); source.Close(); var lines = fileContents.Split("\n"[0]); for(...


3

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(...


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

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)


2

No, you cannot unpack a Unity build into the source files for the project. You can decompile the managed assemblies to get equivalent C# code out of them, but it won't be exactly the code you wrote. It will likely be mangled and harder to read, lacking comments etc. You can try to extract assets like textures too, but you won't get your original files back. ...


1

Just like the error says, you can not list all assets in a classpath FileHandle. The reason you're seeing this error even though you're using an internal file handle is because internal files are added to the .jar when the game is built (where else would they go?) and as such they must be added to the classpath to be readable. This is also the reason you can'...


1

The comment from DMGregory made me realize that it was the compiler that was processing the new added file. This however only happens outside of playmode and only in the editor. With this came the other knowledge of the Resources folder not being editable in a build. And for me this would be a huge issue since players need to be able to add their own custom ...


1

Look at StreamingAssets. When you build your projects, all folders and files are packed, making it difficult, or even impossible, to edit. All except one folder. The StreamingAsset folder. Retrieve its path with Application.streamingAssetsPath This folder is not put in the package when you compiled, but stays next to it, letting anyone edit its ...


1

There are multiple ways to get some bytes of text from the client to a server. But one way to do this which should be quite platform-agnostic is with a HTTP POST Request. The Unity class you need for this is the class WWWForm to store the POST data in addition to the class WWW to make the HTTP request. The example in the official documentation shows you how ...


1

The way I do it is that I always create a new project first where I import the unity package file. I then change the structure of the project as I want it to look in my final project. Finally I select the files i want to export and then i right click on them and choose "Export as UnityPackage", Open your final project and import your newly created Unity ...


1

You could use Files.walk() along with filter(). Thus if you wanted to get all PNG images, then you could do: Path path = Paths.get(Gdx.files.getLocalStoragePath()); try { List<Path> files = Files.walk(path) .filter(filePath -> !Files.isDirectory(filePath) && filePath.toString().toLowerCase()....


1

I've managed to solve my problem converting my byte array directly in a AudioClip using the code posted by Jeff Kesselman in this topic http://answers.unity3d.com/questions/737002/wav-byte-to-audioclip.html


1

It sounds like you don't want to create a whole bunch of String instances for the GC to clean up, so how about using one or more char[] to hold the text file data?


1

Why not using a custom method to take screenshots and save them wherever you want ? I use this method in my games: private IEnumerator TakeScreenshot(string screen_path) { yield return new WaitForEndOfFrame(); int width = Screen.width; int height = Screen.height; // Creates a new texture of the size of your screen. ...


1

If your test desktop filesystem is running on Windows NTFS and the Android device filesystem is on Android native, the difference is in the filesystem drivers. The Windows filesystem drivers are not case sensitive but Android uses Linux which is case sensitive. Make sure your capitalization is correct on the file. Additionally I noticed you were using ...


1

There are already multiple similar questions, that should give you some pointers to get stared: How can I create a pack file / archive for game data files, and then load them? (zlib?) How can you put all images from a game to 1 file? How do you pack resources in a game when you have too many of them? Custom Content Package for Files One option is to use an ...


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