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); }
/// <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]); }
//---------------------------------------------------------------------------------------------------------------------- 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); } }
/// <summary> /// 本控制器接管 /// </summary> public override void Enter(CameraContext context) { SendCameraFocusPosToLogic(0); setFPS(true); SetupByCamParam(); ResetExternOBCameraInfo(); }
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); } } }
/// <summary> /// 本控制器接管 /// </summary> public override void Enter(CameraContext context) { SetupByCamParam(); DataCenter.WarFrontSightDataManager.Instance.FrontSightVisible = false; MouseCursorManager.Instance.MouseCursorVisible = true; }
/// <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; }
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); }
/// <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); } }
/// <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); }
public CameraSteps(CameraContext cameraContext, WorldContext worldContext, PointsContext pointsContext, VectorsContext vectorsContext, RayContext rayContext) { _rayContext = rayContext; _vectorsContext = vectorsContext; _pointsContext = pointsContext; _worldContext = worldContext; _cameraContext = cameraContext; }
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; }
/// <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; }
/// <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; }
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); } }
//外部状态强制切换 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); } }
/// <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); }
/// <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); } }
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]}"); } }
//内部状态切换 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; } } }
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); }
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]); } }
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); }
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); } } }
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)); } }
/// <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); } }
/// <summary> /// 更新相机数据 /// </summary> /// <param name="context"></param> public override void UpdateData(CameraContext context) { }
/// <summary> /// 判断Context是否存在且无误 /// </summary> /// <param name="bEnabled"></param> public override bool CheckGodContext(CameraContext context) { return(true); }
/// <summary> /// 本控制器接管 /// </summary> public override void Enter(CameraContext context) { SwitchTarget(); }
/// <summary> /// 本控制器接管 /// </summary> public override void Enter(CameraContext context) { SendCameraFocusPosToLogic(0); OpenSniperscope(); SetupByCamParam(); }