Example #1
0
    private void Start()
    {
        if (photonView.IsMine)
        {
            _camera = Instantiate(CinemachineCameraPrefab);
            CinemachineVirtualCamera virtualCamera = _camera.GetComponent <CinemachineVirtualCamera>();

            virtualCamera.Follow = gameObject.transform;
            virtualCamera.m_Lens.Orthographic     = true;
            virtualCamera.m_Lens.OrthographicSize = 9;

            CinemachineConfiner confiner = virtualCamera.GetComponent <CinemachineConfiner>();
            GameObject          map      = GameObject.Find("Map");
            confiner.m_BoundingShape2D = map.GetComponent <MapManager>().GetMapCollider();
            virtualCamera.AddExtension(confiner);

            CinemachineBasicMultiChannelPerlin perlin =
                virtualCamera.AddCinemachineComponent <CinemachineBasicMultiChannelPerlin>();

            NoiseSettings shake = Resources.Load("6DShake") as NoiseSettings;
            perlin.m_NoiseProfile  = shake;
            perlin.m_AmplitudeGain = 0;

            playerScript = GetComponent <AbstractPlayerScript>();
            playerScript.SetCinemachineBasicMultiChannelPerlin(perlin);

            isGameStart = false;
        }

        if (SceneManager.GetActiveScene().name.Equals("Game"))
        {
            GameManager.playerManagers.Add(this);
            GameStart();
        }
    }
Example #2
0
        private void SetConfiner()
        {
            CinemachineConfiner confiner         = _cameraConfinerGroup.GetSingleEntity().cameraConfiner.Value;
            Collider2D          confinerCollider = _cameraConfinerColliderGroup.GetSingleEntity().cameraConfinerCollider.Value;

            confiner.m_BoundingShape2D = confinerCollider;
        }
Example #3
0
        protected override void Awake()
        {
            base.Awake();

            _transposer = GetCinemachineComponent <CinemachineFramingTransposer>();
            _confiner   = GetComponent <CinemachineConfiner>();
        }
    private void Awake()
    {
        _CMvcam1 = this.gameObject;

        _camera = _CMvcam1.GetComponent <CinemachineVirtualCamera>();
        _bounds = _CMvcam1.GetComponent <CinemachineConfiner>();
    }
 private void Awake()
 {
     _disabledColliders = GetComponents <Collider2D>()
                          .Where(coll => !coll.enabled)
                          .ToList();
     _confiner = GameObject.FindObjectOfType <CinemachineConfiner>();
 }
    private void GetConfinement()
    {
        GameObject getConfinementObject = cameraConfinement?.Reference;

        if (getConfinementObject != null)
        {
            Collider2D GetBoundingCollider = getConfinementObject.GetComponent <Collider2D>();

            if (GetBoundingCollider == null)
            {
                return;
            }

            // A new confinement has to be made per scene. This is due to a bug within Cinemachine.
            if (confiner == null)
            {
                confiner = gameObject.AddComponent <CinemachineConfiner>();
            }
            else
            {
                GameObject.Destroy(confiner);
                confiner = gameObject.AddComponent <CinemachineConfiner>();
            }

            confiner.m_BoundingShape2D = GetBoundingCollider;
        }
    }
Example #7
0
    void Awake()
    {
        playerTransform     = GameObject.Find("Player").transform;
        cinemachineBrain    = GameObject.Find("Main Camera").transform.GetComponent <CinemachineBrain>();
        cinemachineCamera   = GetComponent <CinemachineVirtualCamera>();
        cinemachineConfiner = GetComponent <CinemachineConfiner>();

        // Check if camera is following 'player' GameObject
        if (playerTransform != null)
        {
            cinemachineCamera.Follow = playerTransform;
        }
        else
        {
            Debug.LogWarning("Can't find 'Player' game object for cinemachine camera to follow. " +
                             "Either set Follow field in CinemachineCamera manually, or create a game object called player (preferably using the prefab) for camera to follow");
        }

        // Note that the Bound Shape 2D field can't be set through script. Must be set through inspector.
        if (cinemachineConfiner.m_BoundingShape2D == null)
        {
            Debug.LogWarning("No camera bounding set! If needed, create a 'PolygonCollider2D' component, create the boundary you want, " +
                             "set the 'IsTrigger' field to true, and assign the component to the 'Bounding Shape 2D' field in the 'Cinemachine Confiner'", this.transform);
        }
    }
        /// <summary>
        /// Creates and sets up the camera's confiner
        /// </summary>
        protected override void SetupConfiner()
        {
            // we add a rigidbody to it and set it up
            _confinerRigidbody                     = _confinerGameObject.AddComponent <Rigidbody>();
            _confinerRigidbody.useGravity          = false;
            _confinerRigidbody.gameObject.isStatic = true;
            _confinerRigidbody.isKinematic         = true;

            // we copy the collider and set it up

            CopyCollider();
            _confinerGameObject.transform.localPosition = Vector3.zero;


            // we set the composite collider as the virtual camera's confiner
            _cinemachineConfiner = VirtualCamera.gameObject.MMGetComponentAroundOrAdd <CinemachineConfiner>();
            _cinemachineConfiner.m_ConfineMode        = CinemachineConfiner.Mode.Confine3D;
            _cinemachineConfiner.m_ConfineScreenEdges = true;

            if (_boxCollider != null)
            {
                _cinemachineConfiner.m_BoundingVolume = _boxCollider;
            }

            if (_sphereCollider != null)
            {
                _cinemachineConfiner.m_BoundingVolume = _sphereCollider;
            }
        }
Example #9
0
 // Use this for initialization
 void Start()
 {
     confCam                   = GetComponent <CinemachineConfiner>();
     virCam                    = GetComponent <CinemachineVirtualCamera>();
     virCam.m_Follow           = GameObject.FindGameObjectWithTag("Player").transform;
     confCam.m_BoundingShape2D = GameObject.FindGameObjectWithTag("BoundingObject").GetComponent <PolygonCollider2D>();
 }
    private void Start()
    {
        playerStats = PlayerStats.instance;
        if (playerStats == null)
        {
            Debug.LogError("No PlayerStats found in the scene.");
        }

        crosshairHotspot = new Vector2(crosshairTexture.width / 2, crosshairTexture.height / 2);
        Cursor.SetCursor(crosshairTexture, crosshairHotspot, CursorMode.Auto);

        audioManager = AudioManager.instance;
        if (audioManager == null)
        {
            Debug.LogError("No AudioManager found in the scene.");
        }

        CinemachineConfiner confiner = FindObjectOfType <CinemachineConfiner>();

        bounds.center  = confiner.m_BoundingShape2D.bounds.center * 3 / 5;
        bounds.extents = confiner.m_BoundingShape2D.bounds.extents * 3 / 5;

        powerupTimer = powerupCooldown;

        if (gameOverUI == null)
        {
            Debug.LogError("GameOverUI not found!");
        }

        UpgradePoints          = startingUpgradePoints;
        upgradePointsText.text = "Upgrade points: " + UpgradePoints.ToString() + "UP";
    }
Example #11
0
        /// <summary>
        /// Creates and sets up the camera's confiner
        /// </summary>
        protected override void SetupConfiner()
        {
            // we add a rigidbody2D to it and set it up
            _confinerRigidbody2D             = _confinerGameObject.AddComponent <Rigidbody2D>();
            _confinerRigidbody2D.bodyType    = RigidbodyType2D.Static;
            _confinerRigidbody2D.simulated   = false;
            _confinerRigidbody2D.useAutoMass = true;
            _confinerRigidbody2D.bodyType    = RigidbodyType2D.Dynamic;

            // we copy the collider and set it up

            CopyCollider();
            _confinerGameObject.transform.localPosition = Vector3.zero;

            // we reset these settings, set differently initially to avoid a weird Unity warning
            _confinerRigidbody2D.bodyType    = RigidbodyType2D.Static;
            _confinerRigidbody2D.useAutoMass = false;

            // we add a composite collider 2D and set it up
            _confinerCompositeCollider2D = _confinerGameObject.AddComponent <CompositeCollider2D>();
            _confinerCompositeCollider2D.geometryType = CompositeCollider2D.GeometryType.Polygons;

            // we set the composite collider as the virtual camera's confiner
            _cinemachineConfiner = VirtualCamera.gameObject.MMGetComponentAroundOrAdd <CinemachineConfiner>();
            _cinemachineConfiner.m_ConfineMode        = CinemachineConfiner.Mode.Confine2D;
            _cinemachineConfiner.m_ConfineScreenEdges = true;
            _cinemachineConfiner.m_BoundingShape2D    = _confinerCompositeCollider2D;
        }
Example #12
0
 void Start()
 {
     confiner = GetComponent <CinemachineConfiner>();
     if (confiner != null)
     {
         bounds = confiner.m_BoundingVolume;
     }
 }
Example #13
0
 void Awake()
 {
     if (target)
     {
         vcam     = cam.GetComponent <CinemachineVirtualCamera>();
         confiner = vcam.GetComponent <CinemachineConfiner>();
     }
 }
Example #14
0
    void Start()
    {
        boundsCollider = GetComponent <PolygonCollider2D>();
        cineCam        = FindObjectOfType <CinemachineVirtualCamera>();
        cineBounds     = cineCam.GetComponent <CinemachineConfiner>();

        cineBounds.m_BoundingShape2D = boundsCollider;
    }
        /// <summary>
        /// On Awake we grab our components
        /// </summary>
        protected virtual void Awake()
        {
            _virtualCamera = GetComponent <CinemachineVirtualCamera>();
            _confiner      = GetComponent <CinemachineConfiner>();

            _currentZoom       = _virtualCamera.m_Lens.Orthographic ? InitialOrthographicZoom : InitialPerspectiveZoom;
            _framingTransposer = _virtualCamera.GetCinemachineComponent <CinemachineFramingTransposer>();
        }
    /// <summary>
    /// Switchs the collider for the cinemachine camera
    /// </summary>
    private void SwitchBoundingShape()
    {
        PolygonCollider2D   col      = GameObject.FindGameObjectWithTag(Tags.BoundsConfiner).GetComponent <PolygonCollider2D>();
        CinemachineConfiner confiner = GetComponent <CinemachineConfiner>();

        confiner.m_BoundingShape2D = col;
        confiner.InvalidatePathCache();
    }
Example #17
0
 void FindConfiner()
 {
     confiner = cmVcam.GetComponent <CinemachineConfiner>();
     if (confiner != null)
     {
         confiner.InvalidatePathCache();
         confiner.m_BoundingShape2D = GameObject.FindGameObjectWithTag("Bound").GetComponent <Collider2D>();
     }
 }
    private void Awake()
    {
        Instance = this;

        // Get virtual camera & components
        virtualCamera = GetComponentInChildren <CinemachineVirtualCamera>();
        targetGroup   = GetComponentInChildren <CinemachineTargetGroup>();
        confiner      = virtualCamera.GetComponent <CinemachineConfiner>();
    }
Example #19
0
 public void Awake()
 {
     //Get cashe Refs
     vCamera        = gameObject.GetComponent <CinemachineVirtualCamera>();
     startIntensity = vCamera.GetCinemachineComponent <CinemachineBasicMultiChannelPerlin>().m_AmplitudeGain;
     shakeNoise     = vCamera.GetCinemachineComponent <CinemachineBasicMultiChannelPerlin>();
     bounds         = gameObject.GetComponent <CinemachineConfiner>();
     instance       = this;
 }
        private void Awake()
        {
            _playerMarker = FindObjectOfType <PlayerMarker>();
            _virtualCameraCOnfinerMarker = FindObjectOfType <VirtualCameraConfinerMarker>();
            _cinemachineVirtualCamera    = GetComponent <CinemachineVirtualCamera>();
            _cinemachineConfiner         = GetComponent <CinemachineConfiner>();

            _cinemachineVirtualCamera.m_Follow     = _playerMarker?.transform;
            _cinemachineConfiner.m_BoundingShape2D = _virtualCameraCOnfinerMarker?.GetComponent <PolygonCollider2D>();
        }
Example #21
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     //_cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
     _cinemachineConfiner = GetComponent <CinemachineConfiner>();
     cameraIndex          = 0;
 }
Example #22
0
        private void SetVirtualCameraConfiner()
        {
            CinemachineConfiner cinemachineConfiner = virtualCamera.gameObject.GetComponent <CinemachineConfiner>();

            if (cinemachineConfiner != null)
            {
                cinemachineConfiner.m_BoundingShape2D = levelSettings.VirtualCameraConfiner;
                cinemachineConfiner.InvalidatePathCache();
            }
        }
    /// <summary>
    /// Switches the confiner that the cinemachine uses to define screen shape.
    /// </summary>
    private void SwitchBoundingShape()
    {
        //Get polygon collider used by cinemachine
        PolygonCollider2D   polygonCollider2D   = GameObject.FindGameObjectWithTag(Tags.BoundConfiner).GetComponent <PolygonCollider2D>();
        CinemachineConfiner cinemachineConfiner = GetComponent <CinemachineConfiner>();

        cinemachineConfiner.m_BoundingShape2D = polygonCollider2D;

        //Special function to clear cache
        cinemachineConfiner.InvalidatePathCache();
    }
Example #24
0
        void SetCinemachineConfines()
        {
            // Set camera bounds to the one in the level, if any.
            PolygonCollider2D   cameraBounds = GameObject.FindWithTag("CameraBoundingBox").GetComponent <PolygonCollider2D>();
            CinemachineConfiner confiner     = FindObjectOfType <CinemachineConfiner>();

            confiner.m_BoundingShape2D = cameraBounds;
            // Cinemachine doesn't automatically update performance path.
            // This makes sure the path is updated.
            confiner.InvalidatePathCache();
        }
Example #25
0
    /// <summary>
    ///   Switch the collider that cinemachine uses to define teh edges of the screen
    ///</summary>
    private void SwitchBoundingShape()
    {
        // Get the polygon collider on the 'boundsconfiner' gameobject which is used by cinemachine to prevent teh camera going beyong the screen edges
        PolygonCollider2D polygonCollider2D = GameObject.FindGameObjectWithTag(Tags.BoundsConfiner).GetComponent <PolygonCollider2D>();

        CinemachineConfiner cinemachineConfiner = GetComponent <CinemachineConfiner>();

        cinemachineConfiner.m_BoundingShape2D = polygonCollider2D;

        // since teh confiner bounds have changed need to call this to clear the cache.
        cinemachineConfiner.InvalidatePathCache();
    }
Example #26
0
    /// <summary>
    /// 设置摄像机活动范围
    /// </summary>
    /// <param name="collide"></param>
    public static void SetCameraConfiner(PolygonCollider2D collide)
    {
        if (_mainCamera == null)
        {
            return;
        }
        var trans = _cameraConfiner.gameObject;

        Destroy(_cameraConfiner);
        _cameraConfiner = trans.gameObject.AddComponent <CinemachineConfiner>();
        _cameraConfiner.m_BoundingShape2D = collide;
    }
Example #27
0
    protected override void ExecuteSystem(List <GameEntity> entities)
    {
        if (entities.Count != 1)
        {
            Debug.LogWarning($"Not the right of camera confiner components available: {entities.Count}");
            return;
        }

        CinemachineConfiner cameraConfiner = _context.camera.Camera.GetComponent <CinemachineConfiner>();

        cameraConfiner.m_BoundingShape2D = entities[0].cameraConfiner.Value;
    }
        private static void DrawColliderGizmos(CinemachineConfiner confiner, GizmoType type)
        {
            CinemachineVirtualCameraBase vcam = (confiner != null) ? confiner.VirtualCamera : null;

            if (vcam != null && confiner.enabled && confiner.m_BoundingVolume != null)
            {
                Color oldColor = Gizmos.color;
                Gizmos.color = Color.yellow;
                Matrix4x4 oldMatrix = Gizmos.matrix;
                Transform t         = confiner.m_BoundingVolume.transform;
                Gizmos.matrix = Matrix4x4.TRS(t.position, t.rotation, t.lossyScale);
                Type colliderType = confiner.m_BoundingVolume.GetType();
                if (colliderType == typeof(BoxCollider))
                {
                    BoxCollider c = confiner.m_BoundingVolume as BoxCollider;
                    Gizmos.DrawWireCube(c.center, c.size);
                }
                else if (colliderType == typeof(SphereCollider))
                {
                    SphereCollider c = confiner.m_BoundingVolume as SphereCollider;
                    Gizmos.DrawWireSphere(c.center, c.radius);
                }
                else if (colliderType == typeof(CapsuleCollider))
                {
                    CapsuleCollider c    = confiner.m_BoundingVolume as CapsuleCollider;
                    Vector3         size = Vector3.one * c.radius * 2;
                    switch (c.direction)
                    {
                    case 0: size.x = c.height; break;

                    case 1: size.y = c.height; break;

                    case 2: size.z = c.height; break;
                    }
                    Gizmos.DrawWireCube(c.center, size);
                }
                else if (colliderType == typeof(MeshCollider))
                {
                    MeshCollider c = confiner.m_BoundingVolume as MeshCollider;
                    Gizmos.DrawWireMesh(c.sharedMesh);
                }
                else
                {
                    // Just draw an AABB - not very nice!
                    Gizmos.matrix = oldMatrix;
                    Bounds bounds = confiner.m_BoundingVolume.bounds;
                    Gizmos.DrawWireCube(t.position, bounds.extents * 2);
                }
                Gizmos.color  = oldColor;
                Gizmos.matrix = oldMatrix;
            }
        }
Example #29
0
 void Awake()
 {
     if (Instance != null)
     {
         Destroy(this.gameObject);
         return;
     }
     Instance = this;
     GameObject.DontDestroyOnLoad(this.gameObject);
     vCam     = GetComponent <CinemachineVirtualCamera>();
     confiner = GetComponent <CinemachineConfiner>();
     princess = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
 }
Example #30
0
    public void setBound(GameObject bg)
    {
        CinemachineConfiner CinemachineC = GetComponent <CinemachineConfiner>();

        if (bg != null)
        {
            CinemachineC.m_BoundingShape2D = bg.GetComponent <Collider2D>();
        }
        else
        {
            CinemachineC.m_BoundingShape2D = null;
        }
    }