forked from zhzl/UIBinding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncRawImage.cs
36 lines (30 loc) · 1001 Bytes
/
SyncRawImage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.IO;
using UnityEngine;
using UnityEngine.UI;
namespace UIBinding
{
public class SyncRawImage : ISyncProperty
{
private RawImage image;
private Color oColor;
private string textureName;
public void SyncProperty(Component uiComponent, object vmPropertyValue, BindingContext bindingContext)
{
var texturePath = vmPropertyValue.ToString();
image = uiComponent as RawImage;
oColor = image.color;
textureName = Path.GetFileName(texturePath);
image.color = Color.clear;
bindingContext.LoadAssetAsync<Texture>(texturePath, texture =>
{
if (image == null)
return;
if (texture != null && texture.name.Equals(textureName, System.StringComparison.Ordinal))
{
image.texture = texture;
}
image.color = oColor;
});
}
}
}