Пример #1
0
 void KeyboardInput()
 {
     if (_cbody && _transform)
     {
         float x = Input.GetAxis("Horizontal");
         float y = Input.GetAxis("Vertical");
         if (x != 0 || y != 0)
         {
             var dirUp   = new Vector2(_transform.up.x * y, _transform.up.y * y);
             var dirLeft = new Vector2(_transform.up.y * x, -_transform.up.x * x);
             _cbody.AddExternalVelocity((dirUp + dirLeft) * AccelForce * Time.deltaTime);
         }
         float rot = (Input.GetKey(KeyCode.Q) ? 1f : 0f) + (Input.GetKey(KeyCode.E) ? -1f : 0f);
         if (rot != 0)
         {
             _targetRotation = Quaternion.Euler(_targetRotation.eulerAngles + new Vector3(0, 0, rot));
         }
     }
 }
Пример #2
0
 void Accelerate(float force)
 {
     if (Fuel > 0 || InfiniteFuel)
     {
         if (!InfiniteFuel)
         {
             Fuel -= FuelSpendRate * SimulationControl.instance.TimeScale;
         }
         _cBody.AddExternalVelocity(_transform.right * force * Acceleration * Time.deltaTime);
         _lastAccelerationValue = force;
         if (!_isAccelerating)
         {
             StartCoroutine(TrackAcceleration());
         }
     }
     else
     {
         Fuel = 0;
     }
 }
Пример #3
0
 void KeyboardControl()
 {
     if (_selected)
     {
         var x = Input.GetAxis("Horizontal");
         var y = Input.GetAxis("Vertical");
         if (x != 0f || y != 0f)
         {
             _selected.AddExternalVelocity(new Vector2(x, y) * KeyboardSensativity * Time.deltaTime);
         }
         if (Input.GetKeyDown(KeyCode.F))
         {
             var f = Camera.main.GetComponent <SimpleFollow>();
             if (f)
             {
                 f.target  = f.target == _selected.transform ? null : _selected.transform;
                 f.enabled = f.target != null;
             }
         }
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         if (SimulationControl.instance)
         {
             if (SimulationControl.instance.TimeScale != 0)
             {
                 _savedTimeScale = SimulationControl.instance.TimeScale;
             }
             SimulationControl.instance.TimeScale = SimulationControl.instance.TimeScale == 0 ? _savedTimeScale : 0f;
         }
     }
     if (Input.GetKeyDown(KeyCode.C))
     {
         Debug.Break();
     }
 }
 private void InitializeControls()
 {
     FollowToggle.onValueChanged.AddListener((b) =>
     {
         if (!_isRefreshing)
         {
             CameraMovement.Instance.FollowTarget(b ? _currentTarget : null);
             RefreshView();
         }
     });
     VelocityValue.OnValueChangedEvent += (f) =>
     {
         if (!_isRefreshing)
         {
             if (_currentTarget != null)
             {
                 if (_currentTarget.Velocity.sqrMagnitude > 1e-4f)
                 {
                     _currentTarget.AddExternalVelocity(_currentTarget.Velocity.normalized * (f - _currentTarget.Velocity.magnitude));
                     RefreshView();
                 }
             }
         }
     };
     RelVelocityValue.OnValueChangedEvent += (f) =>
     {
         if (!_isRefreshing)
         {
             if (_currentTarget != null)
             {
                 if (_currentTarget.Velocity.sqrMagnitude > 1e-4f)
                 {
                     _currentTarget.AddExternalVelocity(_currentTarget.Velocity.normalized * (f - _currentTarget.RelativeVelocity.magnitude));
                     RefreshView();
                 }
             }
         }
     };
     MassSlider.minValue = 1;
     MassSlider.maxValue = MaxMass;
     MassSlider.onValueChanged.AddListener((f) =>
     {
         if (!_isRefreshing)
         {
             if (_currentTarget != null)
             {
                 _currentTarget.Mass = f;
                 RefreshView();
             }
         }
     });
     IsKeplerMotionToggle.onValueChanged.AddListener((b) =>
     {
         if (!_isRefreshing)
         {
             if (_currentTarget != null)
             {
                 _currentTarget.UseKeplerMotion = b;
                 var drawOrbits = DemoSceneManager.Instance.IsShowOrbits;
                 DemoSceneManager.Instance.IsShowOrbits = drawOrbits;
                 RefreshView();
             }
         }
     });
     IsDrawOrbitToggle.onValueChanged.AddListener((b) =>
     {
         if (!_isRefreshing)
         {
             if (_currentTarget != null)
             {
                 var actor = ActorsManager.Instance.FindCreatedActor(_currentTarget);
                 if (actor != null)
                 {
                     actor.OrbitDisplayRef.enabled = true;
                     if (actor.CelestialBodyRef.UseKeplerMotion)
                     {
                         if (actor.OrbitDisplayRef.LineRenderer != null)
                         {
                             actor.OrbitDisplayRef.LineRenderer.enabled = b;
                         }
                         actor.PredictionDisplayRef.enabled = false;
                     }
                     else
                     {
                         if (actor.OrbitDisplayRef.LineRenderer != null)
                         {
                             actor.OrbitDisplayRef.LineRenderer.enabled = false;
                         }
                         actor.PredictionDisplayRef.enabled = b;
                     }
                 }
             }
         }
     });
 }