using Sirenix.OdinInspector;
using UnityEngine;
using DG.Tweening;

namespace mGame
{
    public class BubbleTransmitter : MonoBehaviour
    {
        [FoldoutGroup("Component")] public Transform resetPos;
        [FoldoutGroup("Component")] public Rotater rotater;

        [FoldoutGroup("Setting")] public float resetTime = .1f;
        [FoldoutGroup("Setting")] public Vector3 transDir;
        [FoldoutGroup("Setting")] public float transPower = 10f;

        
        private void OnTriggerEnter(Collider other)
        {
            if(other.TryGetComponent(out mPS.FlayerVelUnit velUint))
            {
                
                velUint.transform.DOMove(resetPos.position, resetTime)
                    .SetEase(Ease.OutCubic)
                    .OnComplete(()=>velUint.SetImpulseVelocityOverWrite(transDir.normalized * transPower));
            }
        }

        private void OnMouseDrag()
        {
            transDir = MGameManager.Instance.mousePos - resetPos.position;
            transDir.y = 0;

            rotater.DoRotate(transDir);
        }
    }
}

