예제 #1
0
        public override void SetDefaults(VehicleController vc)
        {
            base.SetDefaults(vc);

            speedSensitiveSteeringCurve = new AnimationCurve(
                new Keyframe(0f, 1f, 0f, 0f),
                new Keyframe(0.3f, 0.4f, -0.6f, -0.6f),
                new Keyframe(1f, 0.2f, -0.1f, 0.1f)
                );

            linearity = new AnimationCurve(
                new Keyframe(0, 0, 1, 1),
                new Keyframe(1, 1, 1, 1));
        }
예제 #2
0
        /// <summary>
        ///     First function that gets called on all components.
        ///     VehicleController reference will be null before this function is called.
        /// </summary>
        public virtual void Awake(VehicleController vc)
        {
            this.vc      = vc;
            initialized  = false;
            wasEnabled   = false;
            fullTypeName = GetType().FullName;

            if (state == null)
            {
                state = new StateDefinition();
            }

            state.fullName = fullTypeName;
            LoadStateFromDefinitionsFile(fullTypeName, ref state);
        }
예제 #3
0
        public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool isExpanded = base.OnNUI(position, property, label);

            VehicleController vehicleController = property.serializedObject.targetObject as VehicleController;

            if (Application.isPlaying)
            {
                if (vehicleController != null && vehicleController.stateSettings != null)
                {
                    DrawStateSettingsBar(
                        position,
                        vehicleController.stateSettings.LODs.Count,
                        property.FindPropertyRelative("state.isOn"),
                        property.FindPropertyRelative("state.isEnabled"),
                        property.FindPropertyRelative("state.lodIndex"));
                }
            }

            return(isExpanded);
        }
예제 #4
0
        private void Update()
        {
            if (!_insideVehicle)
            {
                nearVehicle = false;

                if (!characterObject.activeSelf)
                {
                    characterObject.SetActive(true);
                }

                _enterExitPoints       = GameObject.FindGameObjectsWithTag(enterExitTag);
                _nearestEnterExitPoint = null;
                float nearestSqrDist = Mathf.Infinity;
                foreach (GameObject eep in _enterExitPoints)
                {
                    float sqrDist = Vector3.SqrMagnitude(characterObject.transform.position - eep.transform.position);
                    if (sqrDist < nearestSqrDist)
                    {
                        nearestSqrDist         = sqrDist;
                        _nearestEnterExitPoint = eep;
                    }
                }

                if (_nearestEnterExitPoint == null)
                {
                    return;
                }

                if (Vector3.Magnitude(Vector3.ProjectOnPlane(
                                          _nearestEnterExitPoint.transform.position - characterObject.transform.position,
                                          Vector3.up)) < enterDistance)
                {
                    nearVehicle     = true;
                    _nearestVehicle = _nearestEnterExitPoint.GetComponentInParent <VehicleController>();
                }
            }
            if (_insideVehicle)
            {
                if (_nearestVehicle.Speed > maxVelocityScript)
                {
                    damageScript.enabled = true;
                }
                else
                {
                    damageScript.enabled = false;
                }
            }

            bool any = false;

            foreach (InputProvider i in InputProvider.Instances)
            {
                if (i.ChangeVehicle())
                {
                    any = true;
                    break;
                }
            }

            if (InputProvider.Instances.Count > 0 && any)
            {
                EnterExitVehicle();
            }
        }
예제 #5
0
 public CharacterVehicleChanger(VehicleController nearestVehicle)
 {
     this._nearestVehicle = nearestVehicle;
 }
예제 #6
0
 /// <summary>
 ///     Ran when VehicleController.Validate is called.
 ///     Checks if the component setup is valid and alerts the developer if there are any issues.
 /// </summary>
 public virtual void Validate(VehicleController vc)
 {
 }
예제 #7
0
 /// <summary>
 ///     Resets component's values to defaults. Also called when Reset is called from inspector.
 /// </summary>
 public virtual void SetDefaults(VehicleController vc)
 {
 }
예제 #8
0
 /// <summary>
 ///     Equivalent to MonoBehavior's OnDrawGizmosSelected().
 /// </summary>
 public virtual void OnDrawGizmosSelected(VehicleController vc)
 {
 }
예제 #9
0
        void Update()
        {
            _vc = VehicleChanger.ActiveVehicleController;

            promptText.text = "";

            if (UnityEngine.Input.GetKeyDown(KeyCode.Tab))
            {
                _canvas.enabled = !_canvas.enabled;
            }

            if (CharacterVehicleChanger.Instance != null && CharacterVehicleChanger.Instance.nearVehicle)
            {
                promptText.text = "Press V to enter the vehicle.";
            }

            if (_vc == null)
            {
                return;
            }

            if (_vc != _prevVc)
            {
                _trailerHitchModule = VehicleChanger.ActiveVehicleController.moduleManager.GetModule <TrailerHitchModule>();
                _flipOverModule     = VehicleChanger.ActiveVehicleController.moduleManager.GetModule <FlipOverModule>();
                _absModule          = VehicleChanger.ActiveVehicleController.moduleManager.GetModule <ABSModule>();
                _tcsModule          = VehicleChanger.ActiveVehicleController.moduleManager.GetModule <TCSModule>();
                _escModule          = VehicleChanger.ActiveVehicleController.moduleManager.GetModule <ESCModule>();
                _aeroModule         = VehicleChanger.ActiveVehicleController.moduleManager.GetModule <AerodynamicsModule>();
            }

            throttleSlider.value        = Mathf.Clamp01(_vc.input.states.vertical);
            brakeSlider.value           = Mathf.Clamp01(-_vc.input.states.vertical);
            clutchSlider.value          = Mathf.Clamp01(_vc.powertrain.clutch.clutchEngagement);
            handbrakeSlider.value       = Mathf.Clamp01(_vc.input.states.handbrake);
            horizontalLeftSlider.value  = Mathf.Clamp01(-_vc.input.Horizontal);
            horizontalRightSlider.value = Mathf.Clamp01(_vc.input.Horizontal);

            if (_trailerHitchModule != null && _trailerHitchModule.trailerInRange && !_trailerHitchModule.attached)
            {
                promptText.text = "Press T to attach the trailer.";
            }

            if (_flipOverModule != null && _flipOverModule.manual && _flipOverModule.flippedOver)
            {
                promptText.text = "Press P to recover the vehicle.";
            }

            if (_absModule != null)
            {
                absButton.targetGraphic.color = _absModule.IsEnabled ? enabledColor : disabledColor;
            }

            if (_tcsModule != null)
            {
                tcsButton.targetGraphic.color = _tcsModule.IsEnabled ? enabledColor : disabledColor;
            }

            if (_escModule != null)
            {
                escButton.targetGraphic.color = _escModule.IsEnabled ? enabledColor : disabledColor;
            }

            if (_aeroModule != null)
            {
                aeroButton.targetGraphic.color = _aeroModule.IsEnabled ? enabledColor : disabledColor;
            }

            damageButton.targetGraphic.color = _vc.damageHandler.Active ? enabledColor : disabledColor;
            animationHealth    = _vc.damageHandler.Damage;
            liveConverter      = _vc.damageHandler.Damage;
            live               = -_vc.damageHandler.Damage;
            damageSlider.value = live;


            _prevVc = _vc;
        }
예제 #10
0
        public override bool OnInspectorNUI()
        {
            if (!base.OnInspectorNUI())
            {
                return(false);
            }

            vehicleController = (VehicleController)target;

            Rect awakeButtonRect = new Rect(drawer.positionRect.x + drawer.positionRect.width - 58f,
                                            drawer.positionRect.y - 20f,
                                            56f, 15f);

            // Draw logo texture
            Rect logoRect = drawer.positionRect;

            logoRect.height = 60f;
            drawer.DrawEditorTexture(logoRect, "NWH Vehicle Physics/Editor/logo_bg", ScaleMode.ScaleAndCrop);
            drawer.DrawEditorTexture(
                new Rect(logoRect.x + 8f, logoRect.y + 11f, logoRect.width - 8f, logoRect.height - 22f),
                "NWH Vehicle Physics/Editor/logo_light", ScaleMode.ScaleToFit);
            drawer.AdvancePosition(logoRect.height);

            // Draw awake button
            Color initGUIColor = GUI.color;

            GUI.color = vehicleController.IsAwake ? NUISettings.enabledColor : NUISettings.disabledColor;
            GUIStyle awakeButtonStyle = new GUIStyle(EditorStyles.miniButton);

            awakeButtonStyle.fixedHeight = 15f;

            if (Application.isPlaying)
            {
                if (GUI.Button(awakeButtonRect, vehicleController.IsAwake ? "AWAKE" : "ASLEEP", awakeButtonStyle))
                {
                    if (vehicleController.IsAwake)
                    {
                        vehicleController.Sleep();
                    }
                    else
                    {
                        vehicleController.Wake();
                    }
                }

                GUI.color = initGUIColor;

                // Draw lod text
                Rect lodRect = awakeButtonRect;
                lodRect.y += 22f;
                GUI.Label(lodRect, "LOD " + vehicleController.activeLODIndex, EditorStyles.whiteMiniLabel);
            }

            GUI.color = initGUIColor;

            // Draw toolbar
            int categoryTab = drawer.HorizontalToolbar("categoryTab",
                                                       new[] { "Sound", "FX", "Powertrain", "Control", "Modules", "Settings" }, true, true);

            drawer.Space(2);

            if (categoryTab == 0) // FX
            {
                drawer.Property("soundManager");
            }
            else if (categoryTab == 1)
            {
                int fxTab = drawer.HorizontalToolbar("fxTab",
                                                     new[] { "Effects", "Grnd. Det.", "Damage" }, true, true);
                drawer.Space(2);

                if (fxTab == 0) // Effects
                {
                    drawer.Property("effectsManager");
                }
                else if (fxTab == 1)
                {
                    drawer.Property("groundDetection");
                }
                else if (fxTab == 2)
                {
                    drawer.Property("damageHandler");
                }
            }
            else if (categoryTab == 2) // Powertrain
            {
                drawer.Property("powertrain");
            } // Powertrain
            else if (categoryTab == 3) // Control
            {
                int controlTab =
                    drawer.HorizontalToolbar("controlTab", new[] { "Input", "Steering", "Brakes" }, true, true);
                switch (controlTab)
                {
                case 0:
                    DrawInputTab();
                    break;

                case 1:
                    drawer.Property("steering");
                    break;

                case 2:
                    drawer.Property("brakes");
                    break;
                }
            }
            else if (categoryTab == 4) // Modules
            {
                DrawModulesTab(vehicleController);
            } // Modules
            else if (categoryTab == 5) // Settings
            {
                DrawSettingsTab();
            }

            DrawWarnings();

            if (drawer.totalHeight < 800)
            {
                drawer.totalHeight = 800;
            }

            drawer.EndEditor(this);
            return(true);
        }
예제 #11
0
 private void DrawModulesTab(VehicleController vc)
 {
     drawer.Property("moduleManager");
 }