Beispiel #1
0
    /// <summary>
    /// 获取或创建机位
    /// </summary>
    /// <param name="name">名称</param>
    /// <returns>CinemachineVirtualCamera</returns>
    private CinemachineVirtualCamera GetOrCreateVirtualCamera(string name)
    {
        MainCameraComponent mainCamera = CameraManager.GetInstance().GetMainCamereComponent();

        Transform virtualCameraTranform = mainCamera.transform.parent.Find(name);

        if (!virtualCameraTranform)
        {
            virtualCameraTranform = new GameObject(name).transform;
            virtualCameraTranform.SetParent(mainCamera.transform.parent);
        }

        CinemachineVirtualCamera virtualCamera = virtualCameraTranform.gameObject.GetComponent <CinemachineVirtualCamera>();

        if (!virtualCamera)
        {
            virtualCamera = virtualCameraTranform.gameObject.AddComponent <CinemachineVirtualCamera>();
            virtualCamera.m_StandbyUpdate    = CinemachineVirtualCameraBase.StandbyUpdateMode.Always;
            virtualCamera.m_Lens.FieldOfView = mainCamera.GetCamera().fieldOfView;

            CinemachineTransposer transposer = virtualCamera.AddCinemachineComponent <CinemachineTransposer>();
            transposer.m_BindingMode  = CinemachineTransposer.BindingMode.WorldSpace;
            transposer.m_FollowOffset = Vector3.zero;

            virtualCamera.AddCinemachineComponent <CinemachineSameAsFollowTarget>();
        }

        return(virtualCamera);
    }
    private bool GetAllEntitySelectedByVirtualCamera(ref List <SpacecraftEntity> targetList)
    {
        MainCameraComponent mainCam = CameraManager.GetInstance().GetMainCamereComponent();

        SkillSystemGrow skillGrow = m_PlayerSkillProxy.GetCurrentWeaponSkill().GetSkillGrow();
        float           range     = skillGrow.Range * SceneController.SPACE_ACCURACY_TO_CLIENT;

        // 粗略的拾取.
        // 拾取锥体视为一个相机, 把技能射程视为远裁剪面. 根据FOV取远裁剪面的大小, 投射这个大小的Box, 获取所有拾取到的Entity
        {
            // 所有粗略裁剪的物体 = Physics.BoxCastAll(投射开始点, 盒子边长, 相机方向, SkillLayer)

            float halfBoxVerticalSideLength   = range * Mathf.Tan(m_ReticleHorizontalFOVParam / m_ReticleAspect * 0.5f * Mathf.Deg2Rad);
            float halfBoxHorizontalSideLength = halfBoxVerticalSideLength * m_ReticleAspect;

            // 投射开始的点 = 相机近裁剪面的中心点 + 相机方向 * 盒子边长的一半
            Vector3      startPoint = mainCam.transform.position + (mainCam.GetCamera().nearClipPlane + halfBoxVerticalSideLength) * mainCam.GetForward();
            RaycastHit[] hitInfos   = Physics.BoxCastAll(startPoint,
                                                         new Vector3(halfBoxHorizontalSideLength, halfBoxVerticalSideLength, halfBoxVerticalSideLength),
                                                         mainCam.GetForward(),
                                                         Quaternion.identity, range,
                                                         LayerUtil.GetLayersIntersectWithSkillProjectile(true));

            for (int iHit = 0; iHit < hitInfos.Length; iHit++)
            {
                Rigidbody rigidBody = hitInfos[iHit].rigidbody;
                if (rigidBody == null)
                {
                    continue;
                }

                SpacecraftEntity entity = rigidBody.GetComponent <SpacecraftEntity>();
                if (entity != null)
                {
                    targetList.Add(entity);
                }
            }
        }

        if (m_VirtualCameraForReticleSelection != null)
        {
            // 更新虚拟相机的方向和位置
            m_VirtualCameraForReticleSelection.transform.position = mainCam.transform.position;
            m_VirtualCameraForReticleSelection.transform.rotation = mainCam.transform.rotation;

            // 更精细的判断. 当前版本仅计算目标中心点是不是在 虚拟相机 里面
            for (int iTarget = 0; iTarget < targetList.Count; iTarget++)
            {
                Vector3 viewportPos = m_VirtualCameraForReticleSelection.WorldToViewportPoint(targetList[iTarget].transform.position);
                if (viewportPos.x < 0 || viewportPos.y < 0 || viewportPos.x > 1 || viewportPos.y > 1)
                {
                    targetList.RemoveAt(iTarget);
                    iTarget--;
                }
            }
        }
        return(targetList.Count > 0);
    }
Beispiel #3
0
    public Camera GetCurrentCamera_ForBothRuntimeAndEditor()
    {
        MainCameraComponent mainCamComponent = CameraManager.GetInstance().GetMainCamereComponent();

        if (mainCamComponent != null)
        {
            return(mainCamComponent.GetCamera());
        }
        else
        {
            return(Camera.main);
        }
    }
    private void DrawBoxOnGUI()
    {
        MainCameraComponent mainCam = CameraManager.GetInstance().GetMainCamereComponent();

        if (mainCam == null)
        {
            return;
        }

        for (int iAim = 0; iAim < m_SubAimAreas.Count; iAim++)
        {
            AimArea aimArea = m_SubAimAreas[iAim];
            m_SubAimAreas[iAim].UpdateBaseRay(GetViewRay().direction);
            Vector3 aimDir    = m_SubAimAreas[iAim].GetBaseRay();
            Vector3 pos       = mainCam.GetPosition() + aimDir;
            Vector3 screenPos = mainCam.GetCamera().WorldToScreenPoint(pos);

            GizmosHelper.GetInstance().DrawGUIBox(screenPos, 100);
        }
    }
Beispiel #5
0
    /// <summary>
    /// 播放动画
    /// </summary>
    /// <param name="director">播放器</param>
    private void PlayTimeLine(PlayableDirector director)
    {
        CinemachineBrain         mainCameraBrain = null;
        CinemachineVirtualCamera camera1         = null;
        CinemachineVirtualCamera camera2         = null;

        GameplayProxy gameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
        Transform     hero          = IsInSpace() ? null : gameplayProxy.GetMainPlayerSkinTransform();

        if (hero != null)
        {
            MainCameraComponent mainCamera = CameraManager.GetInstance().GetMainCamereComponent();
            mainCameraBrain = mainCamera.GetCamera().GetComponent <CinemachineBrain>();
            camera1         = GetOrCreateVirtualCamera(VIRTUAL_CAMERA_NAME_1);
            camera2         = GetOrCreateVirtualCamera(VIRTUAL_CAMERA_NAME_2);

            if (director == m_OpenTimeline)
            {
                //机位1 ( 打开手表时相机所在机位 )
                camera1.Follow          = GetOrCreateVirtualCameraProxy("WATCH_BACK_POINT");
                camera1.Follow.position = mainCamera.transform.position;
                camera1.Follow.rotation = mainCamera.transform.rotation;

                //机位2 ( 注视手表的机位 )
                camera2.Follow = FindTransformBy(hero, CAMERA_POINT_NAME);

                //UI挂点
                m_WatchPoint                   = FindTransformBy(hero, WATCH_UI_NAME);
                Canvas.worldCamera             = CameraManager.GetInstance().GetUI3DCameraComponent().GetCamera();
                Canvas.worldCamera.cullingMask = 1 << LayerMask.NameToLayer(WATCH_3D_LAYER);
                Canvas.worldCamera.gameObject.SetActive(true);
                Canvas.scaleFactor          = 0.001f;
                Canvas.transform.localScale = Vector3.one * 0.0001f;
                Canvas.GetComponent <RectTransform>().sizeDelta = UIManager.ReferenceResolution;

                LayerUtil.SetGameObjectToLayer(Canvas.gameObject, LayerMask.NameToLayer(WATCH_3D_LAYER), true);
                LayerUtil.SetGameObjectToLayer(m_PostEffectScene, m_PostEffectSceneLayer, false);
                LayerUtil.SetGameObjectToLayer(m_PostEffectUI, m_PostEffectUILayer, false);

                camera1.enabled = true;
                camera2.enabled = true;
            }
        }

        m_WatchPanel.gameObject.SetActive(true);

        if (director == m_OpenTimeline)
        {
            m_CloseTimeline.gameObject.SetActive(false);

            SetCinemachineTrack(m_OpenTimeline, mainCameraBrain, camera1, camera2);

            m_OpenTimeline.extrapolationMode = DirectorWrapMode.Hold;
            m_OpenTimeline.gameObject.SetActive(true);
            m_OpenTimeline.time = 0.0f;
            m_OpenTimeline.Play();

            m_PostEffectScene.gameObject.SetActive(true);
            m_PostEffectUI.gameObject.SetActive(true);
        }
        else if (director == m_CloseTimeline)
        {
            m_OpenTimeline.gameObject.SetActive(false);

            SetCinemachineTrack(director, mainCameraBrain, camera2, camera1);

            m_CloseTimeline.extrapolationMode = DirectorWrapMode.None;
            m_CloseTimeline.gameObject.SetActive(true);
            m_CloseTimeline.time = 0.0f;
            m_CloseTimeline.Play();

            m_PostEffectScene.gameObject.SetActive(true);
            m_PostEffectUI.gameObject.SetActive(true);

            m_SelectedIndex = -1;
            UpdateCenterInfo();
        }

        //人形动画
        PlayHumanAnimator(director == m_OpenTimeline);
    }