using System.Threading.Tasks;
using UnityEngine;
using WS;

[ObjectSystem]
public class MoveGuideComponentLateUpdateSystem : LateUpdateSystem<MoveGuideComponent>
{
    public override void LateUpdate(MoveGuideComponent self)
    {
        self.LateUpdate();
    }
}

//移动
public class MoveGuideComponent : OperateComponent<MoveGuideData>
{
    /// <summary> 操作开始前用户位置 </summary>
    public Vector3 startPos;

    /// <summary> 移动的目标点 </summary>
    public GameObject targetPoint;

    public override void Init() { }

    public override void StartOperate()
    {
        startPos = Player.Inst.transform.position;
        targetPoint = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/TeleportPoint"));
        targetPoint.transform.position = new Vector3(
            OperateData.targetPos.x,
            0.1f,
            OperateData.targetPos.z
        );
    }

    public override void Update()
    {
        //if (VRInputComponent.Instance.GetKeyUp(VRKey.圆盘, VRHand.Any))
        //{
        //    if (
        //        Vector3.Distance(
        //            Player.Inst.rigSteamVR.transform.position,
        //            OperateData.targetPos
        //        ) <= 1f
        //    )
        //    {
        //        GameObject.Destroy(targetPoint);
        //        IsComplete = true;
        //    }
        //}
    }

    public void LateUpdate()
    {
        //if (VRInputComponent.Instance.GetKeyUp(VRKey.圆盘, VRHand.Any))
        //{
        //    if (
        //        Vector3.Distance(
        //            Player.instance.rigSteamVR.transform.position,
        //            OperateData.targetPos
        //        ) <= 1f
        //    )
        //    {
        //        GameObject.Destroy(targetPoint);
        //        IsComplete = true;
        //    }
        //}
    }

    public override void Prompt()
    {
        base.Prompt();
    }

    public override Task StartState()
    {
        GameObject startPoint = GameObject.Find("StartPoint");
        Player.Inst.transform.position = startPoint.transform.position;
        Player.Inst.transform.rotation = startPoint.transform.rotation;
        return Task.CompletedTask;
    }

    public override Task EndState()
    {
        Player.Inst.transform.position = OperateData.targetPos;
        return Task.CompletedTask;
    }
}

public class MoveGuideData
{
    public Vector3 targetPos;
}
