// Start is called before the first frame update
 void Start()
 {
     Parent        = transform.parent.gameObject;
     CurrentCamera = FollowCamera;
     brain         = MainCamera.GetComponent <Cinemachine.CinemachineBrain>();
     mixingCamera  = GetComponent <Cinemachine.CinemachineMixingCamera>();
 }
Example #2
0
 public virtual void StartAnimation()
 {
     AnimatorRef.SetBool("IsStart", true);
     Cinemachine.CinemachineBrain brain = Camera.main.gameObject.GetComponent <Cinemachine.CinemachineBrain>();
     brain.m_UpdateMethod      = Cinemachine.CinemachineBrain.UpdateMethod.LateUpdate;
     brain.m_BlendUpdateMethod = Cinemachine.CinemachineBrain.BrainUpdateMethod.LateUpdate;
 }
    public void OnLevelLoad(Scene scene)
    {
        if (scene.name != "HUB scene" && scene.name != "Main Menu")
        {
            runningUI    = GameObject.Find("RunningUI");
            finishUI     = GameObject.Find("FinishUI");
            escapeUI     = GameObject.Find("EscapeUI");
            startUI      = GameObject.Find("StartUI");
            deathUI      = GameObject.Find("DeathUI");
            escapeText   = GameObject.Find("RunningUI/Escape Text");
            escapeBars   = GameObject.Find("RunningUI/Escape Bars");
            commandMenu  = GameObject.Find("RunningUI/Commands Group");
            subCommMenu  = GameObject.Find("RunningUI/Commands Group/Command Panel");
            subCommMenu1 = GameObject.Find("RunningUI/Commands Group/Command Sub-Panel");
            subCommMenu2 = GameObject.Find("RunningUI/Commands Group/Command Context Panel");
            virtCam      = Camera.main.gameObject.GetComponent <Cinemachine.CinemachineBrain>();
            RunningUISet();
            escapeMenuOpen = false;
        }

        if (scene.name == "HUB scene")
        {
            missionUI     = GameObject.Find("HUBUI/Missions Panel");
            loadoutUI     = GameObject.Find("HUBUI/Loadout Panel");
            inventoryUI   = GameObject.Find("HUBUI/Inventory Panel");
            informationUI = GameObject.Find("HUBUI/Information Panel");
        }
    }
Example #4
0
 private void Start()
 {
     if (player == null)
     {
         Debug.LogError("No player transform connected to: " + this.name);
     }
     if (_im == null)
     {
         _im = InputManager.instance;
     }
     if (_pc == null)
     {
         _pc = player.GetComponentInParent <PlayerController>();
     }
     if (_lm == null)
     {
         _lm = LevelManager.instance;
     }
     if (_cb == null)
     {
         _cb = GetComponent <Cinemachine.CinemachineBrain>();
     }
     if (_cb != null)
     {
         _cb.m_DefaultBlend.m_Time = cameraTransitionTime;
     }
 }
 /*
  * public override void FadeOut()
  * {
  *  GameController.Instance.SetTargetCameraSettings(GameController.CameraStatusE.Center);
  *  GameController.Instance.PlayerCharacter.transform.position = PlayerPosition.transform.position;
  *  GameController.Instance.PlayerCharacter.transform.SetParent(PlayerPosition.transform, true);
  *  GameController.Instance.PlayerCharacter.SetAnimationBool("IsIdle", false);
  *  AnimatorRef.SetTrigger("FadeOut");
  * }
  */
 public override void StartAnimation()
 {
     AnimatorRef.SetBool("IsStart", true);
     SoundManager.Instance.PlayMusicClip(Music, true);
     Cinemachine.CinemachineBrain brain = Camera.main.gameObject.GetComponent <Cinemachine.CinemachineBrain>();
     brain.m_UpdateMethod      = Cinemachine.CinemachineBrain.UpdateMethod.LateUpdate;
     brain.m_BlendUpdateMethod = Cinemachine.CinemachineBrain.BrainUpdateMethod.LateUpdate;
 }
Example #6
0
 public void SetBrainBlendTime(float time)
 {
     Cinemachine.CinemachineBrain brain = FindObjectOfType <Cinemachine.CinemachineBrain>();
     if (brain != null)
     {
         brain.m_DefaultBlend.m_Time = time;
     }
 }
Example #7
0
 public void SetBrainBlendStyleToEase()
 {
     Cinemachine.CinemachineBrain brain = FindObjectOfType <Cinemachine.CinemachineBrain>();
     if (brain != null)
     {
         brain.m_DefaultBlend.m_Style = Cinemachine.CinemachineBlendDefinition.Style.EaseInOut;
     }
 }
Example #8
0
 public void DeactivateCamera()
 {
     Cinemachine.CinemachineBrain brain = Camera.main.gameObject.GetComponent <Cinemachine.CinemachineBrain>();
     camSpeedX = ((Cinemachine.CinemachineFreeLook)brain.ActiveVirtualCamera).m_XAxis.m_MaxSpeed;
     camSpeedY = ((Cinemachine.CinemachineFreeLook)brain.ActiveVirtualCamera).m_YAxis.m_MaxSpeed;
     ((Cinemachine.CinemachineFreeLook)brain.ActiveVirtualCamera).m_XAxis.m_MaxSpeed = 0;
     ((Cinemachine.CinemachineFreeLook)brain.ActiveVirtualCamera).m_YAxis.m_MaxSpeed = 0;
 }
Example #9
0
    public override void Awake()
    {
        base.Awake();

        if (Instance.mainCamera == null)
        {
            mainCamera = FindObjectOfType <Cinemachine.CinemachineBrain>();
        }
        Main = Instance.mainCamera;
    }
Example #10
0
 private void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
     cam_brain = GetComponent <Cinemachine.CinemachineBrain>();
 }
 public void GenerateCameraCutEvent(ICinemachineCamera vcam)
 {
     if (vcam != null)
     {
         for (int i = 0; i < this.BrainCount; i++)
         {
             CinemachineBrain activeBrain = this.GetActiveBrain(i);
             if (activeBrain != null && activeBrain.IsLive(vcam))
             {
                 activeBrain.m_CameraCutEvent.Invoke(activeBrain);
             }
         }
     }
 }
Example #12
0
 /// <summary>
 /// Signal that the virtual camera's content is discontinuous WRT the previous frame.
 /// If the camera is live, then all CinemachineBrains that are showing it will send a cut event.
 /// </summary>
 public void GenerateCameraCutEvent(ICinemachineCamera vcam)
 {
     if (vcam != null)
     {
         for (int i = 0; i < BrainCount; ++i)
         {
             CinemachineBrain b = GetActiveBrain(i);
             if (b != null && b.IsLive(vcam))
             {
                 b.m_CameraCutEvent.Invoke(b);
             }
         }
     }
 }
Example #13
0
        private CameraState PullStateFromVirtualCamera(Vector3 worldUp)
        {
            CameraState @default = CameraState.Default;

            @default.RawPosition    = base.transform.position;
            @default.RawOrientation = base.transform.rotation;
            @default.ReferenceUp    = worldUp;
            CinemachineBrain cinemachineBrain = CinemachineCore.Instance.FindPotentialTargetBrain(this);

            this.m_Lens.Aspect       = ((cinemachineBrain != null) ? cinemachineBrain.OutputCamera.aspect : 1f);
            this.m_Lens.Orthographic = (cinemachineBrain != null && cinemachineBrain.OutputCamera.orthographic);
            @default.Lens            = this.m_Lens;
            return(@default);
        }
        private static void DrawFreeLookGizmos(CinemachineNewFreeLook vcam, GizmoType selectionType)
        {
            // Standard frustum and logo
            CinemachineBrainEditor.DrawVirtualCameraBaseGizmos(vcam, selectionType);

            Color originalGizmoColour = Gizmos.color;
            bool  isActiveVirtualCam  = CinemachineCore.Instance.IsLive(vcam);

            Gizmos.color = isActiveVirtualCam
                ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
                : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;

            if (vcam.Follow != null)
            {
                Vector3          pos   = vcam.Follow.position;
                Vector3          up    = Vector3.up;
                CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(vcam);
                if (brain != null)
                {
                    up = brain.DefaultWorldUp;
                }

                var middleRig = vcam.GetComponent <CinemachineTransposer>();
                if (middleRig != null)
                {
                    float      scale  = vcam.m_RadialAxis.Value;
                    Quaternion orient = middleRig.GetReferenceOrientation(up);
                    up = orient * Vector3.up;
                    var orbital = middleRig as CinemachineOrbitalTransposer;
                    if (orbital != null)
                    {
                        float rotation = orbital.m_XAxis.Value + orbital.m_Heading.m_Bias;
                        orient = Quaternion.AngleAxis(rotation, up) * orient;
                    }
                    CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
                        pos + up * vcam.m_Orbits[0].m_Height * scale,
                        orient, vcam.m_Orbits[0].m_Radius * scale);
                    CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
                        pos + up * vcam.m_Orbits[1].m_Height * scale,
                        orient, vcam.m_Orbits[1].m_Radius * scale);
                    CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
                        pos + up * vcam.m_Orbits[2].m_Height * scale,
                        orient, vcam.m_Orbits[2].m_Radius * scale);

                    DrawCameraPath(pos, orient, vcam);
                }
            }
            Gizmos.color = originalGizmoColour;
        }
Example #15
0
 /// <summary>
 /// Is this virtual camera currently actively controlling any Camera?
 /// </summary>
 public bool IsLive(ICinemachineCamera vcam)
 {
     if (vcam != null)
     {
         for (int i = 0; i < BrainCount; ++i)
         {
             CinemachineBrain b = GetActiveBrain(i);
             if (b != null && b.IsLive(vcam))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #16
0
    void UpdateCinemachineBrainWorldUpOverride(Transform up)
    {
        if (mainCamera == null)
        {
            return;
        }

        Cinemachine.CinemachineBrain brain = mainCamera.GetComponent <Cinemachine.CinemachineBrain>();
        if (brain == null)
        {
            return;
        }

        brain.m_WorldUpOverride = up;
    }
 public bool IsLive(ICinemachineCamera vcam)
 {
     if (vcam != null)
     {
         for (int i = 0; i < this.BrainCount; i++)
         {
             CinemachineBrain activeBrain = this.GetActiveBrain(i);
             if (activeBrain != null && activeBrain.IsLive(vcam))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #18
0
    private void Awake()
    {
        if (Instance)
        {
            Destroy(gameObject);
        }
        Instance = this;

        allParticles = GetComponentsInChildren <ParticleSystem>();

        brain = Camera.main.GetComponent <Cinemachine.CinemachineBrain>();

        effect1Particles = transform.GetChild(0).GetComponentsInChildren <ParticleSystem>();
        effect2Particles = transform.GetChild(1).GetComponentsInChildren <ParticleSystem>();
    }
        void CameraUpdatedCallback(CinemachineBrain brain)
        {
            bool showIt = enabled && m_ShowImage && CinemachineCore.Instance.IsLive(VirtualCamera);
            int  layer  = 1 << gameObject.layer;

            if (brain.OutputCamera == null || (brain.OutputCamera.cullingMask & layer) == 0)
            {
                showIt = false;
            }
            CanvasInfo ci = LocateMyCanvas(brain, showIt);

            if (ci != null && ci.mCanvas != null)
            {
                ci.mCanvas.SetActive(showIt);
            }
        }
Example #20
0
        private CameraState PullStateFromVirtualCamera(Vector3 worldUp)
        {
            CameraState state = CameraState.Default;

            state.RawPosition    = transform.position;
            state.RawOrientation = transform.rotation;
            state.ReferenceUp    = worldUp;

            CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(this);

            m_Lens.Aspect       = brain != null ? brain.OutputCamera.aspect : 1;
            m_Lens.Orthographic = brain != null ? brain.OutputCamera.orthographic : false;
            state.Lens          = m_Lens;

            return(state);
        }
        /// <summary>Applies the composer rules and orients the camera accordingly</summary>
        /// <param name="curState">The current camera state</param>
        /// <param name="statePrevFrame">The camera state on the previous frame (unused)</param>
        /// <param name="deltaTime">Used for calculating damping.  If less than
        /// or equal to zero, then target will snap to the center of the dead zone.</param>
        /// <returns>curState with RawOrientation applied</returns>
        public CameraState MutateCameraState(
            CameraState curState, CameraState statePrevFrame, float deltaTime)
        {
            if (!IsValid || !curState.HasLookAt)
            {
                return(curState);
            }

            CameraState newState = curState;

            newState.ReferenceLookAt = GetTrackedPoint(newState.ReferenceLookAt);
            if ((newState.ReferenceLookAt - newState.CorrectedPosition).AlmostZero())
            {
                return(newState);  // navel-gazing, get outa here
            }
            CinemachineBrain brain  = CinemachineCore.Instance.FindPotentialTargetBrain(VirtualCamera);
            float            aspect = brain != null ? brain.OutputCamera.aspect : 1;
            float            fovH   = CameraUtilities.CalculateHorizontalFOV(newState.Lens.FieldOfView, aspect);

            Rect softGuideFOV = ScreenToFOV(SoftGuideRect, newState.Lens.FieldOfView, fovH, aspect);

            if (deltaTime <= 0)
            {
                // No damping, just snap to central bounds, skipping the soft zone
                Rect rect = new Rect(softGuideFOV.center, Vector2.zero); // Force to center
                newState.RawOrientation = PlaceWithinScreenBounds(
                    ref newState, rect, newState.RawOrientation, fovH, 0);
            }
            else
            {
                // Start with previous frame's orientation (but with current up)
                Quaternion rigOrientation = Quaternion.LookRotation(
                    statePrevFrame.RawOrientation * Vector3.forward, newState.ReferenceUp);

                // First force the previous rotation into the hard bounds, no damping
                Rect hardGuideFOV = ScreenToFOV(HardGuideRect, newState.Lens.FieldOfView, fovH, aspect);
                newState.RawOrientation = PlaceWithinScreenBounds(
                    ref newState, hardGuideFOV, rigOrientation, fovH, 0);

                // Now move it through the soft zone, with damping
                newState.RawOrientation = PlaceWithinScreenBounds(
                    ref newState, softGuideFOV, newState.RawOrientation, fovH, deltaTime);
            }
            newState.RawOrientation = UnityQuaternionExtensions.Normalized(newState.RawOrientation);
            return(newState);
        }
        static void StaticBlendingHandler(CinemachineBrain brain)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineStoryboard.StaticBlendingHandler");
            CameraState state         = brain.CurrentCameraState;
            int         numBlendables = state.NumCustomBlendables;

            for (int i = 0; i < numBlendables; ++i)
            {
                var b = state.GetCustomBlendable(i);
                CinemachineStoryboard src = b.m_Custom as CinemachineStoryboard;
                if (!(src == null)) // in case it was deleted
                {
                    src.LocateMyCanvas(brain, true);
                    src.PlaceImage(b.m_Weight);
                }
            }
            //UnityEngine.Profiling.Profiler.EndSample();
        }
Example #23
0
        /// <summary>
        /// Create a camera state based on the current transform of this vcam
        /// </summary>
        /// <param name="worldUp">Current World Up direction, as provided by the brain</param>
        /// <param name="lens">Lens settings to serve as base, will be combined with lens from brain, if any</param>
        /// <returns></returns>
        protected CameraState PullStateFromVirtualCamera(Vector3 worldUp, ref LensSettings lens)
        {
            CameraState state = CameraState.Default;

            state.RawPosition    = TargetPositionCache.GetTargetPosition(transform);
            state.RawOrientation = TargetPositionCache.GetTargetRotation(transform);
            state.ReferenceUp    = worldUp;

            CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(this);

            if (brain != null)
            {
                lens.SnapshotCameraReadOnlyProperties(brain.OutputCamera);
            }

            state.Lens = lens;
            return(state);
        }
        private static void DrawFreeLookGizmos(CinemachineFreeLook vcam, GizmoType selectionType)
        {
            // Standard frustum and logo
            CinemachineBrainEditor.DrawVirtualCameraBaseGizmos(vcam, selectionType);

            Color originalGizmoColour = Gizmos.color;
            bool  isActiveVirtualCam  = CinemachineCore.Instance.IsLive(vcam);

            Gizmos.color = isActiveVirtualCam
                ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
                : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;

            if (vcam.Follow != null)
            {
                Vector3          pos       = vcam.Follow.position;
                var              TopRig    = vcam.GetRig(0).GetCinemachineComponent <CinemachineOrbitalTransposer>();
                var              MiddleRig = vcam.GetRig(1).GetCinemachineComponent <CinemachineOrbitalTransposer>();
                var              BottomRig = vcam.GetRig(2).GetCinemachineComponent <CinemachineOrbitalTransposer>();
                Vector3          up        = Vector3.up;
                CinemachineBrain brain     = CinemachineCore.Instance.FindPotentialTargetBrain(vcam);
                if (brain != null)
                {
                    up = brain.DefaultWorldUp;
                }

                Quaternion orient = TopRig.GetReferenceOrientation(up);
                up = orient * Vector3.up;
                float rotation = vcam.m_XAxis.Value + vcam.m_Heading.m_HeadingBias;
                orient = Quaternion.AngleAxis(rotation, up) * orient;

                CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
                    pos + up * TopRig.m_FollowOffset.y, orient, TopRig.m_FollowOffset.z);
                CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
                    pos + up * MiddleRig.m_FollowOffset.y, orient, MiddleRig.m_FollowOffset.z);
                CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
                    pos + up * BottomRig.m_FollowOffset.y, orient, BottomRig.m_FollowOffset.z);

                DrawCameraPath(pos, orient, vcam);
            }

            Gizmos.color = originalGizmoColour;
        }
        CanvasInfo LocateMyCanvas(CinemachineBrain parent, bool createIfNotFound)
        {
            CanvasInfo ci = null;

            for (int i = 0; ci == null && i < mCanvasInfo.Count; ++i)
            {
                if (mCanvasInfo[i] != null && mCanvasInfo[i].mCanvasParent == parent)
                {
                    ci = mCanvasInfo[i];
                }
            }
            if (createIfNotFound)
            {
                if (ci == null)
                {
                    ci = new CanvasInfo()
                    {
                        mCanvasParent = parent
                    };
                    int numChildren = parent.transform.childCount;
                    for (int i = 0; ci.mCanvas == null && i < numChildren; ++i)
                    {
                        RectTransform child = parent.transform.GetChild(i) as RectTransform;
                        if (child != null && child.name == CanvasName)
                        {
                            ci.mCanvas = child.gameObject;
                            var kids = ci.mCanvas.GetComponentsInChildren <RectTransform>();
                            ci.mViewport        = kids.Length > 1 ? kids[1] : null; // 0 is mCanvas
                            ci.mRawImage        = ci.mCanvas.GetComponentInChildren <UnityEngine.UI.RawImage>();
                            ci.mCanvasComponent = ci.mCanvas.GetComponent <Canvas>();
                        }
                    }
                    mCanvasInfo.Add(ci);
                }
                if (ci.mCanvas == null || ci.mViewport == null || ci.mRawImage == null || ci.mCanvasComponent == null)
                {
                    CreateCanvas(ci);
                }
            }
            return(ci);
        }
Example #26
0
    private void Start()
    {
        rigTargetPos    = lightningUnit.transform.position;
        cameraTargetPos = cinemachineDefault.position;
        cameraStartPos  = cinemachineDefault.localPosition;
        distance        = overworldDistance;
        targetRot       = transform.rotation;


        cam = GetComponentInChildren <Camera>();

        cinemachineBrain = gameObject.GetComponentInChildren <Cinemachine.CinemachineBrain>();

        StartCoroutine(StartCutscene());
        StartCoroutine(FinishCutscene());


        // Subscribe to the settings changing delegate
        settings.onSettingsChanged += SettingsChanged;
        SettingsChanged();
    }
        void CreateCanvas(CinemachineBrain parent)
        {
            mCanvas           = new GameObject(CanvasName, typeof(RectTransform));
            mCanvas.hideFlags = HideFlags.HideAndDontSave;
            mCanvas.transform.SetParent(parent.transform);
            mCanvasParent = parent;
#if UNITY_EDITOR
            // Workaround for Unity bug case Case 1004117
            CanvasesAndTheirOwners.AddCanvas(mCanvas, this);
#endif

            var c = mCanvas.AddComponent <Canvas>();
            c.renderMode = RenderMode.ScreenSpaceOverlay;

            var go = new GameObject("Viewport", typeof(RectTransform));
            go.transform.SetParent(mCanvas.transform);
            mViewport = (RectTransform)go.transform;
            go.AddComponent <UnityEngine.UI.RectMask2D>();

            go = new GameObject("RawImage", typeof(RectTransform));
            go.transform.SetParent(mViewport.transform);
            mRawImage = go.AddComponent <UnityEngine.UI.RawImage>();
        }
Example #28
0
 void DrawReticle(CinemachineBrain brain)
 {
     if (!brain.IsLive(VirtualCamera) || brain.OutputCamera == null)
     {
         CinemachineCore.CameraUpdatedEvent.RemoveListener(DrawReticle);
     }
     else
     {
         var player = VirtualCamera.Follow;
         if (AimTargetReticle != null && player != null)
         {
             // Adjust for actual player aim target (may be different due to offset)
             var playerPos = player.position;
             var aimTarget = VirtualCamera.State.ReferenceLookAt;
             var dir       = aimTarget - playerPos;
             if (RuntimeUtility.RaycastIgnoreTag(new Ray(playerPos, dir),
                                                 out RaycastHit hitInfo, dir.magnitude, AimCollisionFilter, IgnoreTag))
             {
                 aimTarget = hitInfo.point;
             }
             AimTargetReticle.position = brain.OutputCamera.WorldToScreenPoint(aimTarget);
         }
     }
 }
Example #29
0
 /// <summary>Called when a CinemachineBrain is disabled.</summary>
 internal void RemoveActiveBrain(CinemachineBrain brain)
 {
     mActiveBrains.Remove(brain);
 }
Example #30
0
 /// <summary>Called when a CinemachineBrain is enabled.</summary>
 internal void AddActiveBrain(CinemachineBrain brain)
 {
     // First remove it, just in case it's being added twice
     RemoveActiveBrain(brain);
     mActiveBrains.Insert(0, brain);
 }