private SpriteLoadingHandle(AssetInstance asset, SpriteAssetAssignment assignment, string path)
 {
     m_asset                  = asset;
     m_path                   = path;
     m_assignment             = new WeakReference <SpriteAssetAssignment>(assignment);
     m_asset.OnStatusChanged += OnAssetStatusChanged;
 }
 private static void TryApplySprite(SpriteAssetAssignment assignment, AssetInstance spriteAsset)
 {
     if (spriteAsset.Status == AssetRefObject.AssetStatus.DONE)
     {
         spriteAsset.IncRef();
         assignment.Apply(spriteAsset.UnityObject as Sprite);
     }
 }
        public SpriteLoadingHandle RequestSprite(SpriteAssetAssignment assignment, string path, bool sync = false)
        {
            SpriteLoadingHandle ret = null;

            if (m_sprites.TryGetValue(path, out var spriteAsset))
            {
                if (spriteAsset.Status == AssetRefObject.AssetStatus.DESTROYED)
                {
                    m_sprites.Remove(path);
                }
                else
                {
                    if (spriteAsset.IsFinished)
                    {
                        TryApplySprite(assignment, spriteAsset);
                    }
                    else
                    {
                        ret = SpriteLoadingHandle.Create(assignment, spriteAsset, path);
                    }
                    return(ret);
                }
            }

            if (sync)
            {
                var reference = AssetService.Get().Load(path, typeof(Sprite));
                spriteAsset = reference.Asset;
                TryApplySprite(assignment, spriteAsset);
            }
            else
            {
                var loadHandle = AssetService.Get().LoadAsync(path, typeof(Sprite));
                spriteAsset = loadHandle.Asset;
                ret         = SpriteLoadingHandle.Create(assignment, spriteAsset, path);
            }

            m_sprites.Add(path, spriteAsset);
            return(ret);
        }
 public static SpriteLoadingHandle Create(SpriteAssetAssignment assignment, AssetInstance asset, string path)
 {
     return(new SpriteLoadingHandle(asset, assignment, path));
 }