// Use this for initialization void Start() { //RubikElements = TRubikCreator.CreateRubik(new Vector3(0,0,0), 3, ref Prefab, ref Colors); //RubikElements = TRubikCreator.CreateRubik2(new Vector3(0,0,0), 3, ref Prefab);//, ref Colors); //RubikElements = new TRubikElement[9]; //TRubikElement re = (TRubikElement)ScriptableObject.CreateInstance("TRubikElement"); //re.Init(Prefab, new Vector3(0, 0, 0)); //RubikElements[0] = re; Vector3 center = new Vector3(0, 0, 0); float elementSize = 1.0f; //Rubik = TRubikCreator.CreateRubik(center, elementSize, Prefab); Rubik = TRubikCreator2.CreateRubik(center, elementSize, Prefab); }
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); }