HEADJACK
Search Results for

    Show / Hide Table of Contents

    Class CustomVariables

    Namespace: Headjack

    Properties

    availableVariables

    Get an array of all available variables in CustomVariables

    Declaration
    public static string[] availableVariables { get; }
    Property Value
    Type Description
    System.String[]

    string[] containing all available variables in Custom Variables

    Examples
    void LogAllCustomVariables()
    {
    	string[] allVariables = CustomVariables.availableVariables;
    	if (allVariables == null)
    	{
    		Debug.Log("No Custom Variables Found!");
    	}
    	else
    	{
    		foreach(string s in allVariables)
    		{
    			Debug.Log("Custom Variable Found: " + s);
    		}
    	}
    }

    Methods

    GetReturnType(String)

    The return type of a global variable

    Declaration
    public static Type GetReturnType(string variable)
    Parameters
    Type Name Description
    System.String variable

    The variable to check

    Returns
    Type Description
    System.Type

    System.Type of the variable

    Examples
    void LogFirstVariableType()
    {
    	string[] allVariables = CustomVariables.availableVariables;
    	if (allVariables == null)
    	{
    		Debug.Log("No variables found");
    	}
    	else
    	{
    		System.Type variableType = CustomVariables.GetReturnType(allVariables[0]);
    		Debug.Log("First variable's type: " + variableType);
    	}
    }

    GetVariable<T>(String, String)

    Get a variable's value

    Declaration
    public static T GetVariable<T>(string variable, string projectId = null)
    Parameters
    Type Name Description
    System.String variable

    The variable to check

    System.String projectId

    (Optional) When a "per project" variable, use this parameter

    Returns
    Type Description
    T

    The value if it was found and casted to the requisted type, the type's default value on fail

    Type Parameters
    Name Description
    T
    Remarks
    Warning

    Will throw an error on fail, but will return the default value so your code can continue

    Examples
    System.DateTime timeToStart = GetVariable<System.DateTime>("TimeToStart");
    string LanguageOfFirstProject = GetVariable<string>("Language", App.GetProjects()[0]);

    TryGetVariable<T>(String, out T, String)

    Try getting a variable's value

    Declaration
    public static bool TryGetVariable<T>(string variable, out T result, string projectId = null)
    Parameters
    Type Name Description
    System.String variable

    The variable's name

    T result

    The result will be set to this out parameter

    System.String projectId

    (Optional) When a "per project" variable, use this parameter

    Returns
    Type Description
    System.Boolean

    True if the variable was found and casted to the requisted type

    Type Parameters
    Name Description
    T
    Remarks
    Note

    result will be set to the requisted type's default value if failed

    Examples
    Color c;
    if (CustomVariables.TryGetVariable<Color>("PrimaryColor", out c))
    {
    	Debug.Log("Succes!");
    }
    string s;
    if (CustomVariables.TryGetVariable<string>("App Title", out s))
    {
    	Debug.Log("Succes!");
    }
    In This Article
    Back to top