Пример #1
0
 public void ActShakeEffect(float time, float range, float angle, int stepFrame, bool isAngleDirected, bool clearPreviousShake)
 {
     if ((this._largestShakeEntryThisFrame == null) || (range > this._largestShakeEntryThisFrame.range))
     {
         CameraShakeEntry shakeEntry = new CameraShakeEntry {
             timer            = time,
             duration         = time,
             range            = range,
             angle            = angle,
             stepFrame        = stepFrame,
             stepFrameCounter = 1,
             isAngleDirected  = isAngleDirected
         };
         int num = this._cameraShakeLs.SeekAddPosition <CameraShakeEntry>();
         this._cameraShakeLs[num] = shakeEntry;
         if ((this.SeekLargestShakeEntryIndex() == num) || clearPreviousShake)
         {
             if (clearPreviousShake)
             {
                 this._cameraShakeLs.Clear();
             }
             this.SetupShake(shakeEntry);
         }
         this._largestShakeEntryThisFrame = shakeEntry;
     }
 }
Пример #2
0
        private void UpdateCameraShake()
        {
            float timeScale = Singleton <LevelManager> .Instance.levelEntity.TimeScale;

            if (timeScale != 0f)
            {
                if (this._shakeTimer > 0f)
                {
                    this._shakeFrameCounter--;
                    if (this._shakeFrameCounter == 0)
                    {
                        this._shakeFrameCounter = this._shakeStepFrame;
                        Vector3 vector  = (Vector3)((UnityEngine.Random.insideUnitCircle.normalized * this._shakeRange) * (1f - this._shakeDirectedRatio));
                        Vector3 vector2 = this._directedShakeOffset;
                        if (!this._isAlongDirected)
                        {
                            vector2 = (Vector3)(vector2 * 0.7f);
                        }
                        Vector3 direction = this._directedShakeOffset + vector;
                        float   num2      = Mathf.Clamp((float)(this._shakeTimer / this._shakeTotalTime), (float)0.2f, (float)0.9f);
                        direction = (Vector3)(direction * (num2 * num2));
                        Vector3 vector4 = base.transform.TransformDirection(direction);
                        this._calculatedShakeOffset = vector4;
                        this._directedShakeOffset   = (Vector3)(this._directedShakeOffset * -1f);
                        this._isAlongDirected       = !this._isAlongDirected;
                    }
                    if (!this._state.muteCameraShake)
                    {
                        base.transform.position = this._calculatedShakeOffset + base.transform.position;
                    }
                }
                this._shakeTimer -= Time.unscaledDeltaTime;
                bool flag = false;
                for (int i = 0; i < this._cameraShakeLs.Count; i++)
                {
                    if (this._cameraShakeLs[i] != null)
                    {
                        CameraShakeEntry entry = this._cameraShakeLs[i];
                        entry.timer -= Time.deltaTime * timeScale;
                        if (entry.timer <= 0f)
                        {
                            this._cameraShakeLs[i] = null;
                            flag = true;
                        }
                    }
                }
                if (flag)
                {
                    int num4 = this.SeekLargestShakeEntryIndex();
                    if (num4 >= 0)
                    {
                        this.SetupShake(this._cameraShakeLs[num4]);
                    }
                }
                this._largestShakeEntryThisFrame = null;
            }
        }
Пример #3
0
        private int SeekLargestShakeEntryIndex()
        {
            int   num  = -1;
            float num2 = 0f;

            for (int i = 0; i < this._cameraShakeLs.Count; i++)
            {
                if (this._cameraShakeLs[i] != null)
                {
                    CameraShakeEntry entry = this._cameraShakeLs[i];
                    if ((entry.range * (entry.timer / entry.duration)) > num2)
                    {
                        num = i;
                    }
                }
            }
            return(num);
        }
    public void GenerateImpulse(CameraShakeType type)
    {
        if (type == CameraShakeType.None)
        {
            return;
        }

        CameraShakeEntry entry = _cameraShakeEntries.Find(e => e.Type == type);

        if (entry != null)
        {
            //Debug.Log("CameraShakeType " + type.ToString());
            entry.Source.GenerateImpulse();
            return;
        }

        Debug.LogError("CameraShakeType " + type.ToString() + " doesn't exist in controller's entries! Check CameraShakeController object!");
    }
Пример #5
0
 private void SetupShake(CameraShakeEntry shakeEntry)
 {
     this._shakeTimer         = shakeEntry.timer;
     this._shakeTotalTime     = shakeEntry.duration;
     this._shakeStepFrame     = shakeEntry.stepFrame;
     this._shakeFrameCounter  = shakeEntry.stepFrameCounter;
     this._shakeRange         = shakeEntry.range * this._state.cameraShakeRatio;
     this._shakeDirectedRatio = !shakeEntry.isAngleDirected ? 0f : 0.8f;
     if (shakeEntry.isAngleDirected)
     {
         this._directedShakeOffset = (Vector3)(Quaternion.AngleAxis(shakeEntry.angle, Vector3.forward) * Vector3.right);
         this._directedShakeOffset = (Vector3)(this._directedShakeOffset * (shakeEntry.range * this._shakeDirectedRatio));
         this._isAlongDirected     = true;
     }
     else
     {
         this._directedShakeOffset = Vector3.zero;
         this._isAlongDirected     = false;
     }
 }