Пример #1
0
        private void FindAndUpdateBestSC()
        {
            SnapCollider lastBest = bestCandidateSnapCollider;

            bestCandidateSnapCollider = null;
            float bestDist = -1f;

            foreach (SnapCollider sc in curSnapCollidersInContact)
            {
                // Compare SnapCollider to this Codeblock's position
                float compareToDist = (transform.position - sc.transform.position).sqrMagnitude; // faster than Vector3.Distance bc no sqrt
                if (bestCandidateSnapCollider == null || compareToDist < bestDist)
                {
                    bestCandidateSnapCollider = sc;
                    bestDist = compareToDist;
                }
            }
            if (lastBest != bestCandidateSnapCollider)
            {
                bestCandidateSnapCollider.MyMeshOutline.enabled = true;
                if (lastBest != null)
                {
                    lastBest.MyMeshOutline.enabled = false;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Adds SnapCollder in contact to set and updates best snap collider based upon argument.
 /// See `UpdateBestSnapCollider(SnapCollider sc)` for more details.
 /// </summary>
 /// <param name="sc">Snap collider in contact. Can be null.</param>
 public void AddSnapColliderInContact(SnapCollider sc)
 {
     if (sc != null)
     {
         curSnapCollidersInContact.Add(sc);
     }
 }
Пример #3
0
 public void RemoveAsCurSnapColliderInContact(SnapCollider sc)
 {
     GetCurSnapCollidersInContact().Remove(sc);
     if (sc == bestCandidateSnapCollider)
     {
         AddSnapColliderInContact(null);
     }
 }
Пример #4
0
 private void DisableBestCandidateCollider()
 {
     if (bestCandidateSnapCollider != null)
     {
         bestCandidateSnapCollider.MyMeshOutline.enabled = false;
         bestCandidateSnapCollider = null;
     }
 }
Пример #5
0
 /// <summary>
 /// Removes SnapCollider from curSnapCollidersInContact set
 /// </summary>
 /// <param name="sc">SnapCollider to be removed. Cannot be null.</param>
 public void RemoveAsCurSnapColliderInContact(SnapCollider sc)
 {
     Assert.IsTrue(sc != null);
     curSnapCollidersInContact.Remove(sc);
     if (sc == bestCandidateSnapCollider)
     {
         AddSnapColliderInContact(null);
     }
 }
        public void Recenter()
        {
            Transform parentTransform = GetMyCodeBlock().transform.parent;

            if (parentTransform == CodeBlockManager.instance.transform)
            {
                return;
            }
            Vector3      centerPos = myCodeBlock.GetCodeBlockObjectMesh().GetCenterPosition();
            SnapCollider sc        = parentTransform.GetChild(0).GetComponent <SnapCollider>();

            centerPos.x = centerPos.x / parentTransform.localScale.x; // this is on object mesh....
            myCodeBlock.transform.SnapToParent(parentTransform, sc.SnapPosition - centerPos);
        }
Пример #7
0
 // TODO: this should be register/deregister
 private List <SnapCollider> GetSnapColliders()
 {
     if (snapColliders == null)
     {
         snapColliders = new List <SnapCollider>();
         snapColliders.Resize(GetMyCodeBlock().GetMyInternalIArgument().GetNumArguments());
         foreach (Transform go in transform)
         {
             SnapCollider sc = go.GetComponentInChildren <SnapCollider>(true);
             if (sc != null)
             {
                 snapColliders[sc.myArgumentPosition] = sc;
             }
         }
     }
     return(snapColliders);
 }
Пример #8
0
 public void AddSnapColliderInContact(SnapCollider sc)
 {
     if (bestCandidateSnapCollider != null)
     {
         bestCandidateSnapCollider.GetMeshOutline().enabled = false;
     }
     bestCandidateSnapCollider = sc;
     if (bestCandidateSnapCollider != null)
     {
         bestCandidateSnapCollider.GetMeshOutline().enabled = true;
         GetCurSnapCollidersInContact().Add(bestCandidateSnapCollider);
     }
     else if (!GetCurSnapCollidersInContact().Empty())
     {
         bestCandidateSnapCollider = curSnapCollidersInContact.ElementAt(0);
         bestCandidateSnapCollider.GetMeshOutline().enabled = true;
     }
 }
Пример #9
0
        public static CodeBlock GetDestructableCodeBlockObject(this GameObject go)
        {
            CodeBlock           result = null;
            CodeBlockObjectMesh cbom   = go.GetComponentInParent <CodeBlockObjectMesh>();

            if (cbom != null)
            {
                result = cbom.GetMyCodeBlock();
            }
            SnapCollider sc = go.GetComponent <SnapCollider>();

            if (sc != null)
            {
                result = sc.MyCodeBlock;
            }
            // StartCodeBlock is indestructible
            if (result == StartCodeBlock.instance)
            {
                result = null;
            }
            return(result);
        }
Пример #10
0
        IEnumerator ShootRayFromHandThroughSnapColliders(IMixedRealityPointer pointer)
        {
            RaycastHit   rayHitData;
            SnapCollider lastSCLaserContact = null;
            LayerMask    lm = 1 << LayerMask.NameToLayer(LayerMaskConstants.SNAPCOLLIDER);

            while (CurrentlyDraggingCodeBlockSnap == this && pointer != null)
            {
                Vector3 rayOrigin = pointer.Position;
                Vector3 direction = transform.position - rayOrigin;
                if (Physics.Raycast(rayOrigin, direction, out rayHitData, 10, lm))
                {
                    SnapCollider sc = rayHitData.collider.transform.GetComponent <SnapCollider>();
                    if (sc != null)
                    {
                        if (lastSCLaserContact != null)
                        {
                            RemoveAsCurSnapColliderInContact(lastSCLaserContact);
                            lastSCLaserContact = null;
                        }
                        lastSCLaserContact = sc;
                        if (!curSnapCollidersInContact.Contains(lastSCLaserContact))
                        {
                            AddSnapColliderInContact(lastSCLaserContact);
                        }
                    }
                }
                else
                {
                    if (lastSCLaserContact != null)
                    {
                        RemoveAsCurSnapColliderInContact(lastSCLaserContact);
                        lastSCLaserContact = null;
                    }
                }
                yield return(null);
            }
        }
Пример #11
0
        // Gameobject Extensions
        public static string TryGetNiceNameOfObjectForLogging(this GameObject go)
        {
            CodeBlockObjectMesh cbom = go.GetComponentInParent <CodeBlockObjectMesh>();

            if (cbom != null)
            {
                return(cbom.GetMyCodeBlock().name);
            }
            SnapCollider sc = go.GetComponent <SnapCollider>();

            if (sc != null)
            {
                return(sc.MyCodeBlock.name);
            }
            PressableButtonHoloLens2 pbh2 = go.GetComponentInParent <PressableButtonHoloLens2>();

            if (pbh2 != null)
            {
                return(pbh2.name);
            }

            return(go.name);
        }
Пример #12
0
 /// <summary>
 /// Adds snapcollider to `argToSnapCollider` dictionary.
 /// </summary>
 /// <param name="snapColDescIn">String key for type of snapcollider argument</param>
 /// <param name="snapCollider">Pointer to `SnapCollider`</param>
 internal void RegisterSnapCollider(string snapColDescIn, SnapCollider snapCollider)
 {
     GetArgToSnapColliderDict()[snapColDescIn] = snapCollider;
 }
 /// <summary>
 /// Registers the `SnapCollider` of this `CodeBlock` to be enabled/disabled when `MyCodeBlock` is grabbed.
 /// </summary>
 /// <param name="snapCollider"></param>
 public void RegisterSnapCollider(KeyValuePair <Type, int> scKeyType, SnapCollider snapCollider)
 {
     SnapColliderSet[scKeyType] = snapCollider;
 }
Пример #14
0
 public void DeregisterSnapCollider(SnapCollider sIn)
 {
     GetAllSnapColliders().Remove(sIn);
 }
Пример #15
0
 public void RegisterSnapCollider(SnapCollider sIn)
 {
     GetAllSnapColliders().Add(sIn);
 }