void Start()
 {
     mandelbrot  = FindObjectOfType <MandelbrotGen>();
     applyShader = FindObjectOfType <ApplyShader>();
 }
Ejemplo n.º 2
0
        public IEnumerator AddEffect(string effect)
        {
            const float time = 60f;

            CameraEffects camEffect;

            try
            {
                camEffect = (CameraEffects)Enum.Parse(typeof(CameraEffects), effect, true);
            }
            // Couldn't parse the effect, we'll go with a random one (at least for now).
            catch (ArgumentException)
            {
                var values = (CameraEffects[])Enum.GetValues(typeof(CameraEffects));

                camEffect = values[Random.Range(0, values.Length)];
            }

            tk2dCamera tk2dCam = GameCameras.instance.tk2dCam;
            UCamera    cam     = GameCameras.instance.tk2dCam.GetAttr <tk2dCamera, UCamera>("_unityCamera");

            switch (camEffect)
            {
            case CameraEffects.Zoom:
            {
                tk2dCam.ZoomFactor = 5f;
                _activeEffects    |= camEffect;

                yield return(new WaitForSecondsRealtime(time / 6));

                tk2dCam.ZoomFactor = 1f;
                _activeEffects    &= ~camEffect;

                break;
            }

            case CameraEffects.Invert:
            {
                ApplyShader ivc = cam.gameObject.GetComponent <ApplyShader>() ?? cam.gameObject.AddComponent <ApplyShader>();

                ivc.CurrentMaterial = _invertMat;
                ivc.enabled         = true;

                yield return(new WaitForSecondsRealtime(time));

                ivc.enabled = false;

                break;
            }

            case CameraEffects.Pixelate:
            {
                Pixelate pix = cam.gameObject.GetComponent <Pixelate>() ?? cam.gameObject.AddComponent <Pixelate>();

                pix.mainCamera ??= cam;
                pix.enabled = true;

                yield return(new WaitForSecondsRealtime(time));

                pix.enabled = false;

                break;
            }

            case CameraEffects.Backwards:
            {
                float prev_z = cam.transform.position.z;
                float new_z  = cam.transform.position.z + 80;

                /*
                 * When you get hit, spell control tries to reset the camera.
                 * This camera reset moves the camera super far back in z
                 * and as a result you get an unusable black screen.
                 *
                 * This prevents that.
                 */
                void PreventCameraReset(SetPosition.orig_DoSetPosition orig, HutongGames.PlayMaker.Actions.SetPosition self)
                {
                    if (self.Fsm.Name == "Spell Control" && self.Fsm.ActiveState.Name == "Reset Cam Zoom")
                    {
                        return;
                    }

                    orig(self);
                }

                SetPosition.DoSetPosition += PreventCameraReset;

                cam.transform.SetPositionZ(new_z);

                Quaternion prev_rot = cam.transform.rotation;

                // Rotate around the y-axis to flip the vector.
                cam.transform.Rotate(Vector3.up, 180);

                _activeEffects |= CameraEffects.Mirror;

                // Much shorter than the other effects due to it being a lot harder to play around
                yield return(new WaitForSecondsRealtime(time / 4));

                SetPosition.DoSetPosition -= PreventCameraReset;

                _activeEffects ^= CameraEffects.Mirror;

                // Reset the camera.
                cam.transform.rotation = prev_rot;
                cam.transform.SetPositionZ(prev_z);

                break;
            }

            default:
                _activeEffects |= camEffect;
                yield return(new WaitForSecondsRealtime(time));

                _activeEffects &= ~camEffect;
                break;
            }
        }