Пример #1
0
        // Aircraft Methods

        /* Method updates the rotation speed and aquires current control surface
         * values for each axis (x,y,z) */
        public void RotateAxis()
        {
            // Calculate rotation speed based on UI Slider value
            rotationSpeed = RotationSpeedCalc();
            // Get all of the control surfaces relevant angles normalised to
            // values between 180/-180
            float rudderInspectorFloat =
                ControlsUtilityMethods.WrapAngle(this.rudder.GetCurrentRotations().z);
            float aileronInspectorFloat =
                ControlsUtilityMethods.WrapAngle(this.rightAileron.GetCurrentRotations().y);
            float elevatorInspectorFloat =
                ControlsUtilityMethods.WrapAngle(this.rightElevator.GetCurrentRotations().y);
            // Map variables to the corresponding control surfaces
            float roll  = aileronInspectorFloat;  // ailerons (x axis)
            float pitch = elevatorInspectorFloat; // elevators (y axis)
            float yaw   = rudderInspectorFloat;   // rudder (z axis)

            // AxisRotate method rotates the aircraft on each axis individually
            // in the correct order
            AxisRotate(pitch, Vector3.up, Vector3.down);
            // y axis movement rotating either up or down
            AxisRotate(roll, Vector3.right, Vector3.left);
            // x axis movement rotating either right or left
            AxisRotate(yaw, Vector3.back, Vector3.forward);
            // z axis movment, rotating either back or forward
        }
 /* Update is called once per frame Each frame the update method is used to
  * determine the current position of each control surface, updating the text
  * box with the correct user information */
 void Update()
 {
     // update the position value
     rudderZAngle =
         ControlsUtilityMethods.WrapAngle(rudder.GetCurrentRotations().z);
     // Generate a text string for the control surface based on position
     GenerateTextDescription("rudder", rudderZAngle);
     aileronYAngle =
         ControlsUtilityMethods.WrapAngle(leftAileron.GetCurrentRotations().y);
     GenerateTextDescription("ailerons", aileronYAngle);
     elevatorYAngle =
         ControlsUtilityMethods.WrapAngle(leftElevator.GetCurrentRotations().y);
     GenerateTextDescription("elevators", elevatorYAngle);
     // Method is called to check if another UI component is covering the text box
     TextOutput();
 }
Пример #3
0
        // Rotate clouds based on aircrafts Z rotation movement, so they are
        // always moving towards aircraft
        public void RotateClouds()
        {
            float rudderInspectorFloat =
                ControlsUtilityMethods.WrapAngle(this.rudder.GetCurrentRotations().z);

            // current aircraft Z rotation
            if (rudderInspectorFloat >= 1)
            // Rotate the clouds in conjunction with the rudder, so they follow
            // the aircrafts rotation
            {
                this.cloudPivot.transform.localRotation *=
                    Quaternion.AngleAxis((rudderInspectorFloat)
                                         * rotationSpeed * Time.deltaTime, Vector3.back);
            }
            else if (rudderInspectorFloat < 0)
            {
                this.cloudPivot.transform.localRotation *=
                    Quaternion.AngleAxis((-rudderInspectorFloat)
                                         * rotationSpeed * Time.deltaTime, Vector3.forward);
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        // Add references to the control surface objects
        rudder       = ControlSurfaces.rudder;
        leftAileron  = ControlSurfaces.leftAileron;
        leftElevator = ControlSurfaces.leftElevator;

        // Get the relevant start angles for each surface
        rudderZAngle =
            ControlsUtilityMethods.WrapAngle(rudder.GetCurrentRotations().z);
        aileronYAngle =
            ControlsUtilityMethods.WrapAngle(leftAileron.GetCurrentRotations().y);
        elevatorYAngle =
            ControlsUtilityMethods.WrapAngle(leftElevator.GetCurrentRotations().y);

        /* Get the TextMeshPro via code. This text area is where description
         * text is shown to the user */
        var textArray = FindObjectsOfType <TextMeshProUGUI>();

        foreach (var element in textArray)  // loop through all text mesh pro objects
        {
            if (element.tag == "ControlsDescription")
            {   /* If the object is tagged as "ControlsDescription" the reference is stored
                 * in the variable allowing us to print directly into the text box through code */
                controlSurfaceDescriptions = element;
            }
        }

        // Get the UI text box background, enabling us to show and hide it
        controlInputDescriptionBackground =
            GameObject.Find("ControlsDescriptionBackground").GetComponent <Image>();

        // Store initial values of MenuSystem script booleans
        infoIsVisible     = MenuSystem.infoIsVisible;
        controlsIsVisible = MenuSystem.controlsIsVisible;
    }