Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/candycoded/forms
📄 Components used to simplify the handling of form inputs in Unity.
https://github.com/candycoded/forms
forms unity
Last synced: 3 months ago
JSON representation
📄 Components used to simplify the handling of form inputs in Unity.
- Host: GitHub
- URL: https://github.com/candycoded/forms
- Owner: CandyCoded
- License: mit
- Created: 2020-07-09T23:13:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-04T03:23:57.000Z (about 1 year ago)
- Last Synced: 2024-09-16T03:20:41.155Z (4 months ago)
- Topics: forms, unity
- Language: C#
- Homepage:
- Size: 104 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Forms
> Components used to simplify the handling of form inputs in Unity.
[![npm](https://img.shields.io/npm/v/xyz.candycoded.forms)](https://www.npmjs.com/package/xyz.candycoded.form)
## Installation
### Unity Package Manager
#### Git
```json
{
"dependencies": {
"xyz.candycoded.forms": "https://github.com/CandyCoded/Forms.git#v3.1.0",
...
}
}
```#### Scoped UPM Registry
```json
{
"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.
```csharp
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.
```csharp
[SerializeField]
private Form _form;
```Populate the fields with exisiting values (if applicable).
```csharp
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.
```csharp
public void Start()
{_form.LoadFromJSON(jsonString);
}
```Data can also be loaded via a `Dictionary` object.
```csharp
public void Start()
{_form.LoadFormRawValues(new Dictionary
{
{ "active", true },
{ "firstName", "Scott" },
{ "lastName", "Doxey" },
{ "age", 36 },
});}
```Create a submit event handler that takes `Dictionary` as it's only property.
```csharp
public void SubmitFormObject(Dictionary formRawValues)
{Debug.Log(formRawValues);
Debug.Log(JsonConvert.SerializeObject(formRawValues));}
```Or a submit event handler that takes `string` as it's only property.
```csharp
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).