- Home /
Simple modding via importation of text files and jpgs
I'm looking to write a moddable puzzle game. Each piece in the game has a set of simple properties (easily described with numeric codes), plus a jpg texture that gets wrapped around the piece. The game will have 2-5 built-in puzzles, but I'd like to give users the ability to design new puzzle pieces, and new puzzles.
For example, you could describe a new puzzle with a text file of the form:
PieceName = "NewPiece#1"
NumPiecesInGame = 4
Property_1 = 6
Property_2 = 3
... {more piece-wise properties}
TexFilename = "Texture_NewPiece01.jpg"
PieceName = "NewPiece#2"
... {info for NewPiece#2}
... {info for any other pieces in this user-defined puzzle}
So I'd like to be able to have the user select an arbitrary folder, and then a text file within the folder. The compiled game would then read the given text file, import the jpg textures, and setup the puzzle, creating the set of polyhedral-pieces as described within the text file, and skinning them using the specified jpgs.
It seems that one can read text files, and update numeric values (e.g. here). Then this talks about modding via DLL, and this links to a page on Resource Folders and Asset Bundles. But all three of those things (DLL, Resource Folders, Asset Bundles) require some programming expertise. I'd like to have a simpler system, one that requires only text files and paint programs.
Is the sort of modding I've described doable in Unity? Is it doable with javascript? Other options/issues I may be overlooking?
P.S. I'm a pretty good programmer (C++, R), but this will be my first foray into gaming. I've never before worked with either Unity or javascript. Hence, my questions about what is possible in Unity.
Answer by Loius · Jan 18, 2013 at 12:47 AM
Using System.IO
(Google for ".Net System IO file", probably no quotes, for good reference material) lets you read and write arbitrary files. I've used text files in the editor with no problems, and as far as I can tell, you can read files on a machine from the standalone player as well.
The Web player is forbidden from accessing any files on the user's machine (outside of PlayerPrefs, I think?). If you're going for web moddability you'd need a server, otherwise .txt files should work just fine.
Reading image files is a little more complex, but there are likely code snippets for any format you might want.
Answer by TimBur · Jan 18, 2013 at 02:20 AM
Thanks Loiuzein.
It's a standalone game. So the Web player issue won't matter for me.
I'm glad to know that the text part will work. I'm still a little concerned about the jpgs. Even if I can load them, is it possible to dynamically change textures? Once I've loaded the jpg, are there methods to specify textures for game objects at runtime?
There certainly are - check out Texture2D in the Scripting Reference
Also use the comment button for comments :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613091125im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Strange smearing on texture with unity 4.3.4 1 Answer
Perlin Noise and Terrain Generation 1 Answer
Apply uv coordinates to unity cube by script 1 Answer
GUI Info button not displaying 1 Answer