Exemple #1
0
 /// <summary>
 /// Notify globla that a CameraShake happened
 /// </summary>
 /// <param name="sender"> The source of the event. </param>
 /// <param name="info"> Camera shake information </param>
 /// <param name="source"> Source of shake </param>
 public static void RaiseCameraShake(object sender, CameraShakeParams info, Vector3 source)
 {
     if (CameraShake != null)
     {
         CameraShake(sender, new CameraShakeEventArgs(new CameraShakeParams(info), source));
     }
 }
Exemple #2
0
 /// <summary>
 /// Copy parameters from another object
 /// </summary>
 /// <param name="other">CameraShakeInfo to copy parameters</param>
 public void CopyFrom(CameraShakeParams other)
 {
     this.Intensity  = other.Intensity;
     this.Roll       = other.Roll;
     this.Duration   = other.Duration;
     this.Range      = other.Range;
     this.ByDistance = other.ByDistance;
     this.TickTime   = other.TickTime;
     this.Smoothing  = other.Smoothing;
 }
Exemple #3
0
        /// <summary>
        /// Shake camera
        /// </summary>
        /// <param name="shakeInfo">Parameters of shake</param>
        /// <param name="sourceOfShake"> source of shake </param>
        public virtual void Shake(CameraShakeParams shakeInfo, Vector3 sourceOfShake)
        {
            if (shakeInfo.Enable)
            {
                if (this._Shake == null)
                {
                    this._Shake = new CameraShakeParams();
                }

                if (RelativeTo == null)
                {
                    RelativeTo = transform;
                }
                float distanceToSource = 0;
                if (shakeInfo.ByDistance)
                {
                    distanceToSource = Vector3.Distance(RelativeTo.position, sourceOfShake);
                }
                if (!shakeInfo.ByDistance || distanceToSource <= shakeInfo.Range)
                {
                    this._Shake.CopyFrom(shakeInfo);
                    if (this._Shake.Range <= Mathf.Epsilon)
                    {
                        this._Shake.Range = Mathf.Epsilon;
                    }
                    float modifier = (this._Shake.ByDistance) ? (1 - Mathf.Clamp01(distanceToSource / this._Shake.Range)) : 1.0f;
                    this._Shake.Roll      *= modifier;
                    this._Shake.Intensity *= modifier;
                    this._Shake.Smoothing  = Mathf.Max(0.1f, this._Shake.Smoothing);
                    if (this._Shake.TickTime < 0)
                    {
                        this._Shake.TickTime = 0;
                    }
                    this._ShakeTimeTW.Begin(this._Shake.Duration, RealTime);
                    this.Tick();
                    base.enabled = true;
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Create CameraShakeArgs
 /// </summary>
 /// <param name="shake"> Shake information </param>
 /// <param name="source">Source of shake</param>
 public CameraShakeEventArgs(CameraShakeParams shake, Vector3 source)
 {
     this.Shake  = shake;
     this.Source = source;
 }
Exemple #5
0
 /// <summary>
 /// Create a copy of CameraShakeInfo
 /// </summary>
 /// <param name="other">Other CameraShakeInfo to copy</param>
 public CameraShakeParams(CameraShakeParams other)
 {
     CopyFrom(other);
 }