using UnityEngine;
using WS;

public class FlowCollider : FlowBase
{
    private bool isEnter;
    public LayerMask layer;
    public Collider checkCollider;
    public Collider rayCollider;
    public string tipPoint;

    public override void StartFlow() { }

    public override void UpdateFlow()
    {
        if (isEnter)
        {
            bool isRayCast = false;
            Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
            RaycastHit[] hits = Physics.RaycastAll(ray, 100);
            for (int i = 0; i < hits.Length; i++)
            {
                if (hits[i].collider == rayCollider)
                {
                    isRayCast = true;

                    continue;
                }
            }
            FacadeComponent.Instance
                .GetController<PointController>()
                .ShowPoint(isRayCast ? 2 : 1, tipPoint);
            if (isRayCast)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    FlowManager.Inst.NextFlow();
                }
            }
        }
    }

    public void CheckPoint(Collider collider, bool isEnter)
    {
        if (collider == this.checkCollider)
        {
            this.isEnter = isEnter;

            FacadeComponent.Instance
                .GetController<PointController>()
                .ShowPoint(isEnter ? 1 : 0, tipPoint);
        }
    }
}
