/// <summary> /// <para>Attaches the element to the specified host. To overide Attach, please override <see cref="OnAttach(IRenderHost)"/> function.</para> /// <para>To set different render technique instead of using technique from host, override <see cref="OnCreateRenderTechnique"/></para> /// <para>Attach Flow: <see cref="OnCreateRenderTechnique(IRenderHost)"/> -> Set RenderHost -> Get Effect -> <see cref="OnAttach(IRenderHost)"/> -> <see cref="InvalidateSceneGraph"/></para> /// </summary> /// <param name="host">The host.</param> public void Attach(IRenderHost host) { if (IsAttached || host == null || host.EffectsManager == null) { return; } renderHost = host; this.renderTechnique = OnSetRenderTechnique != null?OnSetRenderTechnique(host) : OnCreateRenderTechnique(host); if (renderTechnique == null) { var techniqueName = RenderHost.EffectsManager.RenderTechniques.FirstOrDefault(); if (string.IsNullOrEmpty(techniqueName)) { return; } renderTechnique = RenderHost.EffectsManager[techniqueName]; } IsAttached = OnAttach(host); if (IsAttached) { Attached(); OnAttached?.Invoke(this, EventArgs.Empty); } InvalidateSceneGraph(); }
public void Attach(List <DeviceAlignmentAnchor> anchors) { if (m_Filler != null) { m_WasFillerEnabled = m_Filler.enabled; m_Filler.enabled = false; } if (m_HideInVr) { m_WasActive = gameObject.activeSelf; gameObject.SetActive(false); return; } var anchor = anchors.Find(x => x.device == m_Device && x.alignment == m_Alignment); if (anchor == null) { Debug.LogError($"[{nameof(VRAnchor)}] anchor for {m_Device} device with {m_Alignment} alignment not found!"); return; } if (m_RectTransform == null) { m_RectTransform = GetComponent <RectTransform>(); } m_InitialParent = m_RectTransform.parent; m_SiblingIndex = m_RectTransform.GetSiblingIndex(); m_AnchorMin = m_RectTransform.anchorMin; m_AnchorMax = m_RectTransform.anchorMax; m_Pivot = m_RectTransform.pivot; m_Position = m_RectTransform.localPosition; m_Rotation = m_RectTransform.localEulerAngles; m_Scale = m_RectTransform.localScale; m_RectTransform.SetParent(anchor.transform); // only change if anchors are equal and therefore not stretched to fit if (m_RectTransform.anchorMin == m_RectTransform.anchorMax) { m_RectTransform.anchorMin = m_RectTransform.anchorMax = k_AnchorMinMaxPivots[m_Alignment]; } m_RectTransform.pivot = k_AnchorMinMaxPivots[m_Alignment]; m_RectTransform.localPosition = m_PositionOffset; m_RectTransform.localEulerAngles = Vector3.zero; m_RectTransform.localScale = Vector3.one; OnAttached?.Invoke(); }
/// <summary> /// <para>Attaches the element to the specified host. To overide Attach, please override <see cref="OnAttach(IRenderHost)"/> function.</para> /// <para>Attach Flow: Set RenderHost -> Get Effect -> /// <see cref="OnAttach(IRenderHost)"/> -> <see cref="OnAttach"/> -> <see cref="InvalidateRender"/></para> /// </summary> /// <param name="host">The host.</param> public void Attach(IRenderHost host) { if (IsAttached || host == null) { return; } RenderHost = host; IsAttached = OnAttach(host); if (IsAttached) { OnAttached?.Invoke(this, EventArgs.Empty); } InvalidateAll(); }
public void Attach(HandVR handVR, bool iterateAttachmentPoint = false) { //Debug.Log("Attach: " + this, gameObject); // TO DO: Test if not necessary I did it because maybe detach events are important. But attach should let things as they should be. if (Attached) { //True to avoid possible attach to Slot. Imagine you get from one hand to the other but the from hand is hovering a slot. then the detach will attach grabbable to the slot and then attach to the new hand making a strange effect Detach(true); } else if (Stored) { TryUnstore(OwnerSlot); } if (iterateAttachmentPoint) { currentAttachmentPointIndex++; } if (currentAttachmentPointIndex == attachmentPoints.Count) { currentAttachmentPointIndex = 0; } transform.DOKill(); transform.parent = handVR.transform; OwnerHandVR = handVR; //Important to do this and next line before real physic attach (position and rotation) to be able to detach from it if other hand steal it on the fly to the hand handVR.AttachedGrabbable = this; DisableColliders(); //Disable collider to avoid not desired collisions on attach Vector3 attachPositionOffset = Vector3.zero; Quaternion attachRotationOffset = Quaternion.identity; GetLocalAttachmentPositionAndRotation(handVR.transform, out attachPositionOffset, out attachRotationOffset, handVR.AttachmentPointName.name, iterateAttachmentPoint); float attachTime = DataVR.Instance.grabbable.attachTime; transform.DOLocalMove(-attachPositionOffset, attachTime).SetEase(Ease.OutSine); transform.DOLocalRotate(-attachRotationOffset.eulerAngles, attachTime).SetEase(Ease.OutSine).OnComplete ( () => { PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders); //Ignore Collisions between this and CharacterVR EnableColliders(); //Enable collider (disabled above, before tween attach) WARNING. it is detected by ontriggerenter of physicsproximityAdjust //TrackedPoseDriver approach { ////Set final position ////------------------------------------------------- //if (attachmentPoints.Count == 0 || (handVR.AttachmentPointName.name == "" && iterateAttachmentPoint == false)) //{ // transform.localPosition = Vector3.zero; // transform.localRotation = Quaternion.identity; //} //else //{ // transform.localPosition = -attachPositionOffset; // transform.localRotation = Quaternion.Inverse(attachRotationOffset); //} ////------------------------------------------------- } //SLOT: as it could be in a slot make it kinematic again Rigidbody.interpolation = RigidbodyInterpolation.None; Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative; //TrackedPoseDriver approach { //Original approach //Rigidbody.isKinematic = true; AddTrackedPoseDriver(handVR, attachPositionOffset, attachRotationOffset); } Rigidbody.useGravity = false; state = BelongState.Attached; //Events OnAttached?.Invoke(handVR); #if UNITY_EDITOR Debug.Log("Attach Grabbable: " + this + " to HandVR: " + handVR, gameObject); #endif } ); }