예제 #1
0
    public Vector3 GetTopLeftCorner()
    {
        RectTransform    rt        = (RectTransform)transform;
        UIRectTranslator translate = transform.gameObject.GetComponent <UIRectTranslator>();

        return(translate.WorldTopLeftCorner(rt));
        //return new Vector3(boundsmin.x,boundsmax.y,transform.position.z);
        //all this stuff was supposed to compensate for rotation, but it apparently doesn't matter

        /*if(rotation == 0){
         *      return sprite.bounds.min;
         * }else if(rotation == 90){
         *      return new Vector3(sprite.bounds.min.x,sprite.bounds.max.y,0f);
         * }else if(rotation == 180){
         *      return sprite.bounds.max;
         * }else if(rotation == 270){
         *      return new Vector3(sprite.bounds.max.x,sprite.bounds.max.y,0f);
         * }else{
         *      Debug.Log ("piece has rotation that should be impossible");
         *      return sprite.bounds.min;
         * }*/
    }
예제 #2
0
    public bool TouchIsOnMe(Vector3 touchpos)
    {
        PieceController floatcheck = EditorController.GetFloatingPiece();

        if (floatcheck != this && floatcheck != null)
        {
            if (floatcheck.TouchIsOnMe(touchpos))
            {
                return(false);
            }
        }
        RectTransform    rt        = (RectTransform)transform;
        UIRectTranslator translate = transform.gameObject.GetComponent <UIRectTranslator>();

        bool rectangleOverlap = rt.rect.Contains(rt.InverseTransformPoint(new Vector2(touchpos.x, touchpos.y)));       //sr.bounds.IntersectRay(new Ray(touchpos,transform.forward));

        if (!rectangleOverlap)
        {
            return(false);
        }
        //find local x and y of touch
        int[,] contents = GetArray();

        Vector3 worldSize = translate.WorldSize(rt);
        //Debug.Log("Rsize: " + rt.rect.size.x + "," + rt.rect.size.y);
        //Debug.Log("worldsize: " + worldSize.x + "," + worldSize.y);
        float squareWidth = worldSize.y / (float)contents.GetLength(0);

        Vector3[] corners = new Vector3[4];
        rt.GetWorldCorners(corners);
        Vector3 rCorner = translate.WorldTopLeftCorner(rt);

        Vector3 relativePos = new Vector3(touchpos.x - rCorner.x,
                                          rCorner.y - touchpos.y,
                                          transform.position.z);

        //Debug.Log (file + " touchpos: " + touchpos.x + "," + touchpos.y);
        //Debug.Log (file + " rcorner: " + rCorner.x + "," + rCorner.y);
        //Debug.Log (file + " relative: " + relativePos.x + "," + relativePos.y);
        //Debug.Log (squareWidth);
        if (squareWidth <= 0)
        {
            Debug.Log("BAD BAD TIMES");
            return(false);
        }
        int xcount = -1;
        int ycount = -1;

        while (relativePos.x >= 0)
        {
            relativePos = new Vector3(relativePos.x - squareWidth, relativePos.y, relativePos.z);
            xcount++;
        }
        while (relativePos.y >= 0)
        {
            relativePos = new Vector3(relativePos.x, relativePos.y - squareWidth, relativePos.z);
            ycount++;
        }
        //Debug.Log(file + rotation + " x and y: " + xcount + ", " + ycount);
        int  code   = contents[ycount, xcount];
        bool result = TouchHelper(relativePos, squareWidth, code);

        return(result);
    }