Beispiel #1
0
        private bool DetermineIfBox(RaycastHit hitInfo, out SyllableBox box, out bool boxEmpty)
        {
            GameObject obj = hitInfo.collider.gameObject;
            var        boxPointerScript = obj.GetComponentInParent <SyllableBoxPointer>();

            if (obj != null &&
                boxPointerScript != null)
            {
                SyllableBox collidedBox = boxPointerScript.SyllableBox;
                if (collidedBox != null)
                {
                    box = collidedBox;
                    if (collidedBox.Empty)
                    {
                        boxEmpty = true;
                    }
                    else
                    {
                        boxEmpty = false;
                    }

                    return(true);
                }
            }

            box      = null;
            boxEmpty = false;
            return(false);
        }
Beispiel #2
0
        public void Hold(Vector3 currentFingerPos)
        {
            if (trackedPlane_m != null &&
                currentFingerPos != null)
            {
                //float distance = (trackedPlane_m.transform.position - Camera.main.transform.position).magnitude;
                float   distance = trackedDistance_m;
                Vector3 dir      = (currentFingerPos - Camera.main.transform.position).normalized;
                Vector3 newPos   = currentFingerPos + dir * distance;
                trackedPlane_m.transform.position = newPos;
                trackedPlane_m.transform.forward  = -Camera.main.transform.forward;

                RaycastHit hitInfo;
                if (GetHoldHitInfo(trackedPlane_m, currentFingerPos, out hitInfo))
                {
                    SyllableBox box;
                    bool        boxEmpty;
                    if (DetermineIfBox(hitInfo, out box, out boxEmpty))
                    {
                        // box is valid box
                        BoxHoveredOver = box;
                        CanDrop        = boxEmpty;

                        return;
                    }
                }
            }

            // Only hit this logic if you fail to find something you can drop into
            BoxHoveredOver = null;
            CanDrop        = false;
        }
        public List <SyllableBox> GenerateBoxes(Word word)
        {
            List <SyllableBox> boxes = new List <SyllableBox>();

            // Grab the Vuforia objects we're going to be associating with the boxes
            List <KeyValuePair <int, GameObject> > vuforiaParentPairs = GrabVuforiaObjects(word.SyllableCount);

            //List<GameObject> vuforiaParents = GrabVuforiaObjects(word.SyllableCount);

            if (vuforiaParentPairs == null ||
                vuforiaParentPairs.Count < Word.SyllableCount)
            {
                Debug.LogError("SyllableBoxSet: Insufficient Vuforia planar images associated in project to generate necessary boxes. Please make the Vuforia target images and set them in the scene and ensure that there are a necessary quantity to instantiate these boxes.");
            }
            else
            {
                // Generate the box script, which generates the box object and attaches the necessary scripts
                for (int i = 0; i < word.SyllableCount; i++)
                {
                    SyllableBox box = new SyllableBox(word[i], vuforiaParentPairs[i].Value);
                    boxes.Add(box);
                    Debug.Log("SyllableBoxSet: Generating box for Vuforia ID pattern " + vuforiaParentPairs[i].Key);
                }
            }

            return(boxes);
        }
        public bool IsRightOf(SyllableBox other)
        {
            Vector3 otherRight = other.transform.right;
            Vector3 pos        = transform.position;
            Vector3 vec        = pos - other.transform.position;

            return(Vector3.Dot(otherRight, vec) < 0);
        }
        public GameObject CoupleTo(SyllableBox box)
        {
            // Set the transform to be correct by applying it as a child of the box
            if (plane_m != null &&
                box != null)
            {
                plane_m.transform.parent = box.transform;
            }

            return(box.Box);
        }
Beispiel #6
0
        public GameObject Pull(SyllableBox box)
        {
            // Pull the syllable plane from the box
            if (box != null)
            {
                GameObject planeGO     = box.Box.GetComponentInChildren <SyllablePlane>().gameObject;
                var        planeScript = planeGO.GetComponent <SyllablePlane>();
                planeScript.Uncouple();
                box.PullSyllable();

                return(planeGO);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        public void Push(GameObject planeGO, SyllableBox box)
        {
            if (planeGO != null)
            {
                var planeScript = planeGO.GetComponent <SyllablePlane>();
                if (box != null &&
                    box.Syllable == null)
                {
                    planeScript.CoupleTo(box);
                    Syllable syllable = planeScript.Syllable;
                    box.PushSyllable(syllable);

                    // Set the plane's relative position
                    planeGO.transform.localPosition    = Vector3.zero;
                    planeGO.transform.localEulerAngles = Vector3.zero;
                }
            }
        }
 public void SetBox(SyllableBox box)
 {
     box_m = box;
 }