Example #1
0
 public bool randomRotCur()
 {
     if (curr != null)
     {
         int           rotint;
         System.Random rnd = new System.Random();
         if (curr.type == 3)
         {
             rotint = rnd.Next(1, 5);
         }
         else if (curr.type == 5)
         {
             rotint = rnd.Next(1, 3) + 2;
         }
         else
         {
             rotint = rnd.Next(1, 7);
         }
         Vector3 rotaxi = Vector3.zero;
         if (rotint == 1)
         {
             rotaxi = Vector3.left;
         }
         if (rotint == 2)
         {
             rotaxi = Vector3.right;
         }
         if (rotint == 3)
         {
             rotaxi = Vector3.forward;
         }
         if (rotint == 4)
         {
             rotaxi = Vector3.back;
         }
         if (rotint == 5)
         {
             rotaxi = Vector3.up;
         }
         if (rotint == 6)
         {
             rotaxi = Vector3.down;
         }
         return(curr.rotate(rotaxi));
     }
     return(false);
 }
Example #2
0
        public void Update()
        {
            switchtime += Time.deltaTime;
            displayarmwidget();
            updatebomb();
            updatecube();
            objtime   += Time.deltaTime;
            leaporigin = leapspace.transform.position;
            Matrix4x4 wtc         = camera.worldToCameraMatrix;
            Matrix4x4 ctw         = camera.cameraToWorldMatrix;
            Vector3   leftoffset  = vec4To3(ctw * vec3To4(Vector3.left * 0.1f, 0));
            Vector3   rightoffset = vec4To3(ctw * vec3To4(Vector3.right * 0.1f, 0));
            Vector3   upoffset    = vec4To3(ctw * vec3To4(Vector3.up * 0.1f, 0));
            Vector3   downoffset  = vec4To3(ctw * vec3To4(Vector3.down * 0.1f, 0));

            if (objtime > 1)
            {
                if (righthand != null)
                {
                    Vector3 normal = Vector3.Normalize(leapVectorToWorld(righthand.PalmNormal));
                    Vector3 dir    = leapToWorld(righthand.PalmPosition) - leaporigin;
                    if (translate)
                    {         //translate
                        if (decideDirection(normal) != Vector3.zero)
                        {     //valid pos
                            if (detectColli(leftoffset, rightoffset, upoffset, downoffset, dir))
                            { // has target
                                leavetime = 0;
                                GameObject target = info.collider.gameObject;
                                if (prepos == Vector3.zero)
                                {//first hit
                                    prepos = leapToWorld(righthand.PalmPosition);
                                }
                                else
                                {
                                    if ((prepos - leapToWorld(righthand.PalmPosition)).magnitude > 0.06f)
                                    {//move obj
                                        int    id = Int32.Parse(target.transform.parent.gameObject.name);
                                        puzzle p  = gameController.GetPuzzle(id);
                                        if (p.startMove(decideDirection(normal)))
                                        {
                                            p.highlight();
                                            objtime = 0;
                                        }
                                        prepos = Vector3.zero;
                                    }
                                }
                            }
                            else
                            { //reset pre
                                leavetime += Time.deltaTime;
                                if (leavetime > 0.5f)
                                {
                                    prepos = Vector3.zero;
                                }
                            }
                        }
                    }
                    else
                    {     //rotation
                        if (detectColli(leftoffset, rightoffset, upoffset, downoffset, dir))
                        { // has target
                            GameObject target   = info.collider.gameObject;
                            GameObject parent   = target.transform.parent.gameObject;
                            int        id       = Int32.Parse(target.transform.parent.gameObject.name);
                            puzzle     p        = gameController.GetPuzzle(id);
                            Vector3    hitpoint = info.point;
                            if (righthand.GrabStrength > 0.8f)
                            {
                                p.highlight();
                                Vector3 ax = Vector3.Cross(leapVectorToWorld(righthand.Direction), leapVectorToWorld(righthand.PalmNormal));
                                if (p.rotate(findclosestunit(ax)))
                                {
                                    objtime = 0;
                                }
                            }
                        }
                    }
                }
            }
            movetime += Time.deltaTime;
            if (movetime > 1)
            {
                if (lefthand != null)
                {
                    if (bomb == null && cub == null)
                    {
                        if (isFist(lefthand))
                        {
                            if (leftprepos == Vector3.zero)
                            {
                                leftprepos = leapToWorld(lefthand.PalmPosition);
                            }
                            else
                            {
                                if ((leftprepos - leapToWorld(lefthand.PalmPosition)).magnitude > 0.12f)
                                {
                                    Vector3 dir = findclosestunit(leftprepos - leapToWorld(lefthand.PalmPosition));
                                    gamer.moveplayer(dir);
                                    leftprepos = Vector3.zero;
                                    movetime   = 0;
                                }
                            }
                        }
                        else
                        {
                            leftprepos = Vector3.zero;
                        }
                    }
                    else if (bomb != null)
                    {
                        if (!isFist(lefthand) && !release)
                        {
                            releasetime += Time.deltaTime;
                            if (prebombpos == Vector3.zero)
                            {
                                prebombpos = bomb.transform.position;
                            }
                            if (releasetime > 0.3f)
                            {
                                release = true;
                                bombdir = 0.2f * Vector3.Normalize(bomb.transform.position - prebombpos);
                            }
                        }
                        else
                        {
                            releasetime = 0;
                            prebombpos  = Vector3.zero;
                        }
                    }
                    else
                    {
                        if (!isFist(lefthand))
                        {
                            cubereleasetime += Time.deltaTime;
                            if (cubereleasetime > 1)
                            {
                                if (gameController.ctr.addCube(leaporigin + leapspace.transform.forward))
                                {
                                    cubereleasetime = 0;
                                    GameObject.Destroy(cub);
                                    cub = null;
                                }
                            }
                        }
                    }
                }
            }
        }