Exemplo n.º 1
0
        public void CheckScene()
        {
            int[] arr_id = new int[4];
            arr_id[0] = (_component.topSide > 0) ? this.GetID() - StartPuzzle.sizeX : 0;
            arr_id[1] = (_component.bottomSide > 0) ? this.GetID() + StartPuzzle.sizeX : 0;
            arr_id[2] = (_component.leftSide > 0) ? this.GetID() - 1 : 0;
            arr_id[3] = (_component.rightSide > 0) ? this.GetID() + 1 : 0;


            for (int i = 0; i < 4; i++)
            {
                if (arr_id[i] == 0)
                {
                    continue;                                // go to next iteration
                }
                PuzzleObject _oside = new PuzzleObject(arr_id[i]);

                if (!this.CheckDistance(_oside, i))
                {
                    this.AttachToCanvas();
                    //Debug.Log(i + " false");
                    CheckDistanceForChild(i);
                    continue;                     // go to next iteration
                }

                //Debug.Log(i + " true " + arr_id[i]);

                this.Connect(_oside, i);
                this.SetParentLocal(_oside.GetParent() > 0 ? _oside.GetParent() : arr_id[i]);

                PuzzleObject par = new PuzzleObject(this.GetParent());
                _component.rt.parent = par._component.rt;
                AttachToParent(par);

                break;                 // left from cycle
            }
        }
Exemplo n.º 2
0
        private void test_check(int side, PuzzleObject one, PuzzleObject two /*, PuzzleObject tp*/)
        {
            Vector3 sub = one._component.rt.anchoredPosition3D;

            PuzzleObject two_par = null;

            Vector3 master;
            Vector3 master_par = new Vector3(0, 0, 0);

            master = two._component.rt.anchoredPosition3D;

            // if parent id > 0 then used parent of master piece to calculate global position
            if (two.GetParent() > 0)
            {
                two_par    = new PuzzleObject(two.GetParent());
                master_par = two_par._component.rt.anchoredPosition3D;

                //Debug.Log("two_par" + one);
            }

            //position parent of sub piece
            PuzzleObject par = new PuzzleObject(one.GetParent());
            Vector3      top = par._component.rt.anchoredPosition3D;

            //Debug.Log("id" + one.GetID());
            //Debug.Log("pid " + two.GetParent() + " --- two par " + (two_par._component.id ? two_par._component.id : "333"));
            //Debug.Log("top" + top);
            //Debug.Log("sub" + sub);
            //Debug.Log("sub global" + (top + sub));
            //Debug.Log("master" + master + "mid" + two.GetID());
            //Debug.Log("master par" + master_par);
            //Debug.Log("master global" + (master_par + master));

            Vector3 result = (master_par + master) - (top + sub);

            //Debug.Log("result" + result);

            if (side == 0)
            {
                if ((_component.rt.sizeDelta.x * 0.55f) < result.y && result.y < (_component.rt.sizeDelta.x * 0.7f))
                {
                    if ((_component.rt.sizeDelta.x * 0.1f) > result.x && result.x > -(_component.rt.sizeDelta.x * 0.1f))
                    {
                        //Debug.Log("true");

                        if (two.GetParent() > 0)
                        {
                            this.ConnectChild(one, two_par, result + new Vector3(0, -_component.rt.sizeDelta.x * 0.61f, 0));
                        }
                        else
                        {
                            this.ConnectChild(one, two, result + new Vector3(0, -_component.rt.sizeDelta.x * 0.61f, 0));
                        }
                    }
                }
            }

            if (side == 1)
            {
                if (-(_component.rt.sizeDelta.x * 0.55f) > result.y && result.y > -(_component.rt.sizeDelta.x * 0.7f))
                {
                    if ((_component.rt.sizeDelta.x * 0.1f) > result.x && result.x > -(_component.rt.sizeDelta.x * 0.1f))
                    {
                        //Debug.Log("true");

                        if (two.GetParent() > 0)
                        {
                            this.ConnectChild(one, two_par, result + new Vector3(0, _component.rt.sizeDelta.x * 0.61f, 0));
                        }
                        else
                        {
                            this.ConnectChild(one, two, result + new Vector3(0, _component.rt.sizeDelta.x * 0.61f, 0));
                        }
                    }
                }
            }

            if (side == 2)
            {
                if (-(_component.rt.sizeDelta.x * 0.55f) > result.x && result.x > -(_component.rt.sizeDelta.x * 0.7f))
                {
                    if ((_component.rt.sizeDelta.x * 0.1f) > result.y && result.y > -(_component.rt.sizeDelta.x * 0.1f))
                    {
                        //Debug.Log("true");

                        if (two.GetParent() > 0)
                        {
                            this.ConnectChild(one, two_par, result + new Vector3(_component.rt.sizeDelta.x * 0.61f, 0, 0));
                        }
                        else
                        {
                            this.ConnectChild(one, two, result + new Vector3(_component.rt.sizeDelta.x * 0.61f, 0, 0));
                        }
                    }
                }
            }

            if (side == 3)
            {
                if ((_component.rt.sizeDelta.x * 0.55f) < result.x && result.x < (_component.rt.sizeDelta.x * 0.7f))
                {
                    if ((_component.rt.sizeDelta.x * 0.1f) > result.y && result.y > -(_component.rt.sizeDelta.x * 0.1f))
                    {
                        //Debug.Log("true");

                        if (two.GetParent() > 0)
                        {
                            this.ConnectChild(one, two_par, result + new Vector3(-_component.rt.sizeDelta.x * 0.61f, 0, 0));
                        }
                        else
                        {
                            this.ConnectChild(one, two, result + new Vector3(-_component.rt.sizeDelta.x * 0.61f, 0, 0));
                        }
                    }
                }
            }
        }