using System;
using System.Collections;
using System.Collections.Generic;
using MPStudio;
using UnityEngine;
using UnityEngine.EventSystems;

//Author: SkyAllen Email: 894982165@qq.com Website: www.ytn0.com

[RequireComponent(typeof(RotateShake),typeof(HideFadeOut))]
public class UILock : MonoBehaviour,IPointerClickHandler
{
    public AudioNameEnum lockAudioName;
    public AudioNameEnum unLockAudioName;
    
    private RotateShake rs;
    private HideFadeOut hf;
    private void Awake()
    {
        hf = GetComponent<HideFadeOut>();
        hf.isSp = false;
        rs = GetComponent<RotateShake>();
        rs.enabled = false;
        rs.speed = 5;
        rs.maxAngle = 30;
    }

    void Start()
    {
       // Animal();
    }

    
    //不要叫Animal，叫LockAnimal可以父亲可以向下传播给lock
   public void  LockAnimal()
    {
        print(rs.speed);
        AudioManager.Inst.EffectPlayByEnum(lockAudioName);
        IEnumerator IE()
        {
            rs.enabled = true;
            yield return new  WaitForSeconds(0.35f);
            rs.enabled = false;
            transform.localRotation=Quaternion.Euler(new Vector3(0,0,0));
        }

        StartCoroutine(IE());
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        LockAnimal();
    }

    //不要再取Hide，避免递归调用
    public void HideLock()
    {
        AudioManager.Inst.EffectPlayByEnum(unLockAudioName);
        SendMessage("Hide");
    }
}
