https://github.com/mob-sakai/CompositeToggle
Composite toggle system for unity
https://github.com/mob-sakai/CompositeToggle
component style switch toggle ugui ui unity
Last synced: 5 months ago
JSON representation
Composite toggle system for unity
- Host: GitHub
- URL: https://github.com/mob-sakai/CompositeToggle
- Owner: mob-sakai
- License: mit
- Created: 2017-05-27T01:43:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-01T03:54:40.000Z (over 7 years ago)
- Last Synced: 2024-08-02T05:13:22.680Z (9 months ago)
- Topics: component, style, switch, toggle, ugui, ui, unity
- Language: C#
- Size: 166 KB
- Stars: 45
- Watchers: 4
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-unity-open-source-on-github - CompositeToggle - Composite toggle system (UI Script)
README
CompositeToggle & StyleSystem
===## Overview
CompositeToggle & StyleSystem are components that manage snapshots of properties.
They supports every properties including Image's Sprite, Graphic's Color, Text's text, GameObject's SetActive, etc...
Set values to properties you need, at same time, without other script.## Requirement
* Unity5.3+
* No other SDK## Usage
1. Download [CompositeToggle.unitypackage](https://github.com/mob-sakai/CompositeToggle/raw/master/CompositeToggle.unitypackage) and install to your project.
2. AddComponent `CompositeToggle` or `Style` to the GameObject.
3. Enjoy!## How to contorol component's properties in Unity?
In Unity, how to control Images and Text components at the same time?
How to control the properties, such as sprite, text, color or fontSize?
It's common case in game development.
Do you use UnityEvent? Unfortunately, structures such as Color are not supported.
So, we need a script as following to control the properties.The script controls 'state (On / Off)' and 'property (sprite etc.)'.
Therefore, as the state or properties increase, we need to add a script.
Considering work bottleneck and maintainability, it is not good.```cs
[SerializeField] Sprite sptireOn;
[SerializeField] Sprite sptireOff;
[SerializeField] Color colorOn;
[SerializeField] Color colorOff;
[SerializeField] int fontSizeOn;
[SerializeField] int fontSizeOff;void SwitchOn()
{
GetComponent().sprite = sptireOn;
GetComponent().color = colorOn;
GetComponent().fontSize = fontSizeOn;
}void SwitchOff()
{
GetComponent().sprite = sptireOff;
GetComponent().color = colorOff;
GetComponent().fontSize = fontSizeOff;
}
...
```## CompositeToggle
CompositeToggle implemented to separate 'state' and 'property'.
The state is defined by a script, and the property is defined by a scene or a prefab.
The script should only turn the toggle on or off. Yes, it is very simple.
```cs
[SerializeField] CompositeToggle toggle;void SetToggleValue(bool isOn)
{
toggle.booleanValue = isOn;
}
```CompositeToggle manage snapshots of properties.
Set values to properties you need, at same time, without other script.
## StyleSystem
StyleSystem collectively manages the properties of Component and separates layout and design like CSS.
A style have some properties you need, and can be referred to by multiple GameObjects.
When the properties of the style are changed, they are immediately applied to the referencing GameObjects.
In addition, styles can apply at runtime :)

## Bake Properties To Improve Performance
CompositeToggle internally uses reflection.
Reflection is slow? -Yes, that's right.
You can avoid reflection by baking the property to the script.
Bake the properties from the Style or StyleAsset inspector.
## Screenshot
* Tabs and views
* Indicator
## Release Notes
### ver.0.1.1:
* Fixed: InspectorGUI issue.
* Fixed: Demo scene.### ver.0.1.0:
* Feature: Supports every properties of all components.
* Feature: Set values to properties you need, at same time, without other script.
* Feature: Bake properties to script to improve invocation performance.
* Feature: (CompositeToggle) 4 kind of value type.
* Boolean
* Index
* Count
* Flag
* Feature: (CompositeToggle) Synchronization mode
* Parent-child relationships
* Grouping
* Sync-Other
* Feature: (CompositeToggle) Some features for every toggles.
* Comment
* GameObject activation
* UnityEvent
* Feature: (CompositeToggle) Auto grouping construction based on hierarchy children.
* Feature: (StyleSystem) Style inheritance.