void Cycle4CubleletsReverse(Vector3Int c0, Vector3Int c1, Vector3Int c2, Vector3Int c3, RotationDirection direction) { if (direction == RotationDirection.reverse) { Cycle4Cublelets(c0, c1, c2, c3, RotationDirection.normal); return; } CubeletData cd = _cubeletData[c3.x, c3.y, c3.z]; _cubeletData[c3.x, c3.y, c3.z] = _cubeletData[c2.x, c2.y, c2.z]; _cubeletData[c2.x, c2.y, c2.z] = _cubeletData[c1.x, c1.y, c1.z]; _cubeletData[c1.x, c1.y, c1.z] = _cubeletData[c0.x, c0.y, c0.z]; _cubeletData[c0.x, c0.y, c0.z] = cd; }
// Create the Cubelets of the Cube, // and record the original copy and transforms for quick reset. void Start() { _origSphereTransformData = new TransformData(innerSphere.transform); for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { for (int z = 0; z < 5; z++) { if (IsOuterCubelet(x, y, z)) { CubeletData cData = CreateCubelet(x, y, z); _cubeletData[x, y, z] = cData; _origCubeletData[x, y, z] = cData; // Copy the original configuration to allow quick reset. _origTransformData[x, y, z] = new TransformData(cData.cubelet.transform); } } } } }
public CubeletData CreateCubelet(int x, int y, int z) { string codeNumber = string.Format("{0}{1}{2}", x, y, z); float xTrans = (x - 2) * 1.0f; float yTrans = (y - 2) * 1.0f; float zTrans = (z - 2) * 1.0f; string codeName = "Cubelet" + codeNumber; CubeletData cData = new CubeletData(); GameObject cubelet = new GameObject(codeName); cData.cubelet = cubelet; GameObject cubeletTop = new GameObject(codeName + "Top"); GameObject cubeletBottom = new GameObject(codeName + "Bottom"); GameObject cubeletFront = new GameObject(codeName + "Front"); GameObject cubeletBack = new GameObject(codeName + "Back"); GameObject cubeletLeft = new GameObject(codeName + "Left"); GameObject cubeletRight = new GameObject(codeName + "Right"); cubelet.transform.parent = cubeRoot.transform; cubeletTop.transform.parent = cubelet.transform; cubeletBottom.transform.parent = cubelet.transform; cubeletFront.transform.parent = cubelet.transform; cubeletBack.transform.parent = cubelet.transform; cubeletLeft.transform.parent = cubelet.transform; cubeletRight.transform.parent = cubelet.transform; cubelet.transform.Translate(xTrans, yTrans, zTrans); MeshFilter mfTop = cubeletTop.AddComponent <MeshFilter>(); MeshFilter mfBottom = cubeletBottom.AddComponent <MeshFilter>(); MeshFilter mfFront = cubeletFront.AddComponent <MeshFilter>(); MeshFilter mfBack = cubeletBack.AddComponent <MeshFilter>(); MeshFilter mfLeft = cubeletLeft.AddComponent <MeshFilter>(); MeshFilter mfRight = cubeletRight.AddComponent <MeshFilter>(); MeshRenderer mrTop = cubeletTop.AddComponent <MeshRenderer>(); MeshRenderer mrBottom = cubeletBottom.AddComponent <MeshRenderer>(); MeshRenderer mrFront = cubeletFront.AddComponent <MeshRenderer>(); MeshRenderer mrBack = cubeletBack.AddComponent <MeshRenderer>(); MeshRenderer mrLeft = cubeletLeft.AddComponent <MeshRenderer>(); MeshRenderer mrRight = cubeletRight.AddComponent <MeshRenderer>(); if (y == 4) { mrTop.material = faceMaterialBlue; mrTop.materials[0].mainTexture = _cubeFaceletTextures[x, z]; } else { mrTop.material = faceMaterialBlack; } if (y == 0) { mrBottom.material = faceMaterialGreen; mrBottom.materials[0].mainTexture = _cubeFaceletTextures[x, 4 - z]; } else { mrBottom.material = faceMaterialBlack; } if (z == 0) { mrFront.material = faceMaterialYellow; mrFront.materials[0].mainTexture = _cubeFaceletTextures[x, y]; } else { mrFront.material = faceMaterialBlack; } if (z == 4) { mrBack.material = faceMaterialWhite; mrBack.materials[0].mainTexture = _cubeFaceletTextures[4 - x, y]; // NOTE: On map, the FacePanel is thereby rotated 180 degrees. } else { mrBack.material = faceMaterialBlack; } if (x == 0) { mrLeft.material = faceMaterialRed; mrLeft.materials[0].mainTexture = _cubeFaceletTextures[4 - z, y]; } else { mrLeft.material = faceMaterialBlack; } if (x == 4) { mrRight.material = faceMaterialOrange; mrRight.materials[0].mainTexture = _cubeFaceletTextures[z, y]; // OK! } else { mrRight.material = faceMaterialBlack; } cData.textureNumberBack = mrBack.materials[0].mainTexture; cData.textureNumberFront = mrFront.materials[0].mainTexture; cData.textureNumberLeft = mrLeft.materials[0].mainTexture; cData.textureNumberRight = mrRight.materials[0].mainTexture; cData.textureNumberUp = mrTop.materials[0].mainTexture; cData.textureNumberDown = mrBottom.materials[0].mainTexture; // x axis points right. y axis points up. z axis points into the screen. // Top -------------------- mfTop.mesh = new Mesh { vertices = new Vector3[] { vMPM, vMPP, vPPP, vPPM }, uv = stdUV, triangles = stdTriangles }; RecalculateMesh(mfTop); // Bottom ----------------- mfBottom.mesh = new Mesh { vertices = new Vector3[] { vMMP, vMMM, vPMM, vPMP }, uv = stdUV, triangles = stdTriangles }; RecalculateMesh(mfBottom); // Front ------------------ mfFront.mesh = new Mesh { vertices = new Vector3[] { vMMM, vMPM, vPPM, vPMM }, uv = stdUV, triangles = stdTriangles }; RecalculateMesh(mfFront); // Back ------------------- mfBack.mesh = new Mesh { vertices = new Vector3[] { vPMP, vPPP, vMPP, vMMP }, uv = stdUV, triangles = stdTriangles }; RecalculateMesh(mfBack); // Left ------------------- mfLeft.mesh = new Mesh { vertices = new Vector3[] { vMMP, vMPP, vMPM, vMMM }, uv = stdUV, triangles = stdTriangles }; RecalculateMesh(mfLeft); // Right ------------------ mfRight.mesh = new Mesh { vertices = new Vector3[] { vPMM, vPPM, vPPP, vPMP }, uv = stdUV, triangles = stdTriangles }; RecalculateMesh(mfRight); // Now, set up the extra cubelet stuff. cubelet.AddComponent <BoxCollider>(); Rigidbody rb = cubelet.AddComponent <Rigidbody>(); rb.useGravity = false; rb.isKinematic = true; cubelet.tag = "Cubelet"; cubelet.layer = 8; // "Clickable" return(cData); }
public void CycleTextures() { _textureType = AnimationData.CycleTextureType(_textureType); GameObject cubeletFaceUp, cubeletFaceDown, cubeletFaceFront, cubeletFaceBack, cubeletFaceLeft, cubeletFaceRight; Texture textureUp, textureDown, textureFront, textureBack, textureLeft, textureRight; if (_textureType == TextureType.plain) { textureUp = texturePlain; textureDown = texturePlain; textureFront = texturePlain; textureBack = texturePlain; textureLeft = texturePlain; textureRight = texturePlain; } else // if (_textureType == TextureType.none) { textureUp = null; textureDown = null; textureFront = null; textureBack = null; textureLeft = null; textureRight = null; } for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { for (int z = 0; z < 5; z++) { if (IsOuterCubelet(x, y, z)) { CubeletData cData = _cubeletData[x, y, z]; cubeletFaceUp = cData.cubelet.transform.GetChild(0).gameObject; cubeletFaceDown = cData.cubelet.transform.GetChild(1).gameObject; cubeletFaceFront = cData.cubelet.transform.GetChild(2).gameObject; cubeletFaceBack = cData.cubelet.transform.GetChild(3).gameObject; cubeletFaceLeft = cData.cubelet.transform.GetChild(4).gameObject; cubeletFaceRight = cData.cubelet.transform.GetChild(5).gameObject; if (_textureType == TextureType.number) { textureUp = cData.textureNumberUp; textureDown = cData.textureNumberDown; textureFront = cData.textureNumberFront; textureBack = cData.textureNumberBack; textureLeft = cData.textureNumberLeft; textureRight = cData.textureNumberRight; } cubeletFaceUp.GetComponent <MeshRenderer>().materials[0].mainTexture = textureUp; cubeletFaceDown.GetComponent <MeshRenderer>().materials[0].mainTexture = textureDown; cubeletFaceFront.GetComponent <MeshRenderer>().materials[0].mainTexture = textureFront; cubeletFaceBack.GetComponent <MeshRenderer>().materials[0].mainTexture = textureBack; cubeletFaceLeft.GetComponent <MeshRenderer>().materials[0].mainTexture = textureLeft; cubeletFaceRight.GetComponent <MeshRenderer>().materials[0].mainTexture = textureRight; } } } } }