Exemplo n.º 1
0
    private void SwitchCamMode(CameraMode mode, CameraContext context = null)
    {
        if (cameraControlModeParam == null || curCameraModeParam == null)
        {
            return;
        }
        CameraMode oldMode = cameraMode;

        cameraMode = mode;  //保证外部拿到的cameraMode是当前的?

        if (camCtrl != null)
        {
            if (camCtrl.GetCameraMode() == mode)    //同一个状态不能重复进入
            {
                return;
            }
            curCameraModeParam.FOV               = m_userDesireFov;
            curCameraModeParam.curPitchAngle     = m_userDesireAngle.x;
            curCameraModeParam.curDistance       = m_userDesireDistance;
            cameraControlModeParam[(int)oldMode] = curCameraModeParam;
            camCtrl.Leave();
        }
        camCtrl = CameraUtil.GetCamCtrl(mode);
        camCtrl.curCameraMode = mode;
        curCameraModeParam    = cameraControlModeParam[(int)mode];
        camCtrl.Enter(context);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Render all the current objects.
        /// </summary>
        public override void Render(CameraContext cameraContext)
        {
            // TODO: (KS) Handle categories beyond the 64 which fit into categoryMask.
            // TODO: (KS) Find a better way to split solid, transparent and wireframe rendering. Also need to respect the
            // TwoSided flag.
            // TODO: (KS) Restore colour/tint support from ObjectAttributes to rendering.

            _renderTransforms.Clear();
            _parentTransforms.Clear();
            _renderShapes.Clear();
            _transientCache.Collect(_renderTransforms, _parentTransforms, _renderShapes, ShapeCache.CollectType.Solid);
            _shapeCache.Collect(_renderTransforms, _parentTransforms, _renderShapes, ShapeCache.CollectType.Solid);
            RenderInstances(cameraContext, cameraContext.OpaqueBuffer, SolidMesh, _renderTransforms, _parentTransforms, _renderShapes, Materials[SolidMaterialName]);

            _renderTransforms.Clear();
            _renderShapes.Clear();
            _transientCache.Collect(_renderTransforms, _parentTransforms, _renderShapes, ShapeCache.CollectType.Transparent);
            _shapeCache.Collect(_renderTransforms, _parentTransforms, _renderShapes, ShapeCache.CollectType.Transparent);
            RenderInstances(cameraContext, cameraContext.TransparentBuffer, SolidMesh, _renderTransforms, _parentTransforms, _renderShapes, Materials[TransparentMaterialName]);

            _renderTransforms.Clear();
            _renderShapes.Clear();
            _transientCache.Collect(_renderTransforms, _parentTransforms, _renderShapes, ShapeCache.CollectType.Wireframe);
            _shapeCache.Collect(_renderTransforms, _parentTransforms, _renderShapes, ShapeCache.CollectType.Wireframe);
            RenderInstances(cameraContext, cameraContext.OpaqueBuffer, WireframeMesh, _renderTransforms, _parentTransforms, _renderShapes, Materials[WireframeMaterialName]);
        }
Exemplo n.º 3
0
//----------------------------------------------------------------------------------------------------------------------
        static void RaytraceHardShadowPreRender(Camera cam)
        {
            if (!IsValidCamera(cam))
            {
                return;
            }

            CameraContext ctx = Misc.GetOrAddValue(s_cameraContexts, cam);

            m_curShadowRaytracers = GetEditorShadowRaytracers();
            foreach (ShadowRaytracer shadowRaytracer in m_curShadowRaytracers)
            {
                if (!shadowRaytracer.IsPreviewShownInSceneView())
                {
                    continue;
                }
                CameraContext.Record rec = Misc.GetOrAddValue(ctx.records, shadowRaytracer);
                shadowRaytracer.Render(cam, ref rec.outputTexture, true);
            }

            ++ctx.updateCount;
            if (ctx.updateCount % 128 == 0)
            {
                Misc.RemoveNullKeys(ctx.records);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 本控制器接管
 /// </summary>
 public override void Enter(CameraContext context)
 {
     SendCameraFocusPosToLogic(0);
     setFPS(true);
     SetupByCamParam();
     ResetExternOBCameraInfo();
 }
Exemplo n.º 5
0
        protected virtual void RenderInstances(CameraContext cameraContext, CommandBuffer renderQueue, Mesh mesh,
                                               List <Matrix4x4> transforms, List <Matrix4x4> parentTransforms,
                                               List <CreateMessage> shapes, Material material)
        {
            CategoriesState categories = this.CategoriesState;

            // Handle instancing block size limits.
            for (int i = 0; i < transforms.Count; i += _instanceTransforms.Length)
            {
                MaterialPropertyBlock materialProperties = new MaterialPropertyBlock();
                int itemCount = 0;
                _instanceColours.Clear();
                for (int j = 0; j < _instanceTransforms.Length && j + i < transforms.Count; ++j)
                {
                    if (categories == null || categories.IsActive(shapes[i + j].Category))
                    {
                        _instanceTransforms[itemCount] =
                            cameraContext.TesSceneToWorldTransform * parentTransforms[i + j] * transforms[i + j];
                        Maths.Colour colour = new Maths.Colour(shapes[i + j].Attributes.Colour);
                        _instanceColours.Add(Maths.ColourExt.ToUnityVector4(colour));
                        ++itemCount;
                    }
                }

                if (itemCount > 0)
                {
                    materialProperties.SetVectorArray("_Color", _instanceColours);
                    renderQueue.DrawMeshInstanced(mesh, 0, material, 0, _instanceTransforms, itemCount, materialProperties);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 本控制器接管
        /// </summary>
        public override void Enter(CameraContext context)
        {
            SetupByCamParam();

            DataCenter.WarFrontSightDataManager.Instance.FrontSightVisible = false;
            MouseCursorManager.Instance.MouseCursorVisible = true;
        }
Exemplo n.º 7
0
 /// <summary>
 /// 本控制器接管
 /// </summary>
 public override void Enter(CameraContext context)
 {
     ResetExternOBCameraInfo();
     this.soldierController.SetStopMove(true);
     this.soldierCam.target.gameObject.SetActive(false);
     if (!al)
     {
         al = this.soldierCam.CurrentCamera.gameObject.AddComponent <AudioListener>();
     }
     al.enabled = true;
 }
Exemplo n.º 8
0
    public override CameraContext CameraUpdate(CameraContext modifier, float dt)
    {
        multiFollow = multiFollow.Where(f => f).ToArray();
        if (multiFollow.Length > 0)
        {
            focusPosition = multiFollow.Sum(target => target.transform.position.ToVector2()) / multiFollow.Length;
            if (multiFollow.Length > 1)
            {
                Debug.DrawLine(transform.position, focusPosition, Color.cyan);
                var offset = (multiFollow[0].transform.position.ToVector2() - focusPosition);
                offset = math.abs(offset);
                offset = (offset - MultiFollowRange) / (MaxFollowRange - MultiFollowRange);
                offset = math.clamp(offset, 0, 1);
                var distance = Mathf.Max(offset.x, offset.y);
                distance       = Mathf.Pow(Mathf.Clamp01(offset.magnitude), 2);
                focusPosition += (multiFollow[0].transform.position.ToVector2() - focusPosition) * distance;
            }
        }
        else
        {
            focusPosition = transform.position;
        }
        Debug.DrawLine(transform.position, focusPosition, Color.green);

        var follow = focusPosition - movePosition - FollowRangeOffset;
        var followAccelerateRange = MaxFollowRange - FollowStartRange;

        if (follow.magnitude > FollowIgnoreRange)
        {
            follow.x         = Mathf.Clamp01((Mathf.Abs(follow.x) - FollowStartRange.x) / followAccelerateRange.x) * Mathf.Sign(follow.x);
            follow.y         = Mathf.Clamp01((Mathf.Abs(follow.y) - FollowStartRange.y) / followAccelerateRange.y) * Mathf.Sign(follow.y);
            this.followSpeed = follow;
            //followSpeed = follow * MaxSpeed;
            //followSpeed = follow.normalized * Mathf.Clamp01((follow.magnitude - FollowIgnoreRange) / FollowRange) * MaxSpeed;
        }

        followSpeed *= MaxSpeed;
        var dv = followSpeed - velocity;

        if (dv.magnitude / Time.fixedDeltaTime > MaxAcceleration)
        {
            dv          = dv.normalized * MaxAcceleration * Time.fixedDeltaTime;
            followSpeed = velocity + dv;
        }

        followSpeed.x *= Mathf.Clamp01(1 + Mathf.Pow(seperate.x, 5) * MathUtility.SignInt(followSpeed.x));
        followSpeed.y *= Mathf.Clamp01(1 + Mathf.Pow(seperate.y, 5) * MathUtility.SignInt(followSpeed.y));

        velocity          = followSpeed;
        movePosition     += velocity * dt;
        modifier.Position = movePosition;
        return(modifier);
    }
Exemplo n.º 9
0
 /// <summary>
 /// Render all the current objects.
 /// </summary>
 public override void Render(CameraContext cameraContext)
 {
     // TODO: (KS) category handling.
     foreach (int index in _transientCache.ShapeIndices)
     {
         RenderMeshes(cameraContext, _transientCache, index);
     }
     foreach (int index in _shapeCache.ShapeIndices)
     {
         RenderMeshes(cameraContext, _shapeCache, index);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// 本控制器接管
        /// </summary>
        public override void Enter(CameraContext context)
        {
            //直接结束
            if (context == null)
            {
                EnterGodEyeMode();
                return;
            }
            MapGodCamContext _context = context as MapGodCamContext;

            EnterGodEyeMode(_context.pos, _context.angle, _context.dir, _context.tran, _context.distance, _context.fov);
        }
Exemplo n.º 11
0
 public CameraSteps(CameraContext cameraContext,
                    WorldContext worldContext,
                    PointsContext pointsContext,
                    VectorsContext vectorsContext,
                    RayContext rayContext)
 {
     _rayContext     = rayContext;
     _vectorsContext = vectorsContext;
     _pointsContext  = pointsContext;
     _worldContext   = worldContext;
     _cameraContext  = cameraContext;
 }
Exemplo n.º 12
0
 public void Awake()
 {
     SceneRefs.Set(this);
     dispatcher = Service.Get <EventDispatcher>();
     mainCamera = Camera.main.transform;
     nodes      = new Transform[3];
     nodes[0]   = GameplayCameraLeaf;
     nodes[1]   = CinematicCameraLeaf;
     nodes[2]   = ChaseCameraLeaf;
     curNode    = CameraContext.Gameplay;
     nextNode   = curNode;
 }
Exemplo n.º 13
0
        /// <summary>
        /// 本控制器接管
        /// </summary>
        public override void Enter(CameraContext context)
        {
            if (context != null)
            {
                OBMoveFreeContext obContext   = context as OBMoveFreeContext;
                GodEyeStateParam  godEyeParam = new GodEyeStateParam(obContext.pos, obContext.angle, new Vector3(0, 0, -1), Vector3.zero, 8, 60);
                UpdateFocusPos(godEyeParam);
            }

            EnterOBMode();
            this.soldierController.SetStopMove(true);
            DataCenter.WarFrontSightDataManager.Instance.FrontSightVisible = false;
        }
Exemplo n.º 14
0
        /// <summary>
        /// 本控制器接管
        /// </summary>
        public override void Enter(CameraContext context)
        {
            SetupByCamParam();
            m_defaultScrollSpeed = CurCameraProperty.ScrollSpeed;

            curCameraModeParam.distanceRange = new Vector2(5, 30);
            CurCameraProperty.ScrollSpeed    = soldierCam.OBCtrlMouseScrollSpeed;

            EnterOBMode();

            DataCenter.WarFrontSightDataManager.Instance.FrontSightVisible = false;
            MouseCursorManager.Instance.MouseCursorVisible = true;
        }
Exemplo n.º 15
0
        public override void Render(CameraContext cameraContext)
        {
            // TODO: (KS) Resolve categories.
            foreach (int shapeIndex in _transientCache.ShapeIndices)
            {
                RenderObject(cameraContext, _transientCache, shapeIndex);
            }

            foreach (int shapeIndex in _shapeCache.ShapeIndices)
            {
                RenderObject(cameraContext, _shapeCache, shapeIndex);
            }
        }
Exemplo n.º 16
0
    //外部状态强制切换
    private void HandleModeForceSwitch(CameraMode mode, CameraContext context = null)
    {
        if (!Reset(false))
        {
            return;
        }
        BaseCameraController camCtrl = CameraUtil.GetCamCtrl(mode);

        if (camCtrl.Enable(false) && camCtrl.CheckContext(context))
        {
            SwitchCamMode(mode, context);
        }
    }
Exemplo n.º 17
0
        /// <summary>
        /// 本控制器接管
        /// </summary>
        public override void Enter(CameraContext context)
        {
            AnimCamContext _context = context as AnimCamContext;

            SetupDatas(_context);
            Animation anim = animGo.AddComponent <Animation>();

            if (anim != null)
            {
                anim.AddClip(_context.clip, _context.clip.name);
                anim.Play(_context.clip.name);
            }
            SendCameraFocusPosToLogic(0);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 判断Context是否存在且无误
        /// </summary>
        /// <param name="bEnabled"></param>
        public override bool CheckContext(CameraContext context)
        {
            AnimCamContext _context = context as AnimCamContext;

            if (_context != null && _context.clip != null)
            {
                return(true);
            }
            else
            {
                CameraUtil.LogError("_context.clip is null! : " + _context);
                return(false);
            }
        }
Exemplo n.º 19
0
        private static void State()
        {
            CameraContext cameraContext = GetCameraContext();

            if (cameraContext != null)
            {
                string friendlyName = cameraContext.FriendlyName;
                var    nativeCamera = new NativeCamera();
                int    currentState = 0;

                nativeCamera.GetPrivacy(friendlyName, ref currentState);

                Console.WriteLine($"Current state of {friendlyName} is {CoreRuntimeDefs.StateOnOff[currentState]}");
            }
        }
Exemplo n.º 20
0
 //内部状态切换
 private void RefreshCameraMode(CameraContext context = null)
 {
     if (!Reset(false))
     {
         return;
     }
     for (int i = 0; i < camCtrl.AllowChangeList.Count; i++)
     {
         BaseCameraController canCtrl = CameraUtil.GetCamCtrl(camCtrl.AllowChangeList[i]);
         if (canCtrl.Enable(true) && canCtrl.CheckContext(context))
         {
             SwitchCamMode(camCtrl.AllowChangeList[i], context);
             break;
         }
     }
 }
Exemplo n.º 21
0
 private bool onChangeCameraContextEvent(CinematographyEvents.ChangeCameraContextEvent evt)
 {
     if (nextNode != evt.Context)
     {
         blendCurve    = evt.BlendCurve;
         blendDuration = evt.BlendDuration;
         if (curNode == evt.Context)
         {
             isBlendingFromPrevFrame = true;
             prevCamPos = mainCamera.position;
             prevCamRot = mainCamera.rotation;
         }
         nextNode     = evt.Context;
         curBlendTime = 0f;
         isBlending   = true;
     }
     return(false);
 }
Exemplo n.º 22
0
        private static void Toggle()
        {
            CameraContext cameraContext = GetCameraContext();

            if (cameraContext != null)
            {
                string friendlyName = cameraContext.FriendlyName;
                var    nativeCamera = new NativeCamera();
                int    currentState = 0;

                nativeCamera.GetPrivacy(friendlyName, ref currentState);

                var newState = ToggleState(currentState);

                Console.WriteLine($"Toggling {friendlyName} from {CoreRuntimeDefs.StateOnOff[currentState]} to {newState}");

                nativeCamera.SetPrivacy(friendlyName, CoreRuntimeDefs.State01[newState]);
            }
        }
Exemplo n.º 23
0
    private void FixedUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        var context = new CameraContext()
        {
            Position = transform.position,
            ViewPort = ViewportRect
        };

        GetComponents <CameraPlugin>()
        .Where(plugin => plugin.Enabled)
        .ForEach(plugin => context = plugin.CameraUpdate(context, Time.fixedDeltaTime));

        GetComponent <Rigidbody2D>().MovePosition(context.Position);
        Camera.transform.position = transform.position;
        //GetComponent<Rigidbody2D>().MovePosition(Position);
    }
Exemplo n.º 24
0
 public void OnPreRender()
 {
     _opaqueBuffer.Clear();
     _transparentBuffer.Clear();
     // AddLights();
     if (_thirdEyeScene != null)
     {
         Camera camera = GetComponent <Camera>();
         if (camera != null)
         {
             CameraContext cameraContext = new CameraContext
             {
                 CameraToWorldTransform = camera.transform.localToWorldMatrix,
                 CameraFrustumPlanes    = GeometryUtility.CalculateFrustumPlanes(camera),
                 OpaqueBuffer           = _opaqueBuffer,
                 TransparentBuffer      = _transparentBuffer
             };
             _thirdEyeScene.Render(cameraContext);
         }
     }
 }
Exemplo n.º 25
0
    public void LateUpdate()
    {
        if (!isBlending)
        {
            mainCamera.position = nodes[(int)curNode].position;
            mainCamera.rotation = nodes[(int)curNode].rotation;
            return;
        }
        curBlendTime += Time.deltaTime / Mathf.Max(blendDuration, 0.01f);
        float t = 0f;

        if (curBlendTime > 1f)
        {
            curBlendTime = 1f;
            t            = 1f;
        }
        else if (blendCurve != null && blendCurve.keys.Length > 0)
        {
            t = blendCurve.Evaluate(curBlendTime);
        }
        if (isBlendingFromPrevFrame)
        {
            mainCamera.position = Vector3.Lerp(prevCamPos, nodes[(int)nextNode].position, t);
            mainCamera.rotation = Quaternion.Slerp(prevCamRot, nodes[(int)nextNode].rotation, t);
        }
        else
        {
            mainCamera.position = Vector3.Lerp(nodes[(int)curNode].position, nodes[(int)nextNode].position, t);
            mainCamera.rotation = Quaternion.Slerp(nodes[(int)curNode].rotation, nodes[(int)nextNode].rotation, t);
        }
        if (curBlendTime >= 1f)
        {
            CameraContext fromCamera = curNode;
            curNode    = nextNode;
            isBlending = false;
            isBlendingFromPrevFrame = false;
            dispatcher.DispatchEvent(new CinematographyEvents.CameraBlendComplete(fromCamera, curNode));
        }
    }
Exemplo n.º 26
0
        /// <summary>
        /// 本控制器接管
        /// </summary>
        public override void Enter(CameraContext context)
        {
            isArrive = false;
            EndWarCamContext _context = context as EndWarCamContext;

            this.targetPos = _context.targetPos;
            this.curPos    = _context.curPos;
            float realAngle = 0;

            if (GetSceneAngleY(ref realAngle))   //根据地图和阵营获得对应的旋转角度Y轴
            {
                Vector3 godDir = new Vector3(0, 0, -1);
                oldGodDistance    = tmpGodDistanceMax;
                tmpGodDistanceMax = ENDWAR_GOD_DISTANCE;
                //如果输了,镜头翻转,否则会被高台挡住基地爆炸
                if (!soldierCam.isWin)
                {
                    realAngle += 180;
                }
                EnterGodEyeMode(_context.curPos, new Vector3(50.0f, realAngle, 0.0f), godDir, new Vector3(0, 0, 0), 100.0f, 30.0f, false);
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// 更新相机数据
 /// </summary>
 /// <param name="context"></param>
 public override void UpdateData(CameraContext context)
 {
 }
Exemplo n.º 28
0
 /// <summary>
 /// 判断Context是否存在且无误
 /// </summary>
 /// <param name="bEnabled"></param>
 public override bool CheckGodContext(CameraContext context)
 {
     return(true);
 }
Exemplo n.º 29
0
 /// <summary>
 /// 本控制器接管
 /// </summary>
 public override void Enter(CameraContext context)
 {
     SwitchTarget();
 }
 /// <summary>
 /// 本控制器接管
 /// </summary>
 public override void Enter(CameraContext context)
 {
     SendCameraFocusPosToLogic(0);
     OpenSniperscope();
     SetupByCamParam();
 }