/// <inheritdoc /> public bool RegisterPointer(IMixedRealityPointer pointer) { Debug.Assert(pointer.PointerId != 0, $"{pointer} does not have a valid pointer id!"); if (IsPointerRegistered(pointer)) { return(false); } var pointerData = new PointerData(pointer); pointers.Add(pointerData); // Initialize the pointer result UpdatePointer(pointerData); return(true); }
public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource pointingSource) { for (int iPointer = 0; iPointer < pointers.Count; iPointer++) { PointerData pointer = pointers[iPointer]; if (pointer.PointingSource.OwnsInput(eventData)) { pointingSource = pointer.PointingSource; return(true); } } pointingSource = null; return(false); }
/// <summary> /// Adds a point to the current path segment /// </summary> /// <param name="addition">point to add</param> public void AddPoint(PointerData addition) { Phase phase = addition.Phase; if (mCollectPointerData) { if (phase == Phase.Begin) { // Clear the pointer data list mPointerDataList.Clear(); } mPointerDataList.Add(addition); } var geometry = mPathProducer.Add(phase, addition, null); mPathSegment.Add(phase, geometry.Addition, geometry.Prediction); }
private void UpdatePointers() { bool gazeManagerIsRegistered = false; for (int iPointer = 0; iPointer < pointers.Count; iPointer++) { PointerData pointer = pointers[iPointer]; if (pointer == gazeManagerPointingData) { gazeManagerIsRegistered = true; } UpdatePointer(pointer); if (debugDrawPointingRays) { Color rayColor; if ((debugDrawPointingRayColors != null) && (debugDrawPointingRayColors.Length > 0)) { rayColor = debugDrawPointingRayColors[iPointer % debugDrawPointingRayColors.Length]; } else { rayColor = Color.green; } Debug.DrawRay(pointer.StartPoint, (pointer.End.Point - pointer.StartPoint), rayColor); } } if (gazeManagerPointingData != null) { Debug.Assert(ReferenceEquals(gazeManagerPointingData.PointingSource, GazeManager.Instance)); if (!gazeManagerIsRegistered) { UpdatePointer(gazeManagerPointingData); } GazeManager.Instance.UpdateHitDetails(gazeManagerPointingData.End, gazeManagerPointingData.LastRaycastHit, gazeManagerIsRegistered); } }
/// <summary> /// Process the active pointers from MixedRealityInputManager and all other Unity input. /// </summary> public override void Process() { using (ProcessPerfMarker.Auto()) { CursorLockMode cursorLockStateBackup = Cursor.lockState; try { // Disable cursor lock for MRTK pointers. Cursor.lockState = CursorLockMode.None; // Process pointer events as mouse events. foreach (var p in pointerDataToUpdate) { PointerData pointerData = p.Value; IMixedRealityPointer pointer = pointerData.pointer; if (pointer.IsInteractionEnabled && pointer.Rays != null && pointer.Rays.Length > 0 && pointer.SceneQueryType == Physics.SceneQueryType.SimpleRaycast) { ProcessMouseEvent((int)pointer.PointerId); } else { ProcessMrtkPointerLost(pointerData); } } for (int i = 0; i < pointerDataToRemove.Count; i++) { ProcessMrtkPointerLost(pointerDataToRemove[i]); } pointerDataToRemove.Clear(); } finally { Cursor.lockState = cursorLockStateBackup; } base.Process(); } }
/// <summary> /// Calculator delegate for input from a stylus (pen) /// Calculates the path point properties based on pointer input. /// </summary> /// <param name="previous"></param> /// <param name="current"></param> /// <param name="next"></param> /// <returns>PathPoint with calculated properties</returns> protected override PathPoint CalculatorForStylus(PointerData previous, PointerData current, PointerData next) { // calculate the offset of the pencil tip due to tilted position var cosAltitudeAngle = (float)Math.Cos(current.AltitudeAngle.Value); var sinAzimuthAngle = (float)Math.Sin(current.AzimuthAngle.Value); var cosAzimuthAngle = (float)Math.Cos(current.AzimuthAngle.Value); var x = sinAzimuthAngle * cosAltitudeAngle; var y = cosAltitudeAngle * cosAzimuthAngle; var offsetY = 5f * -x; var offsetX = 5f * -y; // compute the rotation var rotation = current.ComputeNearestAzimuthAngle(previous); // Normalize the tilt be minimum seen altitude angle and the maximum with the pen straight up const float piBy2 = (float)(Math.PI / 2); var tiltScale = Math.Min(1f, (piBy2 - current.AltitudeAngle.Value) / (piBy2 - MinAltitudeAngle)); var size = Math.Max(MinSize, MinSize + (MaxSize - MinSize) * tiltScale); //var rotation = current.ComputeNearestAzimuthAngle(previous); // Change the intensity of alpha value by pressure of speed var alpha = (!current.Force.HasValue) ? current.ComputeValueBasedOnSpeed(previous, next, MinAlpha, MaxAlpha, null, null, 0f, 3500f, v => 1 - v) : ComputeValueBasedOnPressure(current, 0.1f, 0.7f, 0.0f, 1.0f); if (!alpha.HasValue) { alpha = PreviousAlpha; } else { PreviousAlpha = alpha.Value; } PathPoint pp = new PathPoint(current.X, current.Y) { Size = size, Alpha = alpha, Rotation = rotation, OffsetX = offsetX, OffsetY = offsetY }; return(pp); }
private void UpdatePointer(PointerData pointer) { // Call the pointer's OnPreRaycast function // This will give it a chance to prepare itself for raycasts // eg, by building its Rays array pointer.PointingSource.OnPreRaycast(); // If pointer interaction isn't enabled, clear its result object and return if (!pointer.PointingSource.InteractionEnabled) { // Don't clear the previous focused object since we still want to trigger FocusExit events pointer.ResetFocusedObjects(false); } else { // If the pointer is locked // Keep the focus objects the same // This will ensure that we execute events on those objects // even if the pointer isn't pointing at them if (!pointer.PointingSource.FocusLocked) { // Otherwise, continue var prioritizedLayerMasks = (pointer.PointingSource.PrioritizedLayerMasksOverride ?? pointingRaycastLayerMasks); // Perform raycast to determine focused object RaycastPhysics(pointer, prioritizedLayerMasks); // If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions if (EventSystem.current != null) { // NOTE: We need to do this AFTER RaycastPhysics so we use the current hit point to perform the correct 2D UI Raycast. RaycastUnityUI(pointer, prioritizedLayerMasks); } // Set the pointer's result last pointer.PointingSource.Result = pointer; } } // Call the pointer's OnPostRaycast function // This will give it a chance to respond to raycast results // eg by updating its appearance pointer.PointingSource.OnPostRaycast(); }
private void RaycastUnityUI(PointerData pointer, LayerMask[] prioritizedLayerMasks) { Debug.Assert(pointer.End.Point != Vector3.zero, "No pointer source end point found to raycast against!"); Debug.Assert(UIRaycastCamera != null, "You must assign a UIRaycastCamera on the FocusManager before you can process uGUI raycasting."); RaycastResult uiRaycastResult = default(RaycastResult); bool overridePhysicsRaycast = false; RayStep rayStep = default(RayStep); int rayStepIndex = 0; // Comment back in GetType() only when debugging for a specific pointer. Debug.Assert(pointer.PointingSource.Rays != null, "No valid rays for pointer " /* + pointer.GetType()*/); Debug.Assert(pointer.PointingSource.Rays.Length > 0, "No valid rays for pointer " /* + pointer.GetType()*/); // Cast rays for every step until we score a hit for (int i = 0; i < pointer.PointingSource.Rays.Length; i++) { if (RaycastUnityUIStep(pointer, pointer.PointingSource.Rays[i], prioritizedLayerMasks, out overridePhysicsRaycast, out uiRaycastResult)) { rayStepIndex = i; rayStep = pointer.PointingSource.Rays[i]; break; } } // Check if we need to overwrite the physics raycast info if ((pointer.End.Object == null || overridePhysicsRaycast) && uiRaycastResult.isValid && uiRaycastResult.module != null && uiRaycastResult.module.eventCamera == UIRaycastCamera) { newUiRaycastPosition.x = uiRaycastResult.screenPosition.x; newUiRaycastPosition.y = uiRaycastResult.screenPosition.y; newUiRaycastPosition.z = uiRaycastResult.distance; Vector3 worldPos = UIRaycastCamera.ScreenToWorldPoint(newUiRaycastPosition); var hitInfo = new RaycastHit { point = worldPos, normal = -uiRaycastResult.gameObject.transform.forward }; pointer.UpdateHit(uiRaycastResult, hitInfo, rayStep, rayStepIndex); } }
/// <summary> /// Perform a Unity Graphics Raycast to determine which uGUI element is currently being gazed at, if any. /// </summary> /// <param name="pointer"></param> /// <param name="prioritizedLayerMasks"></param> private void RaycastGraphics(PointerData pointer, LayerMask[] prioritizedLayerMasks) { Debug.Assert(pointer.Details.Point != Vector3.zero, "Invalid pointer source start point found to raycast from!"); Debug.Assert(UIRaycastCamera != null, "You must assign a UIRaycastCamera on the FocusProvider before you can process uGUI raycasting."); RaycastResult raycastResult = default(RaycastResult); bool overridePhysicsRaycast = false; RayStep rayStep = default(RayStep); int rayStepIndex = 0; Debug.Assert(pointer.Pointer.Rays != null, "No valid rays for pointer"); Debug.Assert(pointer.Pointer.Rays.Length > 0, "No valid rays for pointer"); // Cast rays for every step until we score a hit for (int i = 0; i < pointer.Pointer.Rays.Length; i++) { if (RaycastGraphicsStep(pointer, pointer.Pointer.Rays[i], prioritizedLayerMasks, out overridePhysicsRaycast, out raycastResult)) { rayStepIndex = i; rayStep = pointer.Pointer.Rays[i]; break; } } // Check if we need to overwrite the physics raycast info if ((pointer.CurrentPointerTarget == null || overridePhysicsRaycast) && raycastResult.isValid && raycastResult.module != null && raycastResult.module.eventCamera == UIRaycastCamera) { newUiRaycastPosition.x = raycastResult.screenPosition.x; newUiRaycastPosition.y = raycastResult.screenPosition.y; newUiRaycastPosition.z = raycastResult.distance; Vector3 worldPos = UIRaycastCamera.ScreenToWorldPoint(newUiRaycastPosition); var hitInfo = new RaycastHit { point = worldPos, normal = -raycastResult.gameObject.transform.forward }; pointer.UpdateHit(raycastResult, hitInfo, rayStep, rayStepIndex); } }
private void Start() { if (gazeManagerPointingData == null) { if (GazeManager.IsInitialized) { gazeManagerPointingData = new PointerData(GazeManager.Instance); } } else { Debug.Assert(ReferenceEquals(gazeManagerPointingData.PointingSource, GazeManager.Instance)); } if ((pointers.Count == 0) && autoRegisterGazePointerIfNoPointersRegistered && GazeManager.IsInitialized) { RegisterPointer(GazeManager.Instance); } }
protected override void DoSetData(PointerData data) { _playerId = PlayerCastData.EntityId(data.IdList); var playerEntity = _playerContext.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(_playerId, (short)EEntityType.Player)); if (null != playerEntity && playerEntity.hasGamePlay) { var player = _playerContext.flagSelfEntity; if (player.gamePlay.IsLifeState(EPlayerLifeState.Alive) && !player.gamePlay.IsSave && //自己是活着 playerEntity.playerInfo.TeamId == player.playerInfo.TeamId && !playerEntity.gamePlay.IsBeSave && //是队友 playerEntity.gamePlay.IsLifeState(EPlayerLifeState.Dying) && //队友是受伤状态 Vector3.Distance(player.position.Value, playerEntity.position.Value) <= SharedConfig.MaxSaveDistance //距离 ) { Tip = string.Format(ScriptLocalization.client_actiontip.saveplayer, playerEntity.playerInfo.PlayerName); } } }
private void RegisterPointers(IMixedRealityInputSource inputSource) { // If our input source does not have any pointers, then skip. if (inputSource.Pointers == null) { return; } for (int i = 0; i < inputSource.Pointers.Length; i++) { RegisterPointer(inputSource.Pointers[i]); // Special Registration for Gaze if (inputSource.SourceId == MixedRealityToolkit.InputSystem.GazeProvider.GazeInputSource.SourceId && gazeProviderPointingData == null) { gazeProviderPointingData = new PointerData(inputSource.Pointers[i]); } } }
/// <summary> /// Calculator delegate for input from mouse input /// Calculates the path point properties based on pointer input. /// </summary> /// <param name="previous"></param> /// <param name="current"></param> /// <param name="next"></param> /// <returns>PathPoint with calculated properties</returns> protected PathPoint CalculatorForMouseAndTouch(PointerData previous, PointerData current, PointerData next) { var size = current.ComputeValueBasedOnSpeed(previous, next, SizeConfig.minValue, SizeConfig.maxValue, SizeConfig.initValue, SizeConfig.finalValue, SizeConfig.minSpeed, SizeConfig.maxSpeed, SizeConfig.remap); if (size.HasValue) { PreviousSize = size.Value; } else { size = PreviousSize; } PathPoint pp = new PathPoint(current.X, current.Y) { Size = size }; return(pp); }
// ---- Unity events void Awake() { m_Instance = this; Debug.Assert(m_MaxPointers > 0); m_Pointers = new PointerData[m_MaxPointers]; for (int i = 0; i < m_Pointers.Length; ++i) { //set our main pointer as the zero index bool bMain = (i == 0); var data = new PointerData(); GameObject obj = (GameObject)Instantiate(bMain ? m_MainPointerPrefab : m_AuxPointerPrefab); obj.transform.parent = transform; data.m_Script = obj.GetComponent <PointerScript>(); data.m_Script.EnableDebugViewControlPoints(bMain && m_DebugViewControlPoints); data.m_Script.ChildIndex = i; data.m_UiEnabled = bMain; m_Pointers[i] = data; if (bMain) { m_MainPointerData = data; } } m_CurrentLineCreationState = LineCreationState.WaitingForInput; m_StraightEdgeProxyActive = false; m_StraightEdgeGesture = new CircleGesture(); if (m_SymmetryWidget) { m_SymmetryWidgetScript = m_SymmetryWidget.GetComponent <SymmetryWidget>(); } //initialize rendering requests to default to hiding everything m_PointersRenderingRequested = false; m_PointersRenderingActive = true; m_FreePaintPointerAngle = PlayerPrefs.GetFloat(PLAYER_PREFS_POINTER_ANGLE, m_DefaultPointerAngle); }
void OnSourceLost(IMixedRealityInputSource inputSource) { for (int i = 0; i < inputSource.Pointers.Length; i++) { var pointer = inputSource.Pointers[i]; if (pointer.InputSourceParent == inputSource) { int pointerId = (int)pointer.PointerId; Debug.Assert(pointerDataToUpdate.ContainsKey(pointerId)); PointerData pointerData = null; if (pointerDataToUpdate.TryGetValue(pointerId, out pointerData)) { Debug.Assert(!pointerDataToRemove.Contains(pointerData)); pointerDataToRemove.Add(pointerData); pointerDataToUpdate.Remove(pointerId); } } } }
public void SetData(PointerData data) { Tip = ""; var useActionEnalbed = IsUseActionEnabled(); if (Logger.IsDebugEnabled) { Logger.DebugFormat("IsUserActionEnabled {0}", useActionEnalbed); } if (!useActionEnalbed) { return; } var player = _playerContext.flagSelfEntity; if (null == player || player.gamePlay.LifeState == (int)EPlayerLifeState.Dead) { return; } DoSetData(data); }
protected float?ComputeValueBasedOnPressure(PointerData pointerData, float minValue, float maxValue, float minPressure = 100f, float maxPressure = 4000f, bool reverse = false, Func <float, float> remap = null) { if (!pointerData.Force.HasValue) { throw new InvalidOperationException(""); } float normalizePressure = (reverse) ? minPressure + (1 - pointerData.Force.Value) * (maxPressure - minPressure) : minPressure + pointerData.Force.Value * (maxPressure - minPressure); var pressureClamped = Math.Min(Math.Max(normalizePressure, minPressure), maxPressure); var k = (pressureClamped - minPressure) / (maxPressure - minPressure); if (remap != null) { k = remap(k); } return(minValue + k * (maxValue - minValue)); }
protected void ResetMousePointerEventData(PointerData pointerData) { // Invalidate last mouse point. pointerData.lastMousePoint3d = null; pointerData.pointer.Result = null; pointerData.eventDataLeft.pointerCurrentRaycast = new RaycastResult(); // Populate the data for the buttons pointerData.eventDataLeft.button = PointerEventData.InputButton.Left; pointerData.mouseState.SetButtonState(PointerEventData.InputButton.Left, PointerEventData.FramePressState.NotChanged, pointerData.eventDataLeft); // Need to provide data for middle and right button for MouseState, although not used by MRTK pointers. CopyFromTo(pointerData.eventDataLeft, pointerData.eventDataRight); pointerData.eventDataRight.button = PointerEventData.InputButton.Right; pointerData.mouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, pointerData.eventDataRight); CopyFromTo(pointerData.eventDataLeft, pointerData.eventDataMiddle); pointerData.eventDataMiddle.button = PointerEventData.InputButton.Middle; pointerData.mouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, pointerData.eventDataMiddle); }
/// <inheritdoc /> public void OnSourceLost(SourceStateEventData eventData) { // If the input source does not have pointers, then skip. if (eventData.InputSource.Pointers == null) { return; } // Let the pointer behavior know that the pointer has been lost IMixedRealityPointerMediator mediator; if (pointerMediators.TryGetValue(eventData.SourceId, out mediator)) { mediator.UnregisterPointers(eventData.InputSource.Pointers); } pointerMediators.Remove(eventData.SourceId); for (var i = 0; i < eventData.InputSource.Pointers.Length; i++) { // Special unregistration for Gaze if (gazeProviderPointingData != null && eventData.InputSource.Pointers[i].PointerId == gazeProviderPointingData.Pointer.PointerId) { // If the source lost is the gaze input source, then reset it. if (eventData.InputSource.SourceId == ((IMixedRealityInputSystem)Service).GazeProvider?.GazeInputSource.SourceId) { gazeProviderPointingData.ResetFocusedObjects(); gazeProviderPointingData = null; } // Otherwise, don't unregister the gaze pointer, since the gaze input source is still active. else { continue; } } UnregisterPointer(eventData.InputSource.Pointers[i]); } }
/// <summary> /// Calculator delegate for input from a stylus (pen) /// Calculates the path point properties based on pointer input. /// </summary> /// <param name="previous"></param> /// <param name="current"></param> /// <param name="next"></param> /// <returns>PathPoint with calculated properties</returns> private PathPoint CalculatorForStylus(PointerData previous, PointerData current, PointerData next) { float?size; if (!current.Force.HasValue) { size = current.ComputeValueBasedOnSpeed(previous, next, 1.5f, 10.2f, null, null, 0, 3500, v => (float)Math.Pow(v, 1.17f)); } else { size = ComputeValueBasedOnPressure(current, 1.5f, 10.2f, 0, 1, false, v => (float)Math.Pow(v, 1.17f)); } if (size.HasValue) { PreviousSize = size.Value; } else { size = PreviousSize; } var cosAltitudeAngle = (float)Math.Abs(Math.Cos(current.AltitudeAngle.Value)); var tiltScale = 1.5f * cosAltitudeAngle; var scaleX = 1.0f + tiltScale; var offsetX = size * tiltScale; var rotation = current.ComputeNearestAzimuthAngle(previous); PathPoint pp = new PathPoint(current.X, current.Y) { Size = size, Rotation = rotation, ScaleX = scaleX, OffsetX = offsetX }; return(pp); }
public void RegisterPointer(IPointingSource pointingSource) { Debug.Assert(pointingSource != null, "Can't register a pointer if you give us one."); int pointerIndex; PointerData pointer; if (TryGetPointerIndex(pointingSource, out pointerIndex)) { // This pointing source is already registered and active. return; } if (pointingSource is GazeManager) { if (gazeManagerPointingData == null) { if (GazeManager.IsInitialized) { gazeManagerPointingData = new PointerData(GazeManager.Instance); } } else { Debug.Assert(ReferenceEquals(gazeManagerPointingData.PointingSource, GazeManager.Instance)); gazeManagerPointingData.ResetFocusedObjects(); } Debug.Assert(gazeManagerPointingData != null); pointer = gazeManagerPointingData; } else { pointer = new PointerData(pointingSource); } pointers.Add(pointer); }
public void RegisterPointer(IPointingSource pointingSource) { Debug.Assert(pointingSource != null); Debug.Assert(TryGetPointerIndex(pointingSource) == null); PointerData pointer; if (pointingSource is GazeManager) { if (gazeManagerPointingData == null) { gazeManagerPointingData = new PointerData(pointingSource); } pointer = gazeManagerPointingData; } else { pointer = new PointerData(pointingSource); } pointers.Add(pointer); }
public void UnregisterPointer(IPointingSource pointingSource) { Debug.Assert(pointingSource != null); int?iPointer = TryGetPointerIndex(pointingSource); Debug.Assert(iPointer != null); PointerData pointer = pointers[iPointer.Value]; pointers.RemoveAt(iPointer.Value); // Raise focus events if needed: if (pointer.End.Object != null) { GameObject unfocusedObject = pointer.End.Object; bool objectIsStillFocusedByOtherPointer = false; for (int iOther = 0; iOther < pointers.Count; iOther++) { if (pointers[iOther].End.Object == unfocusedObject) { objectIsStillFocusedByOtherPointer = true; break; } } if (!objectIsStillFocusedByOtherPointer) { RaiseFocusExitedEvents(unfocusedObject); } RaisePointerSpecificFocusChangedEvents(pointer.PointingSource, unfocusedObject, null); } }
public LanCanvas(InkCanvas canvas, IdGenerator generator, string owner, PermissionsData permissions) { eraserShape = new EllipseStylusShape(2, 2); PointerData = new SharedWindows.PointerData(); PointerData.Attributes = new DrawingAttributes(); PointerData.Attributes.Color = Colors.Red; PointerData.StayTime = 1500; PointerData.FadeTime = 500; OwnerName = owner; this.generator = generator; this.canvas = canvas; this.Permissions = permissions; DefaultDrawingAttributes = new DrawingAttributes(); cursorLibrary = new CursorLibrary(); modeChanger = new ModeChanger(); UpdatePermissions(); canvas.Dispatcher.Invoke(new Action(canvasInit)); drawer = new SignedStrokeDrawer(canvas.Strokes, generator, OwnerName); eraser = new SignedStrokeEraser(canvas.Strokes, permissions, OwnerName); cutter = new SignedStrokeCutter(canvas.Strokes); pointerDrawer = new SignedPointerStrokeDrawer(canvas.Strokes, OwnerName, generator, canvas.Dispatcher); ManualHandler = new ManualHandle(canvas); CanvasHandle = new CanvasEventsHandle(this, drawer, eraser, pointerDrawer); }
private void RegisterPointers(IMixedRealityInputSource inputSource) { // If our input source does not have any pointers, then skip. if (inputSource.Pointers == null) { return; } IMixedRealityPointerMediator mediator = null; if (InputSystem?.InputSystemProfile.PointerProfile.PointerMediator.Type != null) { mediator = Activator.CreateInstance(InputSystem.InputSystemProfile.PointerProfile.PointerMediator.Type) as IMixedRealityPointerMediator; } if (mediator != null) { mediator.RegisterPointers(inputSource.Pointers); if (!pointerMediators.ContainsKey(inputSource.SourceId)) { pointerMediators.Add(inputSource.SourceId, mediator); } } for (int i = 0; i < inputSource.Pointers.Length; i++) { RegisterPointer(inputSource.Pointers[i]); // Special Registration for Gaze if (inputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId && gazeProviderPointingData == null) { gazeProviderPointingData = new PointerData(inputSource.Pointers[i]); } } }
// --- Private Function ------------------------------------------------------------------------------------------------------------------------------------------- // // 缓存指针事件 private void CachePointerEvent(PointerEventType type, PointerEventData data) { PointerData pointerData = new PointerData() { InputType = data.pointerId < 0 ? PointerInputType.Mouse : PointerInputType.Touch, EventType = type, PointerID = data.pointerId, X = (int)data.position.x, Y = (int)data.position.y }; PointerEventCache.Add(pointerData); if (pointerData.EventType == PointerEventType.Enter) { // 添加 Cover 状态 CoverStatus.Add(new PointerCoverStatusForUI() { PointerID = pointerData.InputType == PointerInputType.Mouse ? -1 : pointerData.PointerID, PrevX = pointerData.X, PrevY = pointerData.Y }); } else if (pointerData.EventType == PointerEventType.Exit) { // 移除 Cover 状态 int coverCount = CoverStatus.Count; for (int i = coverCount - 1; i >= 0; i--) { if (CoverStatus[i].PointerID == pointerData.PointerID) { CoverStatus.RemoveAt(i); break; } } } }
public override void Update(float interval) { _viewModel.Show = false; ResetCastLogic(); if (_buffTipLogic.HasTipState()) { ShowBuffTip(); } if (_playerStateTipLogic.HasTipState()) { ShowStateTip(); } else if (CheckCastData()) { ShowCastTip(); } _castData = null; _doCastAction = null; _currentCastLogic = null; }
static _PointerState _ensureStateForPointer(PointerData datum, Offset position) { return(_pointers.putIfAbsent( datum.device, () => new _PointerState(position))); }
private void SetCastData(KeyData data) { _castData = data as PointerData; }
private void UpdatePointer(PointerData pointer) { // Call the pointer's OnPreRaycast function // This will give it a chance to prepare itself for raycasts // eg, by building its Rays array pointer.Pointer.OnPreRaycast(); // If pointer interaction isn't enabled, clear its result object and return if (!pointer.Pointer.IsInteractionEnabled) { // Don't clear the previous focused object since we still want to trigger FocusExit events pointer.ResetFocusedObjects(false); } else { // If the pointer is locked, keep the focused object the same. // This will ensure that we execute events on those objects // even if the pointer isn't pointing at them. if (pointer.Pointer.IsFocusLocked && pointer.Pointer.IsTargetPositionLockedOnFocusLock) { pointer.UpdateFocusLockedHit(); } else { // Otherwise, continue var prioritizedLayerMasks = (pointer.Pointer.PrioritizedLayerMasksOverride ?? FocusLayerMasks); physicsHitResult.Clear(); // Perform raycast to determine focused object RaycastPhysics(pointer.Pointer, prioritizedLayerMasks, physicsHitResult); var currentHitResult = physicsHitResult; // If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions if (EventSystem.current != null) { graphicsHitResult.Clear(); // NOTE: We need to do this AFTER RaycastPhysics so we use the current hit point to perform the correct 2D UI Raycast. RaycastGraphics(pointer.Pointer, pointer.GraphicEventData, prioritizedLayerMasks, graphicsHitResult); currentHitResult = GetPrioritizedHitResult(currentHitResult, graphicsHitResult, prioritizedLayerMasks); } // Make sure to keep focus on the previous object if focus is locked (no target position lock here). if (pointer.Pointer.IsFocusLocked && pointer.Pointer.Result?.CurrentPointerTarget != null) { currentHitResult.HitObject = pointer.Pointer.Result.CurrentPointerTarget; } // Apply the hit result only now so changes in the current target are detected only once per frame. pointer.UpdateHit(currentHitResult); // Set the pointer's result last pointer.Pointer.Result = pointer; } } // Call the pointer's OnPostRaycast function // This will give it a chance to respond to raycast results // eg by updating its appearance pointer.Pointer.OnPostRaycast(); }