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

public class LockPanelMissionHandle : MonoBehaviour
{
    public GameObject _EffectPrefab;

    public GameObject _Hand;
    public Vector3 _StartPos = new Vector3(-240, 0, 0);
    public Vector3 _EndPos = new Vector3(-453, 120, 0);
    public float _MoveTime = 0.5f;
    public float _ClickWaitTime = 1.0f;
    private readonly List<GameObject> _EffectPoolList = new List<GameObject>();

    private void OnEnable()
    {
        HideAllEffect();
        Init();
    }

    public void OnDisable()
    {
        HideAllEffect();
    }

    private void Init()
    {
        _EffectPrefab.SetActive(false);
        _Hand.transform.localPosition = _StartPos;
        var args = new Hashtable();
        args.Add("easeType", iTween.EaseType.easeOutQuad);
        args.Add("time", _MoveTime);

        args.Add("looptype", "none");
        args.Add("islocal", true);
        args.Add("position", _EndPos);

        args.Add("oncomplete", "AnimationEnd");

        iTween.MoveTo(_Hand.gameObject, args);
    }

    public void AnimationEnd()
    {
        CreateEffectPrefab();
        StartCoroutine(CreateEffect());
    }

    public void CreateEffectPrefab()
    {
        _EffectPrefab.SetActive(true);
        _EffectPrefab.transform.localPosition = new Vector3(_EndPos.x - 30, _EndPos.y + 40);
        var effectCom = _EffectPrefab.GetComponentInChildren<ParticleSystem>();
        if (effectCom == null)
            return;
        effectCom.Stop();
        effectCom.Play();
    }

    private IEnumerator CreateEffect()
    {
        yield return new WaitForSeconds(_ClickWaitTime);
        Init();
    }

    public void HideAllEffect()
    {
        for (var index = 0; index < _EffectPoolList.Count; index++) _EffectPoolList[index].gameObject.SetActive(false);
    }
}