Exemplo n.º 1
0
    private IEnumerator FaceTurnAnimation(Hexahedron.Face face)
    {
        Hexahedron.Vertex[]   faceVertices  = Hexahedron.VERTICES_BY_FACE[(int)face];
        VertexAnimationData[] animationData = faceVertices.Select((vertex, faceVertexIndex) => new VertexAnimationData {
            vertexObject  = vertexObjects[(int)controller.vertexPermutationInverse[vertex]],
            startPosition = vertexPositions[vertex],
            endPosition   = vertexPositions[faceVertices[(faceVertexIndex + 1) % faceVertices.Length]],
        }).ToArray();

        float elapsedTime = 0f;
        float duration    = 0.6f;

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

            elapsedTime += Time.deltaTime;
            foreach (VertexAnimationData ad in animationData)
            {
                float progress = Mathf.Min(1f, elapsedTime / duration);
                ad.vertexObject.transform.localPosition = Vector3.Lerp(ad.startPosition, ad.endPosition, progress);
            }
        }

        // Ensure vertices stop at exactly the correct position
        foreach (VertexAnimationData ad in animationData)
        {
            ad.vertexObject.transform.localPosition = ad.endPosition;
        }

        controller.FinishFaceTurn();
        Render();
    }
    public bool StartFaceTurn(HF face)
    {
        if (turningFace.HasValue)
        {
            return(false);
        }

        turningFace = face;
        return(true);
    }
Exemplo n.º 3
0
 private KMSelectable.OnInteractHandler GetFaceButtonPressHandler(Hexahedron.Face face, KMSelectable button)
 {
     return(delegate {
         button.AddInteractionPunch();
         Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, transform);
         if (controller.StartFaceTurn(face))
         {
             Render();
             StartCoroutine(FaceTurnAnimation(face));
         }
         return false;
     });
 }