Exemple #1
0
        public IEnumerator MoveCupCircular(Vector3 destination, float duration, RotationDirection dir, RotationLane lan)
        {
            if (m_ball != null)
            {
                m_ball.GetComponent <Renderer>().enabled = false;
            }
            float currentDuration = 0.0f;
            float currentAngle    = 0.0f;
            float startingAngle   = 0.0f;
            float resultingAngle  = 0.0f;

            if (dir == RotationDirection.left)
            {
                startingAngle  = 90.0f * Mathf.Deg2Rad;
                resultingAngle = 270.0f * Mathf.Deg2Rad;
            }
            if (dir == RotationDirection.right)
            {
                startingAngle  = 270.0f * Mathf.Deg2Rad;
                resultingAngle = 90.0f * Mathf.Deg2Rad;
            }

            float   distance   = Vector3.Distance(destination, transform.localPosition) / 2.0f;
            Vector3 start      = gameObject.transform.localPosition;
            Vector3 pivotPoint = (transform.localPosition + destination) / 2.0f;



            while (currentDuration < duration)
            {
                currentAngle = Mathf.Lerp(startingAngle, resultingAngle, currentDuration / duration);
                Vector3 nextPos = gameObject.transform.localPosition;
                nextPos.x = pivotPoint.x + Mathf.Sin(currentAngle) * distance;
                if (lan == RotationLane.front)
                {
                    nextPos.z = pivotPoint.z + Mathf.Cos(currentAngle) * distance;
                }
                if (lan == RotationLane.back)
                {
                    nextPos.z = pivotPoint.z - Mathf.Cos(currentAngle) * distance;
                }
                gameObject.transform.localPosition = nextPos;
                currentDuration += Time.deltaTime;
                yield return(null);
            }

            gameObject.transform.localPosition = destination;

            if (m_ball != null)
            {
                m_ball.GetComponent <Renderer>().enabled = true;
                m_ball.transform.localPosition           = new Vector3(gameObject.transform.localPosition.x, m_ball.transform.localPosition.y, gameObject.transform.localPosition.z);
            }
        }
Exemple #2
0
        private IEnumerator SwapCups()
        {
            ShuffleMaster.Instance.CupsMoveable = false;

            if (m_AdjacentCup == null)
            {
                //no swapping needed.
                transform.localPosition = m_OriginalPosition;
                yield return(null);
            }
            if (m_AdjacentCup != null)
            {
                RotationDirection dir = RotationDirection.none;
                RotationLane      lan = RotationLane.none;
                //swapping needed
                if (m_Lifted)
                {
                    int index_a  = Array.IndexOf(ShuffleMaster.Instance.Cups, gameObject);
                    int index_b  = Array.IndexOf(ShuffleMaster.Instance.Cups, m_AdjacentCup);
                    int distance = Mathf.Abs(index_a - index_b);
                    if (index_a < index_b)
                    {
                        dir = RotationDirection.left;
                        lan = RotationLane.front;
                    }
                    if (index_b < index_a)
                    {
                        dir = RotationDirection.right;
                        lan = RotationLane.back;
                    }

                    //Cups are near to each other
                    if (distance == 1)
                    {
                        yield return(StartCoroutine(ShuffleMaster.Instance.Cups[index_b].gameObject.GetComponent <DragMe>().MoveCupLinear(m_OriginalPosition, 0.5f)));

                        yield return(StartCoroutine(MoveCupLinear(ShuffleMaster.Instance.Cups[index_b].GetComponent <DragMe>().m_OriginalPosition, 0.5f)));

                        GameObject other_cup = ShuffleMaster.Instance.Cups[index_b];
                        ShuffleMaster.Instance.Cups[index_b] = gameObject;
                        ShuffleMaster.Instance.Cups[index_a] = other_cup;
                        gameObject.GetComponent <DragMe>().resetOriginalPosition();
                        other_cup.GetComponent <DragMe>().resetOriginalPosition();
                        if (m_ball != null)
                        {
                            m_ball.GetComponent <Renderer>().enabled = true;
                        }
                    }
                    //Cups are far to each other
                    if (distance == 2)
                    {
                        yield return(StartCoroutine(ShuffleMaster.Instance.Cups[index_b].gameObject.GetComponent <DragMe>().MoveCupCircular(m_OriginalPosition, 0.5f, dir, lan)));

                        yield return(StartCoroutine(MoveCupLinear(ShuffleMaster.Instance.Cups[index_b].GetComponent <DragMe>().m_OriginalPosition, 0.5f)));

                        GameObject other_cup = ShuffleMaster.Instance.Cups[index_b];
                        ShuffleMaster.Instance.Cups[index_b] = gameObject;
                        ShuffleMaster.Instance.Cups[index_a] = other_cup;
                        gameObject.GetComponent <DragMe>().resetOriginalPosition();
                        other_cup.GetComponent <DragMe>().resetOriginalPosition();
                        if (m_ball != null)
                        {
                            m_ball.GetComponent <Renderer>().enabled = true;
                        }
                    }
                }
            }
            m_Lifted      = false;
            m_AdjacentCup = null;
            //gameObject.layer = LayerMask.NameToLayer("Default");
            ShuffleMaster.Instance.CupsMoveable = true;


            yield return(null);
        }