Skip to content

๐Ÿ“„ Components used to simplify the handling of form inputs in Unity.

License

Notifications You must be signed in to change notification settings

CandyCoded/Forms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

65 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Forms

Components used to simplify the handling of form inputs in Unity.

npm

Installation

Unity Package Manager

https://docs.unity3d.com/Packages/[email protected]/manual/index.html

Git

{
  "dependencies": {
    "xyz.candycoded.forms": "https://github.com/CandyCoded/Forms.git#v3.1.0",
    ...
  }
}

Scoped UPM Registry

{
  "dependencies": {
    "xyz.candycoded.forms": "3.1.0",
    ...
  },
  "scopedRegistries": [
    {
      "name": "candycoded",
      "url": "https://registry.npmjs.com",
      "scopes": ["xyz.candycoded"]
    }
  ]
}

Usage

First create a class with the same field names (and data types) as the form.

public class Profile
{
    public bool active;
    public string firstName;
    public string lastName;
    public int age;
}

Add a Form property to a MonoBehaviour for storing a reference to the Form component.

[SerializeField]
private Form _form;

Populate the fields with exisiting values (if applicable).

public void Start()
{

    _form.LoadFormValues(new Profile
    {
        active = true,
        firstName = "Scott",
        lastName = "Doxey",
        age = 36
    });

}

Data can also be loaded via a JSON string object.

public void Start()
{

    _form.LoadFromJSON<Profile>(jsonString);

}

Data can also be loaded via a Dictionary<string, object> object.

public void Start()
{

    _form.LoadFormRawValues(new Dictionary<string, object>
      {
          { "active", true },
          { "firstName", "Scott" },
          { "lastName", "Doxey" },
          { "age", 36 },
      });

}

Create a submit event handler that takes Dictionary<string, object> as it's only property.

public void SubmitFormObject(Dictionary<string, object> formRawValues)
{

    Debug.Log(formRawValues);
    Debug.Log(JsonConvert.SerializeObject(formRawValues));

}

Or a submit event handler that takes string as it's only property.

public void SubmitFormJSON(string json)
{

    Debug.Log(json);

}

Attach that method to the form submitted event handler on the Form component (see screenshot below).

Note: A button can also be assigned to the form as the primary submit button (also see screenshot below).

About

๐Ÿ“„ Components used to simplify the handling of form inputs in Unity.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published