Пример #1
0
            void Awake()
            {
                Instance   = this;
                mainCamera = Camera.main;
                int cameraPriority = 0;

                virtualCameras = VirtualCamera.virtualCameras;
                // Sets the virtual camera with the highest priority as active
                foreach (VirtualCamera virtualCamera in virtualCameras)
                {
                    if (virtualCamera.priority > cameraPriority)
                    {
                        cameraPriority = virtualCamera.priority;
                        currentCamera  = virtualCamera;
                    }
                    virtualCamera.isActive = false;
                }
                currentCamera.isActive = true;
                if (Application.isPlaying)
                {
                    transform.SetParent(currentCamera.cameraTransform);
                }
                // Reset Position and rotation
                transform.localPosition = Vector3.zero;
                transform.localRotation = Quaternion.Euler(0, 0, 0);
            }
Пример #2
0
            // This function handles priority changes of virtual cameras
            public void OnPriorityChange()
            {
                int           cameraPriority = currentCamera.priority;
                VirtualCamera previousCam    = currentCamera;
                bool          change         = false;

                // Checks if there is a virtual camera with higher priority than the current one
                foreach (VirtualCamera virtualCamera in virtualCameras)
                {
                    if (virtualCamera.priority > cameraPriority)
                    {
                        cameraPriority = virtualCamera.priority;
                        currentCamera  = virtualCamera;
                        change         = true;
                    }
                }
                // If there is a change of the highest priority, the transition will be performed
                if (change)
                {
                    // Checks if the camera will inherit the position from previous
                    if (currentCamera.InheritPosition)
                    {
                        currentCamera.lastPos                  = previousCam.followTarget.position;
                        currentCamera.transform.position       = previousCam.transform.position;
                        currentCamera.cameraTransform.position = previousCam.cameraTransform.position;
                    }
                    transform.parent       = null;
                    previousCam.isActive   = false;
                    currentCamera.isActive = true;
                    StopCoroutine("MoveToPosition");
                    StartCoroutine("MoveToPosition", transitionTime);
                }
            }
Пример #3
0
        private void OnEnable()
        {
            vCam          = target as VirtualCamera;
            vCamTransform = vCam.transform;

            CameraSystem.SoloCamera = vCam;
        }
Пример #4
0
        static void Main6(string[] args)
        {
            _virtualCam = new VirtualCamera();
            _virtualCam.Start();
            var calib  = new SimpleAForgeCalibrator(_virtualCam, _virtualCam);
            var pt     = new AForgePenTracker(new RedLaserStrategy(), _virtualCam);
            var parser = new DataParser(calib, pt, typeof(CornerBarycentricMapper));

            parser.Start();
            parser.PenPositionChanged += NewPoint;
            while (true)
            {
                Thread.Sleep(10000);
                //_virtualCam.Clear();
                _virtualCam.AddRect(500, 500, 15, 15, Color.Red);
                _virtualCam.AddRect(530, 530, 15, 15, Color.Black);
                _virtualCam.Draw();
                Thread.Sleep(30);
                //_virtualCam.Clear();
                _virtualCam.AddRect(500, 500, 15, 15, Color.Black);
                _virtualCam.AddRect(530, 530, 15, 15, Color.Red);
                _virtualCam.Draw();
                Debug.WriteLine("Drew Point");
            }
            Console.Read();
        }
Пример #5
0
        public void InitLevel(int levelId, int heroId)
        {
            // 关卡数据配置
            m_levelCSV = Game.gameCSV.GetData <CSV_Level>(levelId);

            levelInfo  = LevelInfo.Create(m_levelCSV.scene);
            hero       = Hero.Create(heroId);
            monsters   = new List <Monster>();
            heroCamera = Game.gameCamera.heroCamera;

            // 默认区域索引
            areaIndex = 1;

            // 相机初始化
            heroCamera.Initialize();

            // 环境相关
            environment = new LevelEnvironment();
            // 天空盒
            Game.gameCamera.SetSkybox(m_levelCSV.skybox);

            // event
            levelInfo.OnLoadedAreaHandler += OnLoadedAreaHandler;
            levelInfo.OnEnterAreaHandler  += OnEnterAreaHandler;
            levelInfo.OnStayAreaHandler   += OnStayAreaHandler;
            levelInfo.OnExitAreaHandler   += OnExitAreaHandler;

            // init
            levelInfo.InitEnvironment(environment);
        }
 private void OnDestroy()
 {
     if (VirtualCamera != null)
     {
         VirtualCamera.RemovePostPipelineStageHook(PostPipelineStageCallback);
     }
 }
Пример #7
0
    private void ActivateCamera(int cameraIndex)
    {
        ActiveCamera = null;

        for (int i = 0; i < mainCameraList.Count; i++)
        {
            if (i == cameraIndex)
            {
                ActiveCamera       = mainCameraList[i];
                currentCameraIndex = i;
            }
        }

        if (cameraIndex == -1)
        {
            ActiveCamera = auxiliarCamera;
        }

        camera.transform.SetParent(ActiveCamera.CameraMount);
        camera.transform.localPosition = Vector3.zero;
        camera.transform.localRotation = Quaternion.identity;
        camera.cullingMask             = ActiveCamera.CullingMask;

        OnCameraChange?.Invoke(ActiveCamera);
    }
Пример #8
0
    //Make game Over UI objects active
    public void WinGame()
    {
        PlayerPrefs.SetString("InputToggle", (InputToggle.isOn).ToString());
        PlayerPrefs.SetString("AutoPlayToggle", (AutoPlayToggle.isOn).ToString());
        PlayerPrefs.SetString("LockToggle", (LockToggle.isOn).ToString());
        PlayerPrefs.SetInt("LevelNumber", levelNumber + 1);



        if (windGameSceneObjects != null)
        {
            windGameSceneObjects.SetActive(true);
        }
        Player.GetComponent <PlayerController>().speed = 0;
        isGameOver = true;
        ToolParticle.GetComponent <ParticleSystem>().Stop();

        //play End animation

        Tool.GetComponent <Animator>().enabled = true;
        VirtualCamera.GetComponent <CinemachineVirtualCamera>().enabled = false;
        FinishCamAnim.SetTrigger("Finish");
        FinishToolAnim.SetTrigger("Finish");


        Vibration.Vibrate(500);
    }
 public override void OnTriggerExit2D(Collider2D other)
 {
     if (other.CompareTag("Player") && !other.isTrigger)
     {
         ChangeActivation(Enemies, false);
         VirtualCamera.SetActive(false);
     }
 }
Пример #10
0
 // Use this for initialization
 void Start()
 {
     //health = FindObjectOfType(typeof(PlayerHealth)) as PlayerHealth;
     health = PlayerHealth.instance;
     virtualCamera = FindObjectOfType(typeof(VirtualCamera))as VirtualCamera;
     if (health == null) {
         throw new UnityException("no health");
     }
 }
 public override void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Player") && !other.isTrigger)
     {
         ChangeActivation(Enemies, true);
         StartCoroutine(CallChangeDoors(false));
         VirtualCamera.SetActive(true);
     }
 }
Пример #12
0
    public override void Die()
    {
        AudioManager.instance.Play("SkeletonDeath");

        Instantiate(deathEffect, transform.position, Quaternion.identity);
        transform.gameObject.tag = "Background"; // prevent player from dying if they touch the death animation
        Destroy(gameObject, 1f);                 // delay destroying of enemy to allow animation to play
        camRipple.RippleEffect();
        VirtualCamera.GetComponent <SimpleCameraShakeInCinemachine>().shake();
    }
Пример #13
0
 /// <summary>
 /// Singleton initialization
 /// </summary>
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
Пример #14
0
    public override void TakeDamage(int damage)
    {
        health -= damage;
        healthBar.SetHealth(health);
        VirtualCamera.GetComponent <SimpleCameraShakeInCinemachine>().smallshake();

        if (health <= 0)
        {
            Die();
        }
    }
Пример #15
0
    public override void Die()
    {
        AudioManager.instance.Play("Splatter");
        GameObject bs = Instantiate(bloodstain, transform.position, Quaternion.identity);

        Instantiate(deathEffect, transform.position, Quaternion.identity);
        Destroy(gameObject);
        Destroy(bs, bloodlifetime);
        camRipple.RippleEffect();
        VirtualCamera.GetComponent <SimpleCameraShakeInCinemachine>().shake();
    }
Пример #16
0
    public override void Die()
    {
        animator.Play("BanditEnragedDeath");
        GameObject bs = Instantiate(bloodstain, transform.position, Quaternion.identity);

        Instantiate(deathEffect, transform.position, Quaternion.identity);
        transform.gameObject.tag = "Background"; // prevent player from dying if they touch the death animation
        Destroy(gameObject, 1f);                 // delay destroying of enemy to allow animation to play
        Destroy(bs, bloodlifetime);
        camRipple.RippleEffect();
        VirtualCamera.GetComponent <SimpleCameraShakeInCinemachine>().shake();
    }
 /// <summary>
 /// API for the inspector.  Internal use only
 /// </summary>
 public void UpdateInputAxisProvider()
 {
     m_XAxis.SetInputAxisProvider(0, null);
     if (!m_HeadingIsSlave && VirtualCamera != null)
     {
         var provider = VirtualCamera.GetInputAxisProvider();
         if (provider != null)
         {
             m_XAxis.SetInputAxisProvider(0, provider);
         }
     }
 }
Пример #18
0
        /// <summary>
        /// Adjust the rigOrientation to put the camera within the screen bounds.
        /// If deltaTime >= 0 then damping will be applied.
        /// Assumes that currentOrientation fwd is such that input rigOrientation's
        /// local up is NEVER NEVER NEVER pointing downwards, relative to
        /// state.ReferenceUp.  If this condition is violated
        /// then you will see crazy spinning.  That's the symptom.
        /// </summary>
        private void RotateToScreenBounds(
            ref CameraState state, Rect screenRect, Vector3 trackedPoint,
            ref Quaternion rigOrientation, float fov, float fovH, float deltaTime)
        {
            Vector3 targetDir = trackedPoint - state.CorrectedPosition;
            Vector2 rotToRect = rigOrientation.GetCameraRotationToTarget(targetDir, state.ReferenceUp);

            // Bring it to the edge of screenRect, if outside.  Leave it alone if inside.
            ClampVerticalBounds(ref screenRect, targetDir, state.ReferenceUp, fov);
            float min = (screenRect.yMin - 0.5f) * fov;
            float max = (screenRect.yMax - 0.5f) * fov;

            if (rotToRect.x < min)
            {
                rotToRect.x -= min;
            }
            else if (rotToRect.x > max)
            {
                rotToRect.x -= max;
            }
            else
            {
                rotToRect.x = 0;
            }

            min = (screenRect.xMin - 0.5f) * fovH;
            max = (screenRect.xMax - 0.5f) * fovH;
            if (rotToRect.y < min)
            {
                rotToRect.y -= min;
            }
            else if (rotToRect.y > max)
            {
                rotToRect.y -= max;
            }
            else
            {
                rotToRect.y = 0;
            }

            // Apply damping
            if (deltaTime >= 0 && VirtualCamera.PreviousStateIsValid)
            {
                rotToRect.x = VirtualCamera.DetachedLookAtTargetDamp(
                    rotToRect.x, m_VerticalDamping, deltaTime);
                rotToRect.y = VirtualCamera.DetachedLookAtTargetDamp(
                    rotToRect.y, m_HorizontalDamping, deltaTime);
            }

            // Rotate
            rigOrientation = rigOrientation.ApplyCameraRotation(rotToRect, state.ReferenceUp);
        }
        void PositionCamera(ref CameraState curState, float deltaTime)
        {
            var targetPos     = FollowTargetPosition;
            var prevTargetPos = deltaTime >= 0 ? PreviousFollowTargetPosition : targetPos;

            // Compute damped target pos (compute in camera space)
            var dampedTargetPos = Quaternion.Inverse(curState.RawOrientation)
                                  * (targetPos - prevTargetPos);

            if (deltaTime >= 0)
            {
                dampedTargetPos = VirtualCamera.DetachedFollowTargetDamp(
                    dampedTargetPos, Damping, deltaTime);
            }
            dampedTargetPos = prevTargetPos + curState.RawOrientation * dampedTargetPos;

            // Get target rotation (worldspace)
            var fwd = Vector3.forward;
            var up  = Vector3.up;
            var followTargetRotation = FollowTargetRotation;
            var followTargetForward  = followTargetRotation * fwd;
            var angle = UnityVectorExtensions.SignedAngle(
                fwd, followTargetForward.ProjectOntoPlane(up), up);
            var previousHeadingAngle = deltaTime >= 0 ? PreviousHeadingAngle : angle;
            var deltaHeading         = angle - previousHeadingAngle;

            PreviousHeadingAngle = angle;

            // Bypass user-sourced rotation
            dampedTargetPos = targetPos
                              + Quaternion.AngleAxis(deltaHeading, up) * (dampedTargetPos - targetPos);
            PreviousFollowTargetPosition = dampedTargetPos;

            GetRigPositions(out Vector3 root, out Vector3 shoulder, out Vector3 hand);

            // 1. Check if pivot itself is colliding with something, if yes, then move the pivot
            // closer to the player. The radius is bigger here than in step 2, to avoid problems
            // next to walls. Where the preferred distance would be pulled completely to the
            // player, using a bigger radius, this won't happen.
            hand = PullTowardsStartOnCollision(in root, in hand, in CameraCollisionFilter, CameraRadius * 1.05f);

            // 2. Try to place the camera to the preferred distance
            var camPos = hand - (followTargetForward * CameraDistance);

            camPos = PullTowardsStartOnCollision(in hand, in camPos, in CameraCollisionFilter, CameraRadius);

            curState.RawPosition     = camPos;
            curState.RawOrientation  = FollowTargetRotation;
            curState.ReferenceLookAt = camPos + 1000.0f * (FollowTargetRotation * Vector3.forward);
            curState.ReferenceUp     = up;
        }
Пример #20
0
 /// <summary>
 /// API for the inspector.  Internal use only
 /// </summary>
 public void UpdateInputAxisProvider()
 {
     m_HorizontalAxis.SetInputAxisProvider(0, null);
     m_VerticalAxis.SetInputAxisProvider(1, null);
     if (VirtualCamera != null)
     {
         var provider = VirtualCamera.GetInputAxisProvider();
         if (provider != null)
         {
             m_HorizontalAxis.SetInputAxisProvider(0, provider);
             m_VerticalAxis.SetInputAxisProvider(1, provider);
         }
     }
 }
Пример #21
0
 private void OnEnable()
 {
     VirtualCamera = GetComponent <CinemachineVirtualCameraBase>();
     if (VirtualCamera == null)
     {
         Debug.LogError("CinemachineFollowZoom requires a Cinemachine Virtual Camera component");
         enabled = false;
     }
     else
     {
         VirtualCamera.AddPostPipelineStageHook(PostPipelineStageCallback);
         enabled = true;
     }
 }
Пример #22
0
    public void changeCameras(VirtualCamera target)
    {
        //previousCam = targetCam;
        if (targetCam)
        {
            lastPos          = targetCam.transform.position;
            lastRot          = targetCam.transform.rotation;
            lastFov          = targetCam.fieldOfView;
            targetCam.active = false;
        }
        targetCam     = target;
        interpolation = 0;

        targetCam.active = true;
    }
Пример #23
0
    public override void TakeDamage(int damage)
    {
        health -= damage;
        healthBar.SetHealth(health);
        VirtualCamera.GetComponent <SimpleCameraShakeInCinemachine>().smallshake();

        if (health <= 0)
        {
            animator.Play("Skeleton_Death");
            Die();
        }
        else
        {
            animator.Play("Skeleton_Damage");
        }
    }
 private void OnEnable()
 {
     VirtualCamera = GetComponent <CinemachineVirtualCameraBase>();
     if (VirtualCamera == null)
     {
         Debug.LogError("CinemachineSmoother requires a Cinemachine Virtual Camera component");
         enabled = false;
     }
     else
     {
         VirtualCamera.AddPostPipelineStageHook(PostPipelineStageCallback);
         enabled = true;
     }
     mSmoothingFilter         = null;
     mSmoothingFilterRotation = null;
 }
Пример #25
0
        private static void OnDrawGizmos(VirtualCamera vCam, GizmoType gizmoType)
        {
            var cam = vCam.GetComponent <Camera> ();

            if (cam == false)
            {
                return;
            }

            var vCamTransform = vCam.transform;

            Gizmos.matrix = vCamTransform.localToWorldMatrix;
            Gizmos.DrawFrustum(
                Vector3.zero, cam.fieldOfView,
                cam.farClipPlane, cam.nearClipPlane, cam.aspect);
        }
Пример #26
0
 private void OnEnable()
 {
     VirtualCamera = GetComponent <CinemachineVirtualCameraBase>();
     if (VirtualCamera == null)
     {
         CinemachineDebugLogger.LogError("CinemachineCollider requires a Cinemachine Virtual Camera component");
         enabled = false;
     }
     else
     {
         VirtualCamera.AddPostPipelineStageHook(PostPipelineStageCallback);
         enabled = true;
     }
     RebuildCurbFeelers();
     mSmoothingFilter = null;
 }
Пример #27
0
    public override void OnTriggerEnter2D(Collider2D collidedObject)
    {
        if (collidedObject.CompareTag("Player") && !collidedObject.isTrigger)
        {
            foreach (var enemy in Enemies)
            {
                ChangeActivation(enemy, true);
            }

            foreach (var pot in Pots)
            {
                ChangeActivation(pot, true);
            }
            CloseDoors();
            VirtualCamera.SetActive(true);
        }
    }
Пример #28
0
    void Start()
    {
        var camera = new VirtualCamera(new Vector3(0, 0, -10), 60, 16f / 9f, 1000, 0.3f);

        LoadJsonFile();
        var texture = LoadTexture("Suzanne");

        var mesh      = LoadJsonFile();
        var lightData = new LightData {
            Pos = new Vector3(0, 10, -10), LightColor = Color
        };

        m_device      = new Device(Image, lightData, mesh, camera, texture, 1280, 720);
        m_device.Mode = Mode;

        //Application.targetFrameRate = 60;
    }
        /// <summary>Applies the composer rules and orients the camera accordingly</summary>
        /// <param name="curState">The current camera state</param>
        /// <param name="deltaTime">Used for calculating damping.  If less than
        /// zero, then target will snap to the center of the dead zone.</param>
        public override void MutateCameraState(ref CameraState curState, float deltaTime)
        {
            if (!IsValid)
            {
                return;
            }

            Vector3 dampedPos = FollowTargetPosition;

            if (deltaTime >= 0)
            {
                dampedPos = m_PreviousTargetPosition + VirtualCamera.DetachedFollowTargetDamp(
                    dampedPos - m_PreviousTargetPosition, m_Damping, deltaTime);
            }
            m_PreviousTargetPosition = dampedPos;
            curState.RawPosition     = dampedPos;
        }
Пример #30
0
        /// <summary>Orients the camera to match the Follow target's orientation</summary>
        /// <param name="curState">The current camera state</param>
        /// <param name="deltaTime">Not used.</param>
        public override void MutateCameraState(ref CameraState curState, float deltaTime)
        {
            if (!IsValid)
            {
                return;
            }

            Quaternion dampedOrientation = FollowTargetRotation;

            if (deltaTime >= 0)
            {
                float t = VirtualCamera.DetachedFollowTargetDamp(1, m_Damping, deltaTime);
                dampedOrientation = Quaternion.Slerp(
                    m_PreviousReferenceOrientation, FollowTargetRotation, t);
            }
            m_PreviousReferenceOrientation = dampedOrientation;
            curState.RawOrientation        = dampedOrientation;
        }
Пример #31
0
    public override void OnTriggerExit2D(Collider2D _other)
    {
        //When the player exits the room
        if (_other.CompareTag("Player") && !_other.isTrigger)
        {
            //Deactivate All enemies and pots
            for (int i = 0; i < Enemies.Length; i++)
            {
                ChangeActivation(Enemies[i], false);
            }

            //Deactivate All  pots
            for (int i = 0; i < Pots.Length; i++)
            {
                ChangeActivation(Pots[i], false);
            }
            VirtualCamera.SetActive(false); //deactivate the room camera
        }
    }
Пример #32
0
 // Use this for initialization
 void Start()
 {
     virtualCamera = FindObjectOfType<VirtualCamera>();
     transform.position = virtualCamera.ScreenPosToWorldPos(transform.position);
 }
Пример #33
0
 // Use this for initialization
 void Awake()
 {
     virtualCamera = FindObjectOfType<VirtualCamera>();
     animator = GetComponent<Animator>();
 }