private static void DrawColliderGizmos(CinemachineCollider collider, GizmoType type) { CinemachineVirtualCameraBase vcam = (collider != null) ? collider.VirtualCamera : null; if (vcam != null && collider.enabled) { Color oldColor = Gizmos.color; bool isLive = CinemachineCore.Instance.IsLive(vcam); Color feelerColor = isLive ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour; Color hitColour = isLive ? Color.white : Color.grey; Vector3 pos = vcam.State.FinalPosition; if (collider.m_PreserveLineOfSight && vcam.State.HasLookAt) { Vector3 forwardFeelerVector = (vcam.State.ReferenceLookAt - pos).normalized; float distance = collider.m_DistanceLimit; Gizmos.color = collider.IsTargetObscured(vcam.LiveChildOrSelf) ? hitColour : feelerColor; Gizmos.DrawLine(pos, pos + forwardFeelerVector * distance); } Gizmos.color = oldColor; } }
private static void DrawColliderGizmos(CinemachineCollider collider, GizmoType type) { CinemachineVirtualCameraBase vcam = (collider != null) ? collider.VirtualCamera : null; if (vcam != null && collider.enabled) { Color oldColor = Gizmos.color; bool isLive = CinemachineCore.Instance.IsLive(vcam); Color feelerColor = isLive ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour; Color hitColour = isLive ? Color.white : Color.grey; Vector3 pos = vcam.State.FinalPosition; if (collider.m_PreserveLineOfSight && vcam.State.HasLookAt) { Vector3 forwardFeelerVector = (vcam.State.ReferenceLookAt - pos).normalized; float distance = collider.m_LineOfSightFeelerDistance; Gizmos.color = collider.IsTargetObscured(vcam.LiveChildOrSelf) ? hitColour : feelerColor; Gizmos.DrawLine(pos, pos + forwardFeelerVector * distance); } if (collider.m_UseCurbFeelers) { Quaternion orientation = vcam.State.FinalOrientation; var feelers = collider.GetFeelers(vcam.LiveChildOrSelf); foreach (CinemachineCollider.CompiledCurbFeeler feeler in feelers) { Vector3 worldDirection = orientation * feeler.LocalVector; Gizmos.color = feeler.IsHit ? hitColour : feelerColor; Gizmos.DrawLine(pos, pos + worldDirection * feeler.RayDistance); } } Gizmos.color = oldColor; } }
void Update() { #if UNITY_EDITOR if (!EditorApplication.isPlaying) { CreateGlobalEventIfNecessary(); } #endif if (_cache != null) { if (_freeLook != null) { _vcam = _freeLook.GetRig(1) as CinemachineVirtualCameraBase; } else { _vcam = _cache.VirtualCamera; } // _vcam = _cache.VirtualCamera. as CinemachineVirtualCameraBase; // _cache.VirtualCamera.LiveChildOrSelf as CinemachineVirtualCameraBase; } if (_vcam == null) { return; } // variables if (TargetObscuredVariable.initialized) { TargetObscuredVariable.FsmBool.Value = _cache.IsTargetObscured(_vcam); } if (CameraWasDisplaced.initialized) { CameraWasDisplaced.FsmBool.Value = _cache.CameraWasDisplaced(_vcam); } // events if (_cache.IsTargetObscured(_vcam) && !_currentlyObscured) { _currentlyObscured = true; onTargetObscuredBeganEvent.SendEvent(null, eventTarget, debug); } if (!_cache.IsTargetObscured(_vcam) && _currentlyObscured) // only call on our way back from being obscured { _currentlyObscured = false; onTargetObscuredEndedEvent.SendEvent(null, eventTarget, debug); } if (_cache.CameraWasDisplaced(_vcam) && !_currentlyDisplaced) { _currentlyDisplaced = true; onCameraDisplacedBeganEvent.SendEvent(null, eventTarget, debug); } if (!_cache.CameraWasDisplaced(_vcam) && _currentlyDisplaced) // only call on our way back from being obscured { _currentlyDisplaced = false; onCameraDisplacedEndedEvent.SendEvent(null, eventTarget, debug); } }