/// <summary>
        /// Shakes all global Shakers.
        /// Note that all shakers will get the same ShakeInstance, and thus will have the same shake movement.
        /// </summary>
        /// <param name="shakeData">The shake parameters such as strength, roughness and fade in/out times.</param>
        /// <param name="seed">An optional seed to use for the shake. Shakes that have the same seed will have the same movement.</param>
        /// <returns>A single ShakeInstance that all global shakers will be using for the shake. Modifying this will change it for all shakers.</returns>
        public static ShakeInstance ShakeAll(IShakeParameters shakeData, int?seed = null)
        {
            ShakeInstance shakeInstance = new ShakeInstance(shakeData, seed);

            AddShakeAll(shakeInstance);
            return(shakeInstance);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new ShakeInstance using the given ShakeData.
        /// </summary>
        /// <param name="shakeData">The ShakeData containing the shake strength, roughness, fading, and influences.</param>
        /// <param name="seed">The seed to use for the shake. Using the same seed will result in the same shake movement.</param>
        public ShakeInstance(IShakeParameters shakeData, int?seed = null) : this(seed)
        {
            //Create a copy of the shake data.
            ShakeParameters = new ShakeParameters(shakeData);

            fadeInTime  = shakeData.FadeIn;
            fadeOutTime = shakeData.FadeOut;

            State = ShakeState.FadingIn;
        }
Ejemplo n.º 3
0
        public ShakeParameters(IShakeParameters original)
        {
            shakeType = original.ShakeType;

            strength  = original.Strength;
            roughness = original.Roughness;

            fadeIn  = original.FadeIn;
            fadeOut = original.FadeOut;

            positionInfluence = original.PositionInfluence;
            rotationInfluence = original.RotationInfluence;
        }
        /// <summary>
        /// Starts a shake, using a position and distance to scale the strength of the shake.
        /// If the distance between this Shaker and the point is greater than the max distance, no shake will be applied.
        /// </summary>
        /// <param name="point">The poisition that the shake originated from.</param>
        /// <param name="maxDistance">The maximum distance the shake should have an affect.</param>
        /// <param name="shakeData">The shake parameters such as strength and roughness and fade in/out times.</param>
        /// <param name="seed">A optional seed to use for the shake. Shakes that have the same seed will have the same movement.</param>
        /// <returns>A ShakeInstance which can be used to stop the shake or modify the shake parameters.
        /// If the distance between this Shaker and the point is greater than the max distance, null will be returned.</returns>
        public ShakeInstance ShakeFromPoint(Vector3 point, float maxDistance, IShakeParameters shakeData, int?seed = null)
        {
            float distance = Vector3.Distance(transform.position, point);

            if (distance < maxDistance)
            {
                ShakeInstance shakeInstance = new ShakeInstance(shakeData, seed);
                float         scale         = 1 - Mathf.Clamp01(distance / maxDistance);
                shakeInstance.StrengthScale  = scale;
                shakeInstance.RoughnessScale = scale;
                AddShake(shakeInstance);
                return(shakeInstance);
            }

            return(null);
        }
        /// <summary>
        /// Starts a shake for all Global Shakers, using a position and distance to scale the strength of the shake.
        /// If the distance between the shaker and the point is greater than the max distance, no shake will be applied.
        /// </summary>
        /// <param name="point">The poisition that the shake originated from.</param>
        /// <param name="maxDistance">The maximum distance the shake should have an affect.</param>
        /// <param name="shakeData">The shake parameters such as strength and roughness and fade in/out times.</param>
        /// <param name="shakeInstances">An optional list that will be populated with all of the created ShakeInstances.</param>
        /// <param name="seed">A optional seed to use for the shake. Shakes that have the same seed will have the same movement.</param>
        /// If the distance between this Shaker and the point is greater than the max distance, null will be returned.</returns>
        public static void ShakeAllFromPoint(Vector3 point, float maxDistance, IShakeParameters shakeData, List <ShakeInstance> shakeInstances = null, int?seed = null)
        {
            if (shakeInstances != null)
            {
                shakeInstances.Clear();
            }

            for (int i = 0; i < GlobalShakers.Count; i++)
            {
                if (!GlobalShakers[i].gameObject.activeInHierarchy)
                {
                    continue;
                }

                ShakeInstance shakeInstance = GlobalShakers[i].ShakeFromPoint(point, maxDistance, shakeData, seed);

                if (shakeInstances != null && shakeInstance != null)
                {
                    shakeInstances.Add(shakeInstance);
                }
            }
        }
        /// <summary>
        /// Shakes all global Shakers, using a separate ShakeInstance for each Shaker.
        /// </summary>
        /// <param name="shakeData">The shake parameters such as strength, roughness and fade in/out times.</param>
        /// <param name="shakeInstances">An optional list that will be populated with all of the created ShakeInstances.</param>
        /// <param name="seed">An optional seed to use for the shake. Shakes that have the same seed will have the same movement.</param>
        /// <returns>A single ShakeInstance that all global shakers will be using for the shake. Modifying this will change it for all shakers.</returns>
        public static void ShakeAllSeparate(IShakeParameters shakeData, List <ShakeInstance> shakeInstances = null, int?seed = null)
        {
            if (shakeInstances != null)
            {
                shakeInstances.Clear();
            }

            for (int i = 0; i < GlobalShakers.Count; i++)
            {
                if (!GlobalShakers[i].gameObject.activeInHierarchy)
                {
                    continue;
                }

                ShakeInstance shakeInstance = GlobalShakers[i].Shake(shakeData, seed);

                if (shakeInstances != null && shakeInstance != null)
                {
                    shakeInstances.Add(shakeInstance);
                }
            }
        }