#if !COMBAT_SERVER
using System.Collections;
using System.Collections.Generic;
using Fort23.Core;
using UnityEngine;
using UnityEngine.UI;
using Utility;
public class AssetHandle 
{
    public T AssetObject<T>() where T : Object
    {
        return (T) _assetObject;
    }

    private Object _assetObject;

    public bool IsRelease;

    public AssetLoadTaskBasic Associate;
    public AssetInfo AssetInfo;

    public bool IsNull()
    {
        return _assetObject==null;
    }

    public int count
    {
        get { return Associate.HandCount; }
    }

    public void Init(AssetLoadTaskBasic assetLoadTaskBasicBasic, Object assetObject)
    {
        _assetObject = assetObject;
        Associate = assetLoadTaskBasicBasic;
    }

    public void Release()
    {
        if (IsRelease)
        {
            return;
        }

        IsRelease = true;
        Associate?.RemoveAssetHandle(this);
    }

    public async CTask<AssetHandle>  InstantiateSync(bool isUseSynchronous)
    {
        if (Associate == null)
        {
            return null;
        }

        return await Associate.InstantiateSync(isUseSynchronous);
    }

    public bool IsActivation()
    {
        return !IsRelease && _assetObject != null;
    }

    public void ReleaseUI()
    {
        Release();
    }

    public Sprite GetSprite()
    {
        return AssetObject<Sprite>();
    }
}
#endif