Example #1
0
        public static ShakePosition ShakePosition(GameObject target, float duration, bool scaledTime = true)
        {
            Debug.Assert(target.activeInHierarchy, "game object must be active : " + target.name);
            var color = new ShakePosition(target, duration, scaledTime: scaledTime);

            return(color);
        }
Example #2
0
 void Start()
 {
     origin         = startPos = transform.position;
     render         = GetComponent <Renderer>();
     shakeMagnitude = new Vector2(0, 0);
     shakeDuration  = 0;
     shakePosition  = new ShakePosition(shakeFrequency, 0);
 }
Example #3
0
    void Awake()
    {
        // Cache the camera components so that they can be controlled and moved around the world.
        camera   = GetComponent <Camera>();
        camera2d = GetComponent <tk2dCamera>();

        // Add a 'ShakePosition' component to allow screen shake
        cameraShaker = gameObject.AddComponent <ShakePosition>();

        // Caches the camera's Transform for efficiency purposes
        transform = GetComponent <Transform>();
    }
Example #4
0
 private void ShakePosition_UpdateShaking(On.HutongGames.PlayMaker.Actions.ShakePosition.orig_UpdateShaking orig, ShakePosition self)
 {
     try
     {
         if (CustomShake && self.State.Name.Contains("Shake") && self.State.Fsm == shakerFSM.Fsm)
         {
             bool    value = self.isLooping.Value;
             float   num   = Mathf.Clamp01(1f - GetTimer(self) / ShakeDuration);
             Vector3 a     = Vector3.Scale(ShakeExtents, new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)));
             transform.position = GetStartingWorldPosition(self) + a * ((!value) ? num : 1f);
             //this.timer += Time.deltaTime;
             SetTimer(self, GetTimer(self) + Time.deltaTime);
             if (!value && GetTimer(self) > ShakeDuration)
             {
                 CustomShake = false;
                 StopAndReset(self);
                 self.Fsm.Event(self.stopEvent);
                 self.Finish();
             }
         }
         else if (CustomRumble && self.State.Name.Contains("Rumbling") && self.State.Fsm == shakerFSM.Fsm)
         {
             bool    value = self.isLooping.Value;
             float   num   = Mathf.Clamp01(1f - GetTimer(self));
             Vector3 a     = Vector3.Scale(RumbleExtents, new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)));
             transform.position = GetStartingWorldPosition(self) + a * ((!value) ? num : 1f);
             //this.timer += Time.deltaTime;
             SetTimer(self, GetTimer(self) + Time.deltaTime);
             if (!value && GetTimer(self) > 1f)
             {
                 CustomRumble = false;
                 StopAndReset(self);
                 self.Fsm.Event(self.stopEvent);
                 self.Finish();
             }
         }
         else
         {
             orig(self);
         }
     }
     catch (Exception e)
     {
         WeaverLog.LogError("Camera Shaker Exception = " + e);
     }
 }
Example #5
0
 private void ShakePosition_OnExit(On.HutongGames.PlayMaker.Actions.ShakePosition.orig_OnExit orig, ShakePosition self)
 {
     CustomShake = false;
     orig(self);
 }
Example #6
0
 // Start is called before the first frame update
 void Start()
 {
     shakePosition = new ShakePosition(shakeFrequency, shakeDuration);
     origin        = transform.position;
     hero          = FindObjectOfType <Hero>();
 }