Пример #1
0
    IEnumerable PerformRotation(FaceRotation rot, float duration)
    {
        _cubelets = PerformRotationOnCubelets(_cubelets, rot, setParent: true);

        var elapsed = 0f;

        while (elapsed < duration)
        {
            yield return(null);

            var delta = Time.deltaTime;
            elapsed += delta;
            OnAxis.localRotation = rot.Rotation(Easing.OutSine(elapsed, 0, 90, duration));
        }
        OnAxis.localRotation = rot.Rotation(90);

        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                for (int z = 0; z < 3; z++)
                {
                    if (x != 1 || y != 1 || z != 1)
                    {
                        _cubelets[x, y, z].Cubelet.parent = OffAxis;
                    }
                }
            }
        }

        OnAxis.localEulerAngles = new Vector3(0, 0, 0);
    }
Пример #2
0
    CubeletInfo[,,] PerformRotationOnCubelets(CubeletInfo[,,] cubelets, FaceRotation rot, bool setParent = false)
    {
        var newCubelets = new CubeletInfo[3, 3, 3];

        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                for (int z = 0; z < 3; z++)
                {
                    if (x != 1 || y != 1 || z != 1)
                    {
                        if (rot.OnAxis(x, y, z))
                        {
                            if (setParent)
                            {
                                cubelets[x, y, z].Cubelet.parent = OnAxis;
                            }
                            var otherCubelet = cubelets[rot.MapX(x, y, z), rot.MapY(x, y, z), rot.MapZ(x, y, z)];
                            newCubelets[x, y, z] = new CubeletInfo(otherCubelet.Cubelet, rot.Rotation(90) * otherCubelet.Rotation);
                        }
                        else
                        {
                            newCubelets[x, y, z] = cubelets[x, y, z];
                        }
                    }
                }
            }
        }
        return(newCubelets);
    }
Пример #3
0
 private void OnRotationFinished(RubiksColor color, FaceRotation direction)
 {
     if (color != RubiksColor.NONE)
     {
         if (direction == FaceRotation.CLOCKWISE)
         {
             m_rubiksLogic.RotateFaceClockWise(color);
         }
         else if (direction == FaceRotation.COUNTERCLOCKWISE)
         {
             m_rubiksLogic.RotateFaceCounterClockWise(color);
         }
     }
 }
Пример #4
0
    public void ParseSequence(string actionSequence)
    {
        m_colors.Clear();
        m_directions.Clear();
        string[] sequenceElements = actionSequence.Split('_');

        for (int i = 0; i < sequenceElements.Length; i++)
        {
            if (sequenceElements[i].Length == 0)
            {
                continue;
            }

            RubiksColor faceColor = RubiksColor.NONE;
            switch (sequenceElements[i][0])
            {
            case 'W':
                faceColor = RubiksColor.WHITE;
                break;

            case 'Y':
                faceColor = RubiksColor.YELLOW;
                break;

            case 'B':
                faceColor = RubiksColor.BLUE;
                break;

            case 'G':
                faceColor = RubiksColor.GREEN;
                break;

            case 'R':
                faceColor = RubiksColor.RED;
                break;

            case 'O':
                faceColor = RubiksColor.ORANGE;
                break;

            default: break;
            }

            FaceRotation direction = sequenceElements[i][1] == 'C' ? FaceRotation.CLOCKWISE : FaceRotation.COUNTERCLOCKWISE;

            m_colors.Add(faceColor);
            m_directions.Add(direction);
        }
    }
Пример #5
0
        /// <summary>
        /// Converts the given face rotation enum to a rotation index for the quad builder.
        /// </summary>
        /// <param name="pos">The position of the block.</param>
        /// <param name="rot">The face rotation.</param>
        /// <returns>The rotation index.</returns>
        private int SolveRotation(BlockPosition pos, FaceRotation rot)
        {
            if (rot == FaceRotation.Random)
            {
                long r;
                r = pos.X * 19;
                r = r * 17 + pos.Y;
                r = r * 31 + pos.Z;

                r = r * 25214903917 + 11;
                r = r * 25214903917 + 11;
                r = r * 25214903917 + 11;
                r = r * 25214903917 + 11;

                return((int)(r & 0x7));
            }

            return((int)rot);
        }
Пример #6
0
    private float GetMultiplierForRotation(RubiksFace faceToRotate, FaceRotation direction)
    {
        float multiplier = 1.0f;

        if (faceToRotate == RubiksFace.LEFT || faceToRotate == RubiksFace.RIGHT)
        {
            multiplier *= -1.0f;
        }

        switch (direction)
        {
        case FaceRotation.COUNTERCLOCKWISE:
            multiplier *= -1.0f;
            break;

        default: break;
        }

        return(multiplier);
    }
Пример #7
0
    private IEnumerator RotateFace(RubiksFace faceToRotate, FaceRotation direction, GameObject faceGO, float duration = 1.0f, RotationCallback callback = null)
    {
        Quaternion from = faceGO.transform.localRotation;
        Quaternion to   = faceGO.transform.localRotation;

        to *= Quaternion.Euler(GetMultiplierForRotation(faceToRotate, direction) * GetAxisForFace(faceToRotate) * NINETY_DEGREES);

        float elapsed = 0.0f;

        while (elapsed < duration)
        {
            faceGO.transform.rotation = Quaternion.Slerp(from, to, elapsed / duration);
            elapsed += Time.deltaTime;
            yield return(null);
        }
        faceGO.transform.rotation = to;

        ResetRubiksFaceParents();
        callback?.Invoke(GetFaceColor(faceToRotate), direction);
        RubiksCubeRotation.SetRotationState(RubiksCubeRotation.RotationState.IDLE);
    }
Пример #8
0
 /// <summary>
 /// Sets the texture rotation for a given block face.
 /// </summary>
 /// <param name="face">The face index.</param>
 /// <param name="rotation">The texture rotation.</param>
 /// <returns>This builder.</returns>
 public BlockBuilder FaceRotation(int face, FaceRotation rotation)
 {
     m_FaceRotations[face] = rotation;
     return(this);
 }
Пример #9
0
 private void Rotate(RubiksFaceRotation.RubiksFace faceToRotate, RubiksColor faceColor, GameObject faceGO, FaceRotation direction)
 {
     m_rubiksFaceRotation.Rotate(faceToRotate, direction, faceGO, m_shuffleRotationDuration, OnRotationFinished);
 }
Пример #10
0
 public void Rotate(RubiksFace faceToRotate, FaceRotation direction, GameObject faceGO, float rotationDuration, RotationCallback callback = null)
 {
     RubiksCubeRotation.SetRotationState(RubiksCubeRotation.RotationState.ROTATING);
     SetRubiksFaceParents(faceToRotate, faceGO);
     StartCoroutine(RotateFace(faceToRotate, direction, faceGO, rotationDuration, callback));
 }
Пример #11
0
 /// <summary>
 /// Creates a new block face.
 /// </summary>
 /// <param name="side">The side of the block this face is on.</param>
 /// <param name="rotation">The texture rotation for this block face.</param>
 /// <param name="texture">The texture for this block face.</param>
 internal BlockFace(int side, FaceRotation rotation, IBlockTexture texture)
 {
     Side     = side;
     Rotation = rotation;
     Texture  = texture;
 }