Skip to content

mob-sakai/CompositeToggle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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.

compositetoggle_switch

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.

[SerializeField] Sprite sptireOn;
[SerializeField] Sprite sptireOff;
[SerializeField] Color colorOn;
[SerializeField] Color colorOff;
[SerializeField] int fontSizeOn;
[SerializeField] int fontSizeOff;

void SwitchOn()
{
    GetComponent<Image>().sprite = sptireOn;
    GetComponent<Image>().color = colorOn;
    GetComponent<Text>().fontSize = fontSizeOn;
}

void SwitchOff()
{
    GetComponent<Image>().sprite = sptireOff;
    GetComponent<Image>().color = colorOff;
    GetComponent<Text>().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.

compositetoggle_property

[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.

compositetoggle_selectproperty

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.

stylesystem_inspector

In addition, styles can apply at runtime :)

style_pp

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.

image

Screenshot

  • Tabs and views
    compositetoggle_tabs

  • Indicator
    compositetoggle_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.

Releases

No releases published

Packages

No packages published

Languages