Ejemplo n.º 1
0
    void InitMovePlayerByMarkSpeed()
    {
        Transform tran = AiPathScript.transform;

        Transform[] tranArray = new Transform[2];
        tranArray[0] = transform;
        tranArray[1] = tran.GetChild(MarkCount);
//		Debug.Log("Unity:"+"InitMovePlayerByMarkSpeed -> path "+AiPathScript.name
//		          +", mark "+tranArray[1].name);

        if (tranArray[1] == XkGameCtrl.GetInstance().GmCamMark.transform)
        {
            QuanShuCount++;
            if (QuanShuCount > 1)
            {
                XkGameCtrl.GetInstance().AddPlayerQuanShu();
            }
        }

        EndPos = tranArray[1].position;
        AiMark markScript = tranArray[1].GetComponent <AiMark>();

        AimMvToMarkTran = markScript.transform;
        if (EndPos == tranArray[0].position)
        {
            //move to next mark point
            SpeedA = markScript.GetMvSpeed();
            MovePlayerOnCompelteITween();
            return;
        }

        PathNodes = AiPathScript.GetPathNodes(MarkCount);
        if (PathNodes == null)
        {
            Debug.Log("Unity:" + "PathNodes is null! MarkCount " + MarkCount);
            return;
        }

        EndPos         = PathNodes[1];
        ForwardMoveVal = Vector3.Normalize(EndPos - tranArray[0].position);
        SpeedB         = markScript.GetMvSpeed();
        float disVal   = 0f;
        int   maxNodes = PathNodes.Length;

        for (int i = 1; i < maxNodes; i++)
        {
            disVal += Vector3.Distance(PathNodes[i - 1], PathNodes[i]);
        }

        float timeVal = (2f * disVal) / (SpeedA + SpeedB);

        TimeRotation = timeVal;
        if (SpeedB != SpeedA)
        {
            JiaSuDuVal = ((SpeedB - SpeedA) * (SpeedA + SpeedB)) / (2f * disVal);
        }
        else
        {
            JiaSuDuVal = 0f;
        }
        RotationStart = tranArray[0].rotation;
        RotationEnd   = tranArray[1].rotation;
//		Debug.LogError("Unity:"+"SpeedA *** "+SpeedA+", MarkCount "+MarkCount+", maxNodes "+maxNodes);
//		Debug.LogWarning("Unity:"+"SpeedA *** "+SpeedA+", SpeedB "+SpeedB);
        if (!IsStartMovePlayerByMark)
        {
            StartCoroutine(MovePlayerByMarkSpeed());
            IsStartMovePlayerByMark = true;
        }
    }
    void InitMovePlayerByMarkSpeed()
    {
        Transform tran = AiPathScript.transform;

        Transform[] tranArray = new Transform[2];
        tranArray[0] = transform;
        tranArray[1] = tran.GetChild(MarkCount);

        EndPos = tranArray[1].position;
        AiMark markScript = tranArray[1].GetComponent <AiMark>();

        if (markScript != null)
        {
            SetCameraMarkInfo(markScript);
        }

        if (MarkCount == 0)
        {
            //make camera movce to first point.
            transform.rotation = tranArray[1].rotation;
            transform.position = EndPos;
            EndPos             = tranArray[0].position;
        }

        if (EndPos == tranArray[0].position)
        {
            //move to next mark point
            SpeedA = markScript.GetMvSpeed();
            MovePlayerOnCompelteITween();
            return;
        }

        PathNodes = AiPathScript.GetPathNodes(MarkCount);
        if (PathNodes == null)
        {
            Debug.Log("PathNodes is null! MarkCount " + MarkCount);
            return;
        }

        EndPos         = PathNodes[1];
        ForwardMoveVal = Vector3.Normalize(EndPos - tranArray[0].position);
        SpeedB         = markScript.GetMvSpeed();
        float disVal   = 0f;
        int   maxNodes = PathNodes.Length;

        for (int i = 1; i < maxNodes; i++)
        {
            disVal += Vector3.Distance(PathNodes[i - 1], PathNodes[i]);
        }

        float timeVal = (2f * disVal) / (SpeedA + SpeedB);

        TimeRotation = timeVal;
        if (SpeedB != SpeedA)
        {
            JiaSuDuVal = ((SpeedB - SpeedA) * (SpeedA + SpeedB)) / (2f * disVal);
        }
        else
        {
            JiaSuDuVal = 0f;
        }
        RotationStart = tranArray[0].rotation;
        RotationEnd   = tranArray[1].rotation;
//		Debug.LogError("SpeedA *** "+SpeedA+", MarkCount "+MarkCount+", maxNodes "+maxNodes);
//		Debug.LogWarning("SpeedA *** "+SpeedA+", SpeedB "+SpeedB);
        if (!IsStartMovePlayerByMark)
        {
            gameObject.SetActive(true);
            StartCoroutine(MovePlayerByMarkSpeed());
            IsStartMovePlayerByMark = true;
        }
    }