Пример #1
0
        public override void Update(float deltaTime, Camera cam)
        {
            if (hasLight == null)
            {
                List <LightComponent> lightComponents = item.GetComponents <LightComponent>();

                if (lightComponents != null && lightComponents.Count > 0)
                {
                    lightComponent = lightComponents.Find(lc => lc.Parent == this);
                    hasLight       = (lightComponent != null);
                }
                else
                {
                    hasLight = false;
                }
            }

            this.cam = cam;

            if (reload > 0.0f)
            {
                reload -= deltaTime;
            }

            ApplyStatusEffects(ActionType.OnActive, deltaTime, null);

            if (minRotation == maxRotation)
            {
                return;
            }

            float targetMidDiff = MathHelper.WrapAngle(targetRotation - (minRotation + maxRotation) / 2.0f);

            float maxDist = (maxRotation - minRotation) / 2.0f;

            if (Math.Abs(targetMidDiff) > maxDist)
            {
                targetRotation = (targetMidDiff < 0.0f) ? minRotation : maxRotation;
            }

            float deltaRotation = MathHelper.WrapAngle(targetRotation - rotation);

            deltaRotation = MathHelper.Clamp(deltaRotation, -0.5f, 0.5f) * 5.0f;

            rotation += deltaRotation * deltaTime;

            float rotMidDiff = MathHelper.WrapAngle(rotation - (minRotation + maxRotation) / 2.0f);

            if (rotMidDiff < -maxDist)
            {
                rotation = minRotation;
            }
            else if (rotMidDiff > maxDist)
            {
                rotation = maxRotation;
            }

            if ((bool)hasLight)
            {
                lightComponent.Rotation = rotation;
            }
        }