upm add package dev.upm-packages.cafu.numberrenderer
Note: upm
command is provided by this repository.
You can also edit Packages/manifest.json
directly.
{
"dependencies": {
// (snip)
"dev.upm-packages.cafu.numberrenderer": "[latest version]",
// (snip)
},
"scopedRegistries": [
{
"name": "Unofficial Unity Package Manager Registry",
"url": "https://upm-packages.dev",
"scopes": [
"dev.upm-packages"
]
}
]
}
Setup GameObjects and Components to render images.
Setup Installer.
- Add
NumberRendererInstaller
to some Context.- This installer exposes
INumberRenderer
interface. - If you want to use
async
withIAsyncNumberRenderer
interface, addAsyncNumberRendererInstaller
instead ofNumberRendererInstaller
.
- This installer exposes
- Choose
Renderer Type
to use to render all digits.SpriteRenderer
: UsingUnityEngine.SpriteRenderer
.UIImage
: UsingUnityEngine.UI.Image
.UIRawImage
: UsingUnityEngine.UI.RawImage
.
- Put renderers into
Renderers
field.- Renderer components type must match to
Renderer Type
. - Please arrange the displayed numbers from left to right.
- Renderer components type must match to
- Put images into
Sprites
field orTextures
field.- You must put
Sprites
if you chooseSpriteRenderer
orUIImage
atRenderer Type
. - You must put
Textures
if you chooseUITexture
atRenderer Type
.
- You must put
- Choose
Empty Digit Type
to specify how to handle empty digits.None
: Nothing to do.DestroyGameObject
: Destroy GameObject related to empty image components.DestroyImmediateGameObject
: Destroy GameObject related to empty image components immediately.DeactivateGameObject
: InvokeGameObject.SetActive(false)
on GameObject related to empty image components.DestroyComponent
: Destroy empty image components.DestroyImmediateComponent
: Destroy empty image components immediately.DisableComponent
: Setfalse
toBehaviour.enabled
of empty image components.Transparent
: SetColor.clear
toMaterial
orGraphic.color
of empty image components.ZeroFill
: Render0
image into empty image components.
- Check
Should Render Initial Value
if you want to render initial value. - Input initial value to
Initial Value
field.
Invoke INumberRenderer.Render()
to render images.
using CAFU.NumberRenderer;
public class Foo
{
public Foo(INumberRenderer numberRenderer)
{
NumberRenderer = numberRenderer;
}
private INumberRenderer NumberRenderer { get; }
public void Run()
{
NumberRenderer.Render(123);
}
}
You can also invoke asynchronous with IAsyncNumberRenderer.RenderAsync()
to use Addressable.AssetReferenceSprite
or Addressable.AssetReferenceTexture
instead of to use Sprite
or Texture
directly.
using CAFU.NumberRenderer;
using UniRx.Async;
public class Bar
{
public Bar(IAsyncNumberRenderer asyncNumberRenderer)
{
AsyncNumberRenderer = asyncNumberRenderer;
}
private IAsyncNumberRenderer AsyncNumberRenderer { get; }
public async UniTask RunAsync(CancellationToken cancellationToken = default)
{
await AsyncNumberRenderer.RenderAsync(123, cancellationToken);
}
}