Esempio n. 1
0
    public override void OnUpdate(AutoPilot ap)
    {
        /*
         * if(Counter == 0f){
         *      armoriserHUD.StartHUD(ap);
         * }else{
         *      armoriserHUD.StartUpHUD(ap, Counter);
         * }
         * Counter += 2f;
         * if(Counter > 361f){
         *      armoriserHUD.ContinueRend(ap);
         * }
         * armoriserHUD.SearchObject(ap);
         */

        /*
         * ap.Print(0,ap.GetFlightTime());
         * ap.Print(1,ap.GetVelocity().y);
         * ap.Print(2,Mathf.Floor(ap.GetSpeed()) * 3800 / 1000);
         * ap.Print(3,Counter);
         */

        //データロード
        if (Input.GetKey(KeyCode.F7) && Input.GetKey(KeyCode.LeftAlt))
        {
            if (PushedTab == false)
            {
                ReadAssignFile(ap);
                PushedTab = true;
            }
        }
        else
        {
            PushedTab = false;
        }



        if (Input.GetKey(AimAssist))
        {
            if (IsPushedAlpha2 == false && isAiming == false)
            {
                isAiming       = true;
                IsPushedAlpha2 = true;
            }
            else if (IsPushedAlpha2 == false && isAiming == true)
            {
                isAiming       = false;
                IsPushedAlpha2 = true;
            }
        }
        else
        {
            IsPushedAlpha2 = false;
        }
        if (Input.GetKey(BoostKey))
        {
            if (IsPushedF == false)
            {
                if (IsboostMode == false)
                {
                    IsboostMode = true;
                }
                else if (IsboostMode == true)
                {
                    IsboostMode = false;
                }
                IsPushedF = true;
            }
        }
        else
        {
            IsPushedF = false;
        }
        if (Input.GetKey(ChangeOptKey))
        {
            if (IsPushedKeyPad5 == false)
            {
                if (RancherMode == false)
                {
                    RancherMode = true;
                }
                else if (RancherMode == true)
                {
                    RancherMode = false;
                }
                if (AimingOpt == false)
                {
                    AimingOpt = true;
                }
                else if (AimingOpt == true)
                {
                    AimingOpt = false;
                }
                IsPushedKeyPad5 = true;
            }
        }
        else
        {
            IsPushedKeyPad5 = false;
        }
        if (Input.GetKey(AimKey))
        {
            if (IsPushedT == false)
            {
                if (Aiming == false)
                {
                    Aiming = true;
                }
                else if (Aiming == true)
                {
                    Aiming = false;
                }
                IsPushedT = true;
            }
        }
        else
        {
            IsPushedT = false;
        }
        if (Input.GetKey(LauncherKey))
        {
            if (IsPushedKeypad4 == false)
            {
                if (IsSGMode == false)
                {
                    IsSGMode = true;
                }
                else if (IsSGMode == true)
                {
                    IsSGMode = false;
                }
                IsPushedKeypad4 = true;
            }
        }
        else
        {
            IsPushedKeypad4 = false;
        }


        if (AimingOpt == false)
        {
            if (Input.GetKey(Wep1))
            {
                if (IsSGMode == false)
                {
                    ap.StartAction("Main", 1);
                }
                else if (IsSGMode == true)
                {
                    ap.StartAction("SG", 1);
                }
            }
            if (Input.GetKey(Wep2) && Input.GetKey(Wep3))
            {
                ap.StartAction("Sub2", 1);
            }
            else
            {
                if (Input.GetKey(Wep2))
                {
                    ap.StartAction("Sword", 1);
                }
                if (Input.GetKey(Wep3))
                {
                    ap.StartAction("Sub", 1);
                }
            }
        }
        else
        {
            if (Input.GetKey(Wep1))
            {
                if (IsSGMode == false)
                {
                    ap.StartAction("OptWepF1", 2);
                }
                else
                {
                    ap.StartAction("OptWepF5", 2);
                }
            }
            if (Input.GetKey(Wep2) && Input.GetKey(Wep3))
            {
                ap.StartAction("OptWepF4", 2);
            }
            else
            {
                if (Input.GetKey(Wep2))
                {
                    ap.StartAction("OptWepF2", 2);
                }
                if (Input.GetKey(Wep3))
                {
                    ap.StartAction("OptWepF3", 2);
                }
            }
        }


        if (ChangeAim == true)
        {
            if (Aiming == true && AimingOpt == false)
            {
                if (isChengedAiming == false)
                {
                    ap.StartAction("Aim", -1);
                    ap.EndAction("OptWep");
                    isChengedAiming    = true;
                    isChengedAimingOpt = false;
                }
            }
            else if (Aiming == true && AimingOpt == true)
            {
                if (isChengedAimingOpt == false)
                {
                    ap.StartAction("OptWep", -1);
                    ap.EndAction("Aim");
                    isChengedAiming    = false;
                    isChengedAimingOpt = true;
                }
            }
            else
            {
                ap.EndAction("OptWep");
                ap.EndAction("Aim");
                isChengedAiming    = false;
                isChengedAimingOpt = false;
            }
        }
        else
        {
            if (Aiming == true && AimingOpt == false)
            {
                if (isChengedAiming == false)
                {
                    ap.StartAction("Aim", -1);
                    ap.EndAction("OptWep");
                    isChengedAiming    = true;
                    isChengedAimingOpt = false;
                }
            }
            else if (Aiming == true && AimingOpt == true)
            {
                if (isChengedAimingOpt == false)
                {
                    ap.StartAction("OptWep", -1);
                    isChengedAiming    = false;
                    isChengedAimingOpt = true;
                }
            }
            else
            {
                ap.EndAction("OptWep");
                ap.EndAction("Aim");
                isChengedAiming    = false;
                isChengedAimingOpt = false;
            }
        }

        if (RancherMode == true)
        {
            if (Input.GetKey(Missile))
            {
                ap.StartAction("Launcher", 1);
            }
        }
        else
        {
            if (Input.GetKey(Missile))
            {
                ap.StartAction("Missile2", 1);
            }
        }


        if (ap.GetFlightTime() <= 0.5f)
        {
            if (Input.GetKey(MoveF) || Input.GetKey(MoveB) || Input.GetKey(MoveL) || Input.GetKey(KeyCode.E))
            {
                ap.StartAction("AnyAssig", 1);
            }

            if (Input.GetKey(MoveB) == false)
            {
                if (Input.GetKey(MoveF) == false)
                {
                    if (Input.GetKey(MoveL))
                    {
                        ap.StartAction("ThrustF", 1);
                        ap.StartAction("MoveL", 1);
                        ap.StartAction("WalkF", 1);
                    }
                    if (Input.GetKey(KeyCode.E))
                    {
                        ap.StartAction("ThrustF", 1);
                        ap.StartAction("MoveR", 1);
                        ap.StartAction("WalkF", 1);
                    }
                }
                else
                {
                    if (Input.GetKey(MoveL) || Input.GetKey(KeyCode.E))
                    {
                        if (Input.GetKey(MoveL))
                        {
                            ap.StartAction("ThrustF", 1);
                            ap.StartAction("MoveF", 1);
                            ap.StartAction("MoveL", 1);
                            ap.StartAction("WalkF", 1);
                        }
                        if (Input.GetKey(KeyCode.E))
                        {
                            ap.StartAction("ThrustF", 1);
                            ap.StartAction("MoveF", 1);
                            ap.StartAction("MoveR", 1);
                            ap.StartAction("WalkF", 1);
                        }
                    }
                    else
                    {
                        ap.StartAction("ThrustF", 1);
                        ap.StartAction("MoveF", 1);
                        ap.StartAction("WalkF", 1);
                    }
                }
            }
            else
            {
                if (Input.GetKey(MoveL) || Input.GetKey(KeyCode.E))
                {
                    if (Input.GetKey(MoveL))
                    {
                        ap.StartAction("ThrustB", 1);
                        ap.StartAction("MoveR", 1);
                        ap.StartAction("MoveB", 1);
                        ap.StartAction("WalkF", 1);
                    }
                    if (Input.GetKey(KeyCode.E))
                    {
                        ap.StartAction("ThrustB", 1);
                        ap.StartAction("MoveL", 1);
                        ap.StartAction("MoveB", 1);
                        ap.StartAction("WalkF", 1);
                    }
                }
                else
                {
                    ap.StartAction("ThrustB", 1);
                    ap.StartAction("MoveB", 1);
                    ap.StartAction("WalkF", 1);
                }
            }

            if (IsboostMode == true)
            {
                ap.EndAction("ThrustF");
                ap.EndAction("ThrustB");
                if (Input.GetKey(MoveF))
                {
                    ap.StartAction("SlideF", 20);
                    ap.EndAction("MoveF");
                }
                if (Input.GetKey(MoveB))
                {
                    ap.StartAction("SlideB", 1);
                    ap.EndAction("MoveB");
                }
                if (Input.GetKey(MoveL))
                {
                    ap.StartAction("SlideF", 20);
                    ap.StartAction("MoveL", 1);
                }
                if (Input.GetKey(KeyCode.E))
                {
                    ap.StartAction("SlideF", 20);
                    ap.StartAction("MoveR", 1);
                }
                if (Input.GetKey(MoveU))
                {
                    ap.StartAction("SlideU", 1);
                    ap.StartAction("SlideF", 20);
                    ap.EndAction("MoveU");
                }
                else if (ap.GetVelocity().y < 0)
                {
                    ap.StartAction("SlideU", 1);
                    ap.StartAction("SlideF", 20);
                    ap.EndAction("MoveU");
                }
                if (Input.GetKey(MoveD))
                {
                    //ap.StartAction("SlideD", 1);
                    //ap.EndAction("MoveD");
                }
            }
            else
            {
                if (ap.CheckAction("ThrustF"))
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                }
                else if (ap.CheckAction("ThrustB"))
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("ThrustB", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("ThrustB", 1);
                    }
                }
                else
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                }
            }
        }
        else
        {
            if (ap.GetGroundClearance() > 3)
            {
                ap.StartAction("FryMode", 1);
            }

            if (Input.GetKey(MoveF) || Input.GetKey(MoveB) || Input.GetKey(MoveL) || Input.GetKey(KeyCode.E))
            {
                ap.StartAction("AnyAssig", 1);
            }

            if (Input.GetKey(MoveB) == false)
            {
                if (Input.GetKey(MoveF) == false)
                {
                    if (Input.GetKey(MoveL))
                    {
                        ap.StartAction("ThrustF", 1);
                        ap.StartAction("MoveUL", 1);
                    }
                    if (Input.GetKey(KeyCode.E))
                    {
                        ap.StartAction("ThrustF", 1);
                        ap.StartAction("MoveUR", 1);
                    }
                }
                else
                {
                    if (Input.GetKey(MoveL) || Input.GetKey(KeyCode.E))
                    {
                        if (Input.GetKey(MoveL))
                        {
                            ap.StartAction("ThrustF", 1);
                            ap.StartAction("MoveUF", 1);
                            ap.StartAction("MoveUL", 1);
                        }
                        if (Input.GetKey(KeyCode.E))
                        {
                            ap.StartAction("ThrustF", 1);
                            ap.StartAction("MoveUF", 1);
                            ap.StartAction("MoveUR", 1);
                        }
                    }
                    else
                    {
                        ap.StartAction("ThrustF", 1);
                        ap.StartAction("MoveUF", 1);
                    }
                }
            }
            else
            {
                if (Input.GetKey(MoveL) || Input.GetKey(KeyCode.E))
                {
                    if (Input.GetKey(MoveL))
                    {
                        ap.StartAction("ThrustB", 1);
                        ap.StartAction("MoveULB", 1);
                        ap.StartAction("MoveUB", 1);
                    }
                    if (Input.GetKey(KeyCode.E))
                    {
                        ap.StartAction("ThrustB", 1);
                        ap.StartAction("MoveURB", 1);
                        ap.StartAction("MoveUB", 1);
                    }
                }
                else
                {
                    ap.StartAction("ThrustB", 1);
                    ap.StartAction("MoveUB", 1);
                }
            }



            if (IsboostMode == true)
            {
                ap.EndAction("ThrustF");
                ap.EndAction("ThrustB");
                if (Input.GetKey(MoveF))
                {
                    ap.StartAction("SlideF", 20);
                    ap.EndAction("MoveUF");
                }
                if (Input.GetKey(MoveB))
                {
                    ap.StartAction("SlideB", 1);
                    ap.EndAction("MoveB");
                }
                if (Input.GetKey(MoveL))
                {
                    ap.StartAction("SlideF", 20);
                    ap.EndAction("MoveL");
                }
                if (Input.GetKey(KeyCode.E))
                {
                    ap.StartAction("SlideF", 20);
                    ap.EndAction("MoveR");
                }
                if (ap.CheckAction("SlideF"))
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("SlideF", 20);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("SlideF", 20);
                    }
                }
                else if (ap.CheckAction("SlideB"))
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("SlideB", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("SlideB", 1);
                    }
                }
                else
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("SlideF", 20);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("SlideF", 20);
                    }
                }
            }
            else
            {
                if (ap.CheckAction("ThrustF"))
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                }
                else if (ap.CheckAction("ThrustB"))
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("ThrustB", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("ThrustB", 1);
                    }
                }
                else
                {
                    if (Input.GetKey(MoveU))
                    {
                        ap.StartAction("MoveU", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                    else if (Input.GetKey(MoveD))
                    {
                        ap.StartAction("MoveD", 1);
                        ap.StartAction("ThrustF", 1);
                    }
                }
            }
        }


        if (isAiming)
        {
            SavedVelocity  = new Vector3(Mathf.Lerp(SavedVelocity.x, ap.GetVelocity().normalized.x, 0.5f), Mathf.Lerp(SavedVelocity.y, ap.GetVelocity().normalized.y, 0.5f), Mathf.Lerp(SavedVelocity.z, ap.GetVelocity().normalized.z, 0.5f));
            ray            = new Ray(ap.AddVec(ap.GetPosition(), ap.MulVec(ap.GetCameraForward(), 10f)), ap.AddVec(ap.GetCameraForward(), ap.MulVec(SavedVelocity, 0.1f)));
            targetPosition = ray.GetPoint(1000f);
            ap.DrawLine3D(Color.yellow, ray.origin, targetPosition);
            if (Physics.Raycast(ray.origin, ray.direction, out hit, 1000f))
            {
                ap.Print(4, hit.transform.name);
                if (ap.MeasureClearance((int)(ap.AddVec(ap.GetCameraForward(), ap.MulVec(SavedVelocity, 0.05f)).x * 1000), (int)(ap.AddVec(ap.GetCameraForward(), ap.MulVec(SavedVelocity, 0.05f)).y * 1000), (int)(ap.AddVec(ap.GetCameraForward(), ap.MulVec(SavedVelocity, 0.05f)).z * 1000), (int)hit.distance + 50) != 9999)
                {
                    ap.DrawLine3D(Color.red, ap.GetPosition(), targetPosition);
                }
                else
                {
                    ap.DrawLine3D(Color.green, ap.GetPosition(), targetPosition);
                }
            }
            else
            {
                ap.DrawLine3D(Color.red, ap.GetPosition(), targetPosition);
            }
        }

        Vector2 MachineForward       = new Vector2(ap.GetForward().x, ap.GetForward().z);
        Vector2 CameraForward        = new Vector2(ap.GetCameraForward().x, ap.GetCameraForward().z);
        float   DotVariable          = Vector2.Dot(MachineForward.normalized, CameraForward.normalized);
        int     CalcAngleRWithCamera = ap.CalcAngleR(ap.GetCameraPosition());

        ap.Log(DotVariable);
        if (DotVariable < 0.6f)
        {
            if (CalcAngleRWithCamera < 0)
            {
                ap.StartAction("TurnR", 1);
            }
            else
            {
                ap.StartAction("TurnL", 1);
            }
        }
        else if (DotVariable < 0.8f)
        {
            if (CalcAngleRWithCamera < 0)
            {
                ap.StartAction("TurnR2", 1);
            }
            else
            {
                ap.StartAction("TurnL2", 1);
            }
        }
        else if (DotVariable < 0.98f)
        {
            if (CalcAngleRWithCamera < 0)
            {
                ap.StartAction("TurnR3", 1);
            }
            else
            {
                ap.StartAction("TurnL3", 1);
            }
        }

        /*
         * int DotVariable = ap.CalcAngleR(ap.GetCameraPosition());
         * ap.Log(DotVariable);
         * if(DotVariable > -90 && DotVariable < 90){
         *      if(ap.CalcAngleR(ap.GetCameraPosition()) < 0){
         *              ap.StartAction("TurnR", 2);
         *      }else{
         *              ap.StartAction("TurnL", 2);
         *      }
         * }else if(DotVariable > -170 && DotVariable < 170){
         *      if(ap.CalcAngleR(ap.GetCameraPosition()) < 0){
         *              ap.StartAction("TurnR2", 2);
         *      }else{
         *              ap.StartAction("TurnL2", 2);
         *      }
         * }else if(DotVariable > -175 && DotVariable < 175){
         *      if(ap.CalcAngleR(ap.GetCameraPosition()) < 0){
         *              ap.StartAction("TurnR3", 2);
         *      }else{
         *              ap.StartAction("TurnL3", 2);
         *      }
         * }
         */
    }