playMaker

Author Topic: Cinemachine Support [ECOSYSTEM] [MAY 2020]  (Read 16399 times)

Twood

  • Junior Playmaker
  • **
  • Posts: 68
Re: Cinemachine Support [ECOSYSTEM] [MAY 2020]
« Reply #45 on: January 02, 2022, 04:12:56 PM »
Why no reply? I still need it.
Or it cannot be done? If so, I will use alternative way by myself.

@samsss Your request was a while ago, but I recently made that C# script for myself to change Cinemachine noise levels while using PM.

To use it first make sure you have enabled Basic Perlin Channel Noise on the Noise setting of this Cinemachine camera, then put this script on it.

Assign the camera object where it asks, and it has open settings for 3 different noise levels.

To start a noise level in-game, you use the Call Method action in Playmaker and the CinemachineNoiseAdjust script you just placed as target, and you will see the different noise profiles as method names in a dropdown.

You could also change the values directly with Set Property on the script, but make sure you Call Method any time you want to update the value. In that case you'd probably just one only one set of the variables and one method and can ignore the others.
« Last Edit: January 02, 2022, 04:32:34 PM by Twood »

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 230
    • Haven Made
Re: Cinemachine Support [ECOSYSTEM] [MAY 2020]
« Reply #46 on: January 18, 2022, 03:11:56 PM »
Thanks for this Twood! :D

Twood

  • Junior Playmaker
  • **
  • Posts: 68
Re: Cinemachine Support [ECOSYSTEM] [MAY 2020]
« Reply #47 on: January 25, 2022, 01:21:52 AM »
No prob. It's probably much better to build it as a playmaker action instead of doing it this way. I will likely be doing that at some point.

Twood

  • Junior Playmaker
  • **
  • Posts: 68
Re: Cinemachine Support [ECOSYSTEM] [MAY 2020]
« Reply #48 on: January 25, 2022, 05:30:47 PM »
Update. I turned cinemachine noise adjustment into a Playmaker action.

Coding is NOT my main thing so let me know if I'm doing anything weird, but it runs fine for me in Unity.

Code: [Select]
using UnityEngine;


namespace HutongGames.PlayMaker.Actions.ecosystem.cinemachine

{
    [ActionCategory("Cinemachine")]
    [Tooltip("Allows you to adjust noise on a Cinemachine camera that has perlin noise enabled.")]


    public class CinemachineNoiseAdjust : FsmStateAction
    {

       
        [CheckForComponent(typeof(Cinemachine.CinemachineVirtualCamera))]
        [RequiredField]
        public Cinemachine.CinemachineVirtualCamera vcam;
        private Cinemachine.CinemachineBasicMultiChannelPerlin noiseChannel;
       

        public FsmFloat Amplitude;

        public FsmFloat Frequency;

        public FsmBool everyFrame;

        private bool goEveryFrame;
        private float goAmplitude;
        private float goFrequency;

         
        public override void OnEnter()

        {
            goAmplitude = Amplitude.Value;
            goFrequency = Frequency.Value;
            goEveryFrame = everyFrame.Value;


            vcam.GetCinemachineComponent<Cinemachine.CinemachineBasicMultiChannelPerlin>().m_AmplitudeGain = goAmplitude;
            vcam.GetCinemachineComponent<Cinemachine.CinemachineBasicMultiChannelPerlin>().m_FrequencyGain = goFrequency;

            if (!goEveryFrame)
            Finish();

        }

        public override void OnUpdate()
        {
            base.OnUpdate();
            if (goEveryFrame == true)
            {
                goAmplitude = Amplitude.Value;
                goFrequency = Frequency.Value;
                goEveryFrame = everyFrame.Value;


                vcam.GetCinemachineComponent<Cinemachine.CinemachineBasicMultiChannelPerlin>().m_AmplitudeGain = goAmplitude;
                vcam.GetCinemachineComponent<Cinemachine.CinemachineBasicMultiChannelPerlin>().m_FrequencyGain = goFrequency;
            }

        }

        public override void Reset()
        {
            Amplitude = null;
            Frequency = null;
            vcam = null;
            noiseChannel = null;
            goFrequency = 0;
            goAmplitude = 0;
            everyFrame = false;
            goEveryFrame = false;

        }

    }
}