using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Giant.Res {

    public class InstanceRequest : AssetRequest
    {
        protected AssetRequestHandle assetRequest;
        protected Vector3 positon;
        protected Quaternion rotation;

        public InstanceRequest(Vector3 _pos, Quaternion _rot) {
            positon = _pos;
            rotation = _rot;
        }

        internal override void Load()
        {
            assetRequest = AssetsMgr.LoadAsset(path, typeof(UnityEngine.GameObject));
            if (assetRequest.IsValid() && null != assetRequest.asset)
            {
                asset = GameObject.Instantiate(assetRequest.asset, positon, rotation);
            }
            else {
                error = true;
                Debug.LogError("InstanceRequest error ! asset is null ");
            }
        }

        internal override void Unload()
        {
            if (asset != null) {
                GameObject.Destroy(asset);
                asset = null;
            }

            if (assetRequest.IsValid()) {
                assetRequest.Release();
            }
        }

        //[Obsolete("请使用AssetsMgr.ReleaseInstance")]
        public override void Release()
        {
            base.Release();
            Unload();
        }
    }
}
