private bool IsMousePointerActive() { IList <GcPointer> pointers = GcPointer.GetInstances(); //return true; return(pointers.Any(p => p is GcMouse)); }
/// <summary> /// 当命中物体后触发,可重写 /// 默认进入可交互物体后,或可命中的UI笔震动一下 /// </summary> /// <param name="pointer"></param> /// <param name="obj"></param> protected virtual void OnObjectEnter(GcPointer pointer, GameObject obj) { //检查是否可拖拽物体震动 if (obj.GetComponent <CustomInteractable>() != null) { GCSeries.FCore.PenShake(); return; } //检查UI震动 Selectable uiSelectable = obj.GetComponent <Selectable>(); if (uiSelectable != null) { if (uiSelectable.IsInteractable()) { GCSeries.FCore.PenShake(); } return; } else { //因为toggle的组件是在父级物体,所以往上找一层 uiSelectable = obj.transform.parent.GetComponent <Toggle>(); if (uiSelectable != null) { if (uiSelectable.IsInteractable()) { GCSeries.FCore.PenShake(); } return; } } }
//////////////////////////////////////////////////////////////////////// // Protected Methods //////////////////////////////////////////////////////////////////////// protected void ProcessPointers() { IList <GcPointer> pointers = GcPointer.GetInstances(); for (int i = 0; i < pointers.Count; ++i) { this.ProcessPointerEvent(pointers[i]); } }
/// <summary> /// Get the interactable's specified drag plane. /// </summary> /// <param name="pointer"></param> /// <returns></returns> public virtual Plane GetDragPlane(GcPointer pointer) { if (pointer.DefaultCustomDragPlane != null) { return(pointer.DefaultCustomDragPlane(pointer)); } return(default(Plane)); }
//////////////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////////////// /// <summary> /// Overrides the pointer's current drag policy for this interactable. /// </summary> /// /// <param name="pointer"> /// A reference to the pointer currently interacting with this /// interactable. /// </param> /// /// <returns> /// The interactable's drag policy. /// </returns> public virtual GcPointer.DragPolicy GetDragPolicy(GcPointer pointer) { if (this.GetComponent <RectTransform>() != null) { return(pointer.UIDragPolicy); } else { return(pointer.ObjectDragPolicy); } }
public override void Process(GcPointer pointer, Vector3 worldScale) { base.Process(pointer, worldScale); if (pointer.IsVisible) { if (_lineRender == null) { InitLineRender(); } else { _lineRender.enabled = true; this._lineRender.gameObject.SetActive(pointer.IsVisible); // 跟随ViewerScale缩放线宽 _lineRender.startWidth = lineStartWidth * FCore.ViewerScale; _lineRender.endWidth = lineEndWidth * FCore.ViewerScale; Vector3 hitPosition = pointer.HitInfo.worldPosition; this._endPoint = hitPosition; Vector3 p0 = pointer.transform.position; Vector3 p2 = this._endPoint; _lineRender.SetPosition(0, pointer.transform.position); Vector3 project = Vector3.Project(p2 - p0, pointer.transform.forward); _lineRender.SetPosition(1, p0 + project); // 跟随ViewerScale缩放笔头 trackHandle.transform.localScale = Vector3.one * mrSystem.ViewerScale; trackHandle.gameObject.SetActive(true); trackHandle.transform.position = hitPosition; trackHandle.transform.forward = pointer.transform.forward; } } else { if (_lineRender != null) { _lineRender.enabled = false; } trackHandle.gameObject.SetActive(false); } }
void OnGUI() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append($"RuntimeArgs.MainIs3DShow = {Global.Instance.Data.RuntimeArgs.MainIs3DShow} \n"); stringBuilder.Append($"FCore.glassPosition = {FCore.glassPosition.ToString("F3")} \n"); stringBuilder.Append($"------------------------ \n"); foreach (var pointer in GcPointer.GetInstances()) { stringBuilder.Append($"{pointer.name}\n"); stringBuilder.Append($"IsVisible : {pointer.IsVisible} \n"); stringBuilder.Append($"Position : {pointer.transform.position.ToString("F3")} \n"); stringBuilder.Append($"Rotation : {pointer.transform.rotation.ToString("F3")} \n"); stringBuilder.Append($"GetButton(0):{pointer.GetButton(0)} GetButton(1):{pointer.GetButton(1)} GetButton(2):{pointer.GetButton(2)} \n"); stringBuilder.Append($"------------------------ \n"); } GUILayout.Label(stringBuilder.ToString(), _layoutOption); }
protected GcEventData GetEventData(GcPointer pointer, int buttonId) { int id = pointer.Id + buttonId; RaycastResult hitInfo = pointer.HitInfo; // Attempt to retrieve the pointer event data. If it doesn't exist, // create it. GcEventData eventData = null; if (!this._eventDataCache.TryGetValue(id, out eventData)) { eventData = new GcEventData(this.eventSystem); eventData.position = hitInfo.screenPosition; this._eventDataCache.Add(id, eventData); } // Reset the pointer event data before populating it with latest // information from the pointer. eventData.Reset(); eventData.Pointer = pointer; eventData.ButtonId = buttonId; eventData.IsUIObject = (hitInfo.gameObject?.GetComponent <RectTransform>() != null); eventData.Delta3D = hitInfo.worldPosition - eventData.pointerCurrentRaycast.worldPosition; eventData.button = pointer.GetButtonMapping(buttonId); eventData.delta = hitInfo.screenPosition - eventData.position; eventData.position = hitInfo.screenPosition; eventData.scrollDelta = pointer.ScrollDelta; eventData.pointerCurrentRaycast = hitInfo; eventData.TouchCount = pointer.TouchCount; return(eventData); }
protected void ProcessPointerEvent(GcPointer pointer) { for (int i = 0; i < pointer.ButtonCount; ++i) { GcEventData eventData = this.GetEventData(pointer, i); if (!pointer.IsVisible) { while (eventData.hovered.Count != 0) { ExecuteEvents.Execute(eventData.hovered[0], eventData, ExecuteEvents.pointerExitHandler); eventData.hovered.Remove(eventData.hovered[0]); } return; } // Process button press/release events. if (pointer.GetButtonDown(i)) { this.ProcessButtonPress(eventData); } if (pointer.GetButtonUp(i)) { this.ProcessButtonRelease(eventData); } // Process move/scroll events only for the primary button. if (eventData.button == PointerEventData.InputButton.Left) { this.ProcessMove(eventData); this.ProcessScroll(eventData); } // Process drag events. this.ProcessDrag(eventData); } }
public virtual void Process(GcPointer pointer, Vector3 worldScale) { }