Exemplo n.º 1
0
 public void AnimateWheelsAndTracksPosition(TimeUpdateEvent evt, ChassisAnimationNode node)
 {
     if (((GraphicsSettings.INSTANCE.CurrentQualityLevel > 1) || !node.Entity.HasComponent <SelfTankComponent>()) ? ((GraphicsSettings.INSTANCE.CurrentQualityLevel > 1) && node.cameraVisibleTrigger.IsVisibleAtRange(50f)) : true)
     {
         ChassisAnimationComponent chassisAnimation = node.chassisAnimation;
         TrackController           leftTrack        = node.chassisTrackController.LeftTrack;
         TrackController           rightTrack       = node.chassisTrackController.RightTrack;
         leftTrack.highDistance  = chassisAnimation.highDistance;
         leftTrack.lowDistance   = chassisAnimation.lowDistance;
         rightTrack.highDistance = chassisAnimation.highDistance;
         rightTrack.lowDistance  = chassisAnimation.lowDistance;
         Transform transform = node.tankVisualRoot.transform;
         if (chassisAnimation.additionalRaycastsEnabled)
         {
             leftTrack.AnimateWithAdditionalRays(transform, chassisAnimation.smoothSpeed, chassisAnimation.maxStretchingCoeff);
             rightTrack.AnimateWithAdditionalRays(transform, chassisAnimation.smoothSpeed, chassisAnimation.maxStretchingCoeff);
         }
         else
         {
             leftTrack.Animate(transform, chassisAnimation.smoothSpeed, chassisAnimation.maxStretchingCoeff);
             rightTrack.Animate(transform, chassisAnimation.smoothSpeed, chassisAnimation.maxStretchingCoeff);
         }
     }
 }
Exemplo n.º 2
0
 public void AnimateWheelsAndTracksRotation(TimeUpdateEvent evt, AliveChassisAnimationNode node)
 {
     if (node.cameraVisibleTrigger.IsVisibleAtRange(50f))
     {
         ChassisAnimationComponent chassisAnimation = node.chassisAnimation;
         TrackComponent            track            = node.track;
         TrackController           leftTrack        = node.chassisTrackController.LeftTrack;
         TrackController           rightTrack       = node.chassisTrackController.RightTrack;
         float maxSpeed  = node.effectiveSpeed.MaxSpeed;
         float deltaTime = evt.DeltaTime;
         this.CalculateTrackAnimationSpeed(track.LeftTrack, node, maxSpeed, deltaTime);
         chassisAnimation.LeftTrackPosition += (track.LeftTrack.animationSpeed * deltaTime) * 0.5f;
         leftTrack.UpdateWheelsRotation(chassisAnimation.LeftTrackPosition);
         this.CalculateTrackAnimationSpeed(track.RightTrack, node, maxSpeed, deltaTime);
         chassisAnimation.RightTrackPosition += (track.RightTrack.animationSpeed * deltaTime) * 0.5f;
         rightTrack.UpdateWheelsRotation(chassisAnimation.RightTrackPosition);
         if (chassisAnimation.TracksMaterial != null)
         {
             float   num4   = -chassisAnimation.RightTrackPosition * chassisAnimation.tracksMaterialSpeedMultiplyer;
             Vector2 vector = new Vector2((-chassisAnimation.LeftTrackPosition * chassisAnimation.tracksMaterialSpeedMultiplyer) % 1f, num4 % 1f);
             chassisAnimation.TracksMaterial.SetVector(TankMaterialPropertyNames.TRACKS_OFFSET, vector);
         }
     }
 }
        private TrackController ConstructController(TrackBindingData data, Transform root)
        {
            TrackController controller = new TrackController();

            TrackPoint[] pointArray = new TrackPoint[data.trackPointsJoints.Length];
            for (int i = 0; i < data.trackPointsJoints.Length; i++)
            {
                Transform trackPoint       = data.trackPointsJoints[i];
                Vector3   position         = data.trackPointsPositions[i];
                Vector3   trackPointOffset = root.InverseTransformPoint(trackPoint.position) - position;
                pointArray[i] = new TrackPoint(position, trackPoint, trackPointOffset);
            }
            controller.trackPoints = pointArray;
            MovingWheel[] wheelArray = new MovingWheel[data.movingWheelsJoints.Length];
            for (int j = 0; j < data.movingWheelsJoints.Length; j++)
            {
                MovingWheel wheel;
                Transform   transform2 = data.movingWheelsJoints[j];
                int         index      = data.movingWheelsNearestTrackPointsIndices[j];
                if (index < 0)
                {
                    wheel = new MovingWheel(transform2);
                }
                else
                {
                    Vector3 vector3 = data.trackPointsPositions[index];
                    wheel = new MovingWheel(transform2, pointArray[index], root.InverseTransformPoint(transform2.position) - vector3);
                }
                if (data.movingWheelsRadiuses != null)
                {
                    wheel.radius = data.movingWheelsRadiuses[j];
                }
                wheelArray[j] = wheel;
            }
            controller.movingWheels = wheelArray;
            Wheel[] wheelArray2 = new Wheel[data.rotatingWheelsJoints.Length];
            for (int k = 0; k < data.rotatingWheelsJoints.Length; k++)
            {
                Wheel wheel2 = new Wheel(data.rotatingWheelsJoints[k]);
                if (data.rotatingWheelsRadiuses != null)
                {
                    wheel2.radius = data.rotatingWheelsRadiuses[k];
                }
                wheelArray2[k] = wheel2;
            }
            controller.rotatingWheels = wheelArray2;
            if (data.trackPointsJoints.Length <= 1)
            {
                controller.segments = new TrackSegment[0];
            }
            else
            {
                TrackSegment[] segmentArray = new TrackSegment[data.trackPointsJoints.Length - 1];
                int            index        = 1;
                while (true)
                {
                    if (index >= data.trackPointsJoints.Length)
                    {
                        controller.segments = segmentArray;
                        break;
                    }
                    TrackPoint a       = pointArray[index - 1];
                    TrackPoint b       = pointArray[index];
                    Vector3    vector5 = data.trackPointsPositions[index - 1];
                    Vector3    vector6 = data.trackPointsPositions[index];
                    Vector3    vector7 = vector6 - vector5;
                    segmentArray[index - 1] = new TrackSegment(a, b, vector7.magnitude);
                    index++;
                }
            }
            controller.centerX = data.centerX;
            return(controller);
        }