Is it possible to use Resources.Load to load a textasset not ended with .txt
For example I want to load .ini or .cs files as text
No, the supported file extensions which are recognised as text assets are listed in the manual. The extension is pretty irrelevant anyways. Just use .txt
or .ini.txt
if you really want. Note that the extension .cs
wouldnât make much sense anyways. C# files need to be compiled and that happens at build time. You can not simply âloadâ a C# file dynamically. So whatâs your actual goal?
You could ship arbitrary files in the StreamingAssets folder. They are shipped with the game unaltered and they can be read through the UnityWebRequest. See the StreamingAssets manual. Though that doesnât change the fact that you have to handle the content of those files yourself.
inis are from some decade-old game containing object stats/rule set/settings that kind of stuff. Iâm doing a remake of an old game that still adapt those old inis but I donât want player to touch them easily i.e. via streamassets
Youâre off by at least three decades. The oldest instance Iâm aware of is MS-DOS in the early 80s. None of that is relevant here though. Unityâs text asset importer is looking for specific extensions but once the asset is imported those extensions have no meaning at all and it will just refer to the file by the name.
If you must have a custom text file format you can do it with a custom importer like this. Just be aware that like the builtin one once the file is imported that extension has no meaning and you wonât be referring to it any more by that extension.
using System.IO;
using UnityEngine;
using UnityEditor.AssetImporters;
[ScriptedImporter( 1, "foo" )]
public class FooImporter : ScriptedImporter {
public override void OnImportAsset( AssetImportContext ctx ) {
TextAsset subAsset = new TextAsset( File.ReadAllText( ctx.assetPath ) );
ctx.AddObjectToAsset( "text", subAsset );
ctx.SetMainObject( subAsset );
}
}
You could put them in a password protected zip file under StreamingAssets, if you donât mind embedding the zip password in the executable somewhere.
There are tools that extract assets from a Unity build so I assume you are only looking to prevent the curious user from modifying the assets, not enthusiasts.
Well thereâs your problem!!
You want water, but you donât want it to be wet.
Thatâs not a thing. And it will never be a thing.
If youâre concerned about the user âhacking your save files,â or âcheating in your game,â which is playing on their computer, just donât be.
Thereâs nothing you can do about it. Nothing is secure, it is not your computer, it is the userâs computer.
If it must be secure, store it on your own server and have the user connect to download it.
Anything else is a waste of your time and the only person youâre going to inconvenience is yourself when youâre debugging the game and you have savegame errors. Work on your game instead.
Remember, it only takes one 12-year-old in Finland to write a script to read/write your game files and everybody else can now use that script. Read about Cheat Engine to see more ways you cannot possibly control this.
If you still feel compelled to waste your own time making water not wet, by all means be my guest. But no amount of forum posting or klever trickee leet koding will change the fact that water is wet: the user has the data, itâs on their computer, they control it, they can read every single byte.
You could use encryption to somehow obfuscate the data and deter some players go further, but any determined individual would be able to decrypt it anyway. As Kurt said, your best bet would be using server-side data validation or not caring at all if itâs not a big deal for your project.
Sorry for off-topic but this reminded me of a recent headline from The Times âVolcano in iceland erupting molten lavaâ and I said, they probably have another headline elsewhere like âLeakage flooded town with wet waterâ.
Ok, so you want to include an ini file in your game and donât want the player to have âeasyâ access to it (they still can if they want, though). What exactly is your issue renaming the file to .txt
and use it as TextAsset? Is there any reason you want to keep that ini extension inside your Unity project?
Apart from that you may just convert / translate the information in that ini file into a more convenient format(JSON,ScriptableObject, âŚ). What game do we talk about? You do know that assets from other games have copyright as well, right? So just grabbing say the rules.ini of C&C Red Alert because it has well balanced units and buildings will just get you in trouble.
ps: Note that all those settings in C&C:RA were stored internally. The rules.ini could be placed in the main folder to override the built-in values. This was a specific game feature / development feature which let you modify any of those values. With those you could easily cheat the game or even create some weird units like a soldier which has a battleship cannon and can shoot across half the map ^^.
You donât even have to decrypt it yourself as the game will have to do so itself just to be able to use it. Itâs why when people want to steal textures or models from a game they do so straight from GPU as it canât render an encrypted asset so everything is stored in video memory in decrypted form.