Wanzyee Studio
VariableTweaker

Save variable values serialized by Json.NET to a specified file, or load it back. More...

Inherits MonoBehaviour.

Public Member Functions

void Save ()
 Save all variable values in a text file. More...
 
bool Load ()
 Load and apply all variable values from file. More...
 

Static Public Member Functions

static string Serialize (bool readable, params VariableInfo[] variables)
 Serialize all variable values to a JSON string. More...
 
static void Deserialize (string json, params VariableInfo[] variables)
 Deserialize a JSON string generated by Serialize(). More...
 
static string GetTargetText (VariableInfo variable)
 Get the text describes the target of specified VariableInfo. More...
 
static string GetTooltipText (VariableInfo variable)
 Get the text of the tooltip attribute of specified VariableInfo. More...
 
static string GetMemberText (VariableInfo variable, bool type=true)
 Get the text describes the member of specified VariableInfo. More...
 

Public Attributes

bool reloadOnAwake = true
 Flag if to auto load and save when Awake(). More...
 
string file
 The unique file path to save and load values. More...
 
bool encrypt
 Flag if save values with encrypted text. More...
 

Properties

VariableInfo[] variables [get]
 Get all the VariableInfo of this. More...
 

Detailed Description

Save variable values serialized by Json.NET to a specified file, or load it back.

Variable could be a field or property of a UnityEngine.Component, or a static one of some runtime type. It's also able to drag objects to the list to select multiple variables.

Member Function Documentation

static string Serialize ( bool  readable,
params VariableInfo[]  variables 
)
static

Serialize all variable values to a JSON string.

Optional to format to an indented multiline text with readable variable information. Otherwise, return a single line text include value series only.

Parameters
readableIf set to true readable.
variablesVariables.
Returns
The JSON string.
static void Deserialize ( string  json,
params VariableInfo[]  variables 
)
static

Deserialize a JSON string generated by Serialize().

Deserialize values in turn to apply all variables. This'll throw a combined exception at last if any failed, for partial valid apply done.

Parameters
jsonJSON string.
variablesVariables.
static string GetTargetText ( VariableInfo  variable)
static

Get the text describes the target of specified VariableInfo.

Return name or path of UnityEngine.Object, otherwise type name.

Parameters
variableVariable.
Returns
The target text.
static string GetTooltipText ( VariableInfo  variable)
static

Get the text of the tooltip attribute of specified VariableInfo.

Parameters
variableVariable.
Returns
The tooltip text.
static string GetMemberText ( VariableInfo  variable,
bool  type = true 
)
static

Get the text describes the member of specified VariableInfo.

Include member name, and the index if reflect to array element. Optional to append value type, and enum values if it is.

Parameters
variableVariable.
typeIf set to true append value type name.
Returns
The member text.
void Save ( )

Save all variable values in a text file.

The load operation depends on the order of content in the result file. Be careful while editing the file manually in need.

bool Load ( )

Load and apply all variable values from file.

Return false silently if file not existed, otherwise return if all applied. The operation depends on the order of content in the source file. Be careful while editing the file manually in need.

Returns
true if all values is deserialized and set.

Member Data Documentation

bool reloadOnAwake = true

Flag if to auto load and save when Awake().

string file

The unique file path to save and load values.

bool encrypt

Flag if save values with encrypted text.

Property Documentation

VariableInfo [] variables
get

Get all the VariableInfo of this.

This guarantees every element within is existed and read-writable. Otherwise, throw exception when generating. It's better to check VariableInfo.isValid before accessing it in need.