Skip to content

ismslv/Unity_CFG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity_CFG

Screenshot A simple class to store different settings in .fmcfg (or any other extension) plain text format.

Version 1.53 supports the following data formats:

string, int, float, bool, KeyCode, string/int/float/bool/KeyCode arrays and lists, Vector2, Vector2Int, Vector3, Vector3Int and randoms between two (see the usage example).

New in this version: generic Enums.

Usage

Store settings in .fmcfg file like this:

#Config.fmcfg

BoardSize = 10:10 #Size of the board: width, height
TurnsTotal = 128
HeroName = "Captain Jack"
HeroStartHealth = 0.1:0.9
ExitKey = Esc

To be able to fold regions in VSCode

#> World settings
Setting1 = 1
Setting2List = 2,1,3
#<

Spells

#name Hardcore

Defines a config name to show in the debugger

#stop

Stops config reading at this line.

If placed on top, disables all file and does not register it's name.

key, mouse, joystick, axisbutton

Autocompletes the lists of input values.

Keys according to Unity KeyCodes

Mouse: Left, Right, Middle

Joystick and axisbutton add support for FMLHT input module (link will be here upon a release)

Adding to a project

To get these settings, add CFGLoader component and call it:

CFG.Load(cfgfilepath);
//or, to reload when testing
CFGLoader.LoadConfig();

string name = CFG.S("HeroName");
int turns = CFG.I("TurnsTotal");
Vector2Int size = CFG.V2I("BoardSize");
float healthHero1 = V2Rand("HeroStartHealth");
float healthHero2 = V2Rand("HeroStartHealth");

Also, it automatically loads if flag "loadOnAwake" is set on true.

String option "configFile" sets the base name (by default, "Config").

Then, "Config.fmcfg" will carry base configurations. You can also add any amount of additional "Config_test1.fmcfg" files, that will be loaded upon the base, overwriting what doubles.

Generic enums

To parse generic enums:

CharacterState state = CFG.E<CharacterState>("Hero_StateStart");
CharacterState[] states = CFG.AE<CharacterState>("Monster_StatesOrder");