예제 #1
0
        protected override void Get(UnityUGUIContext context, AssetReferenceType realType, object realValue, Action <Texture2D> callback)
        {
            if (realType == AssetReferenceType.Url)
            {
                webDeferred = MainThreadDispatcher.StartDeferred(GetTexture(realValue as string, callback));
            }
            else if (realType == AssetReferenceType.Data)
            {
                var    base64   = realValue as string;
                byte[] fileData = Convert.FromBase64String(base64);
                var    texture  = new Texture2D(1, 1);
                texture.LoadImage(fileData);
                callback(texture);
            }
            else if (realType == AssetReferenceType.File)
            {
                var       filePath = realValue as string;
                Texture2D texture  = null;
                byte[]    fileData;

                if (File.Exists(filePath))
                {
                    fileData = File.ReadAllBytes(filePath);
                    texture  = new Texture2D(1, 1);
                    texture.LoadImage(fileData);
                }
                callback(texture);
            }
            else if (realType == AssetReferenceType.Procedural)
            {
                var color = ParserMap.ColorConverter.Convert(realValue);

                if (color is Color c)
                {
                    var t = new Texture2D(1, 1);
                    t.SetPixel(0, 0, c);
                    t.Apply();
                    callback(t);
                }
                else
                {
                    callback(null);
                }
            }
            else
            {
                base.Get(context, realType, realValue, callback);
            }
        }