Beispiel #1
0
    public TRotationPlane FindPlane(ref TRubikCubik cubik, ref List <TRotationPlane> planes)
    {
        for (int i = 0; i < planes.Count; ++i)
        {
            TRotationPlane plane = planes[i];
            foreach (TRubikCubik rc in plane.Elements)
            {
                if (rc == cubik)
                {
                    return(plane);
                }
            }
        }

        return(null);
    }
Beispiel #2
0
    public void SelectRotationPlane(ref List <TRotationPlane> planes, ref TRubikCubik cubik, bool select)
    {
        TRotationPlane plane = FindPlane(ref cubik, ref planes);

        if (plane == null)
        {
            Debug.Log("Can't find plane");
            return;
        }
        foreach (TRubikCubik rc in plane.Elements)
        {
            if (select)
            {
                rc.Select();
            }
            else
            {
                rc.UnSelect();
            }
        }
    }
Beispiel #3
0
    public static TRubik2 CreateRubik(Vector3 center, float elementSize, GameObject prefab)
    {
        int     centerIndex = (Dimension - 1) / 2;
        float   startShift  = elementSize * (((float)Dimension - 1) / 2);
        Vector3 startPos    = center - new Vector3(startShift, startShift, startShift);
        TRubik2 res         = new TRubik2();

        int nameIndex = 0;

        for (int i = 0; i < Dimension; ++i)
        {
            //int j = 0;
            for (int j = 0; j < Dimension; ++j)
            {
                //int k = 0;
                for (int k = 0; k < Dimension; ++k)
                {
                    string name = nameIndex.ToString();
                    nameIndex += 1;
                    // skip center cube
                    if (i == centerIndex && j == centerIndex && k == centerIndex)
                    {
                        // add fake element
                        res.GOBS.Add(new GameObject());
                        continue;
                    }
                    Vector3     smallCubCenter = startPos + new Vector3(elementSize * i, elementSize * j, elementSize * k);
                    TRubikCubik smallCubik     = CreateSmallCubik(smallCubCenter, center, prefab, elementSize, ref name);
                    res.Elements.Add(smallCubik);
                    res.GOBS.Add(smallCubik.HolderObject);
                    //ProcessSides(smallCubCenter,
                    //break;
                }
            }
        }

        // rotation planes
        for (int i = 0; i < Dimension; ++i)
        {
            //int j = 0;
            TRotationPlane xPlane = new TRotationPlane();
            TRotationPlane yPlane = new TRotationPlane();
            TRotationPlane zPlane = new TRotationPlane();
            for (int j = 0; j < Dimension; ++j)
            {
                //int k = 0;
                for (int k = 0; k < Dimension; ++k)
                {
                    if (i == centerIndex && j == centerIndex && k == centerIndex)
                    {
                        continue;
                    }

                    TRubikCubik cubik = res.GOBS[i * Dimension * Dimension + j * Dimension + k].GetComponent <TRubikCubik>();
                    xPlane.Elements.Add(cubik);
                    cubik = res.GOBS[j * Dimension * Dimension + i * Dimension + k].GetComponent <TRubikCubik>();
                    yPlane.Elements.Add(cubik);
                    cubik = res.GOBS[k * Dimension * Dimension + i * Dimension + j].GetComponent <TRubikCubik>();
                    zPlane.Elements.Add(cubik);
                }
            }
            res.XPlanes.Add(xPlane);
            res.YPlanes.Add(yPlane);
            res.ZPlanes.Add(zPlane);
        }

        return(res);
    }