<< 🎮 Demo | ⚙ Installation | 🚀 Usage | 🤝 Contributing >>
In Unity UI, UI elements typically do not provide an accessible MaterialPropertyBlock. To change material properties via animations, like with MeshRenderer, you usually need to create custom components, which are often shader-specific.
Custom properties for changing material properties are easy for experienced users but can be a high hurdle for beginners:
- Are material assets being changed directly?
- Are material instances leaking?
- Is it allocating unnecessarily every time the property changes?
- Does it support masks?
- Does it support animations?
- And so on.
This package provides a component that allows easy modification of material properties for Unity UI (uGUI) without the need for shader-specific custom components.
Key Features:
- Change UI material properties without shader-specific custom components.
- Modify material properties:
- via animation, similar to
MeshRenderer
- via tweener component
- via code
- via the inspector
- via animation, similar to
- Automatic creation and deletion of material instances.
- Instead of creating material assets with slight differences, you can create material instances and change properties.
- Share material instances by specifying a
GroupId
. - Automatic detection of shader properties.
- Supports the
Mask
component. - Supports
TextMeshProUGUI
andSubMeshUI
components. (uGUI 2.0 ready) - Good performance.
This package requires Unity 2019.4 or later.
- This package is available on OpenUPM package registry.
- This is the preferred method of installation, as you can easily receive updates as they're released.
- If you have openupm-cli installed, then run the following command in your project's directory:
openupm add com.coffee.ui-material-property-injector
- To update the package, use Package Manager UI (
Window > Package Manager
) or run the following command with@{version}
:openupm add [email protected]
- Click
Window > Package Manager
to open Package Manager UI. - Click
+ > Add package from git URL...
and input the repository URL:https://github.com/mob-sakai/UIMaterialPropertyInjector.git?path=Packages/src
- To update the package, change suffix
#{version}
to the target version.- e.g.
https://github.com/mob-sakai/UIMaterialPropertyInjector.git?path=Packages/src#1.0.0
- e.g.
-
Open the
Packages/manifest.json
file in your project. Then add this package somewhere in thedependencies
block:{ "dependencies": { "com.coffee.ui-material-property-injector": "https://github.com/mob-sakai/UIMaterialPropertyInjector.git?path=Packages/src", ... } }
-
To update the package, change suffix
#{version}
to the target version.- e.g.
"com.coffee.ui-material-property-injector": "https://github.com/mob-sakai/UIMaterialPropertyInjector.git?path=Packages/src#1.0.0",
- e.g.
- Download a source code zip file from Releases and extract it.
- Place it in your project's
Packages
directory.
- If you want to fix bugs or add features, install it as an embedded package.
- To update the package, you need to re-download it and replace the contents.
- Add the
UIMaterialPropertyInjector
component to a graphic (Image, RawImage, Text, etc.) and mark the shader properties as injectable.
- Change the properties via animation, code or tweener.
var injector = GetComponent<UIMaterialPropertyInjector>(); injector.SetFloat("_Intensity", 0.9f);
- Enjoy!
Change the material properties of the CanvasRenderer.
- Reset Values On Enable: Reset injector values with the material properties when the component is enabled.
- Animatable: Makes it animatable in the Animation view.
- Shared Group Id: Share material instances by specifying a
GroupId
.- NOTE: The material instances cannot be shared if the mask depth is different.
- Properties: Shader properties to inject.
- Click
Reset Values
to reset injector values to the material properties.
- Click
A tweener to change the material properties.
- Target: The target
UIMaterialPropertyInjector
to tween. - Curve: The curve to tween the properties.
- Delay: The delay in seconds before the tween starts.
- Duration: The duration in seconds of the tween.
- Interval: The interval in seconds between each loop.
- Restart On Enable: Whether to restart the tween when enabled.
- Wrap Mode: The wrap mode of the tween.
Clamp
: Clamp the tween value, not loop.Loop
: Loop the tween value.PingPongOnce
: PingPong the tween value, not loop.PingPong
: PingPong the tween value.
- Update Mode: Specifies how to get delta time.
Normal
: UseTime.deltaTime
.Unscaled
: UseTime.unscaledDeltaTime
.Manual
: Not updated automatically and update manually withUpdateTime
orSetTime
method.
- Properties: Shader properties to inject. The tweener interpolates two values with an animation curve.
- Click
Reset Values
to reset injector values to the material properties.
- Click
Issues are incredibly valuable to this project:
- Ideas provide a valuable source of contributions that others can make.
- Problems help identify areas where this project needs improvement.
- Questions indicate where contributors can enhance the user experience.
Pull requests offer a fantastic way to contribute your ideas to this repository.
Please refer to CONTRIBUTING.md
and develop branch for guidelines.
This is an open-source project developed during my spare time.
If you appreciate it, consider supporting me.
Your support allows me to dedicate more time to development. 😊
- MIT
- GitHub page : https://github.com/mob-sakai/UIMaterialPropertyInjector
- Releases : https://github.com/mob-sakai/UIMaterialPropertyInjector/releases
- Issue tracker : https://github.com/mob-sakai/UIMaterialPropertyInjector/issues
- Change log : https://github.com/mob-sakai/UIMaterialPropertyInjector/blob/main/CHANGELOG.md