Exemplo n.º 1
0
        private static void OnCurrentRigidMovementEnd(Rigidbody rb)
        {
            AggregateGradualMovement  aggr  = currentRigidGradualMovements[rb];
            Queue <QIGradualMovement> queue = rigidGradualMovements[rb];
            QIGradualMovement         mov;

            while (queue.Count > 0)
            {
                mov = queue.Dequeue();
                aggr.movements.Add(mov);
                if (!mov.IsStacked())
                {
                    aggr.currentStaticMovement = mov;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private static void OnCurrentMovementEnd(GameObject g)
        {
            AggregateGradualMovement  aggr  = currentGradualMovements[g];
            Queue <QIGradualMovement> queue = gradualMovements[g];
            QIGradualMovement         mov;

            while (queue.Count > 0)
            {
                mov = queue.Dequeue();
                aggr.movements.Add(mov);
                if (!mov.IsStacked())
                {
                    aggr.currentStaticMovement = mov;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private IEnumerator MovementEnumeration()
        {
            enumerationRunning = true;
            while (enumerationActive)
            {
                float time = 0f;
                //waiting happens here.
                if (currentProperties.useFixedUpdate)
                {
                    yield return(new WaitForFixedUpdate());

                    time = Time.fixedDeltaTime;
                }
                else
                {
                    yield return(new WaitForEndOfFrame());

                    time = Time.deltaTime;
                }
                //code goes here.
                Vector3 currentAggregateTransformation;
                toBeRemoved.Clear();
                objectsToBeRemoved.Clear();
                rigidbodiesToBeRemoved.Clear();
                //handle regular
                foreach (GameObject g in currentGradualMovements.Keys)
                {
                    AggregateGradualMovement mov = currentGradualMovements[g];
                    if (mov.paused)
                    {
                        continue;
                    }
                    currentAggregateTransformation = Vector3.zero;
                    toBeRemoved.Clear();
                    foreach (QIGradualMovement qmov in mov.movements)
                    {
                        Vector3 trans = qmov.GetApplyTransformation(time);
                        if (trans.x == Vector3.negativeInfinity.x)
                        {
                            //the movement is done! remove it handle logic and then continue.
                            toBeRemoved.Add(qmov);
                            continue;
                        }
                        if (!qmov.IsWorldTranslation())
                        {
                            trans    = g.transform.rotation * trans;
                            trans.x /= g.transform.lossyScale.x;
                            trans.y /= g.transform.lossyScale.y;
                            trans.z /= g.transform.lossyScale.z;
                        }
                        currentAggregateTransformation += trans;
                    }
                    //do the transformation
                    g.transform.Translate(currentAggregateTransformation, Space.World);
                    foreach (QIGradualMovement qmov in toBeRemoved)
                    {
                        if (!mov.movements.Contains(qmov))
                        {
                            continue;
                        }
                        if (qmov.IsStacked())
                        {
                            //just a stacked movement that has finished.
                            qmov.OnMovementFinish(false);
                            mov.movements.Remove(qmov);
                        }
                        else
                        {
                            //the non stacked movement has finished!
                            qmov.OnMovementFinish(false);
                            mov.RemoveStaticMovement();
                            OnCurrentMovementEnd(g);
                        }
                    }
                    if (mov.movements.Count == 0)
                    {
                        //movement of this object has completely finished.
                        objectsToBeRemoved.Add(g);
                    }
                }
                foreach (GameObject g in objectsToBeRemoved)
                {
                    gradualMovements.Remove(g);
                    currentGradualMovements.Remove(g);
                }
                //handle rigid
                foreach (Rigidbody rb in currentRigidGradualMovements.Keys)
                {
                    AggregateGradualMovement mov = currentRigidGradualMovements[rb];
                    if (mov.paused)
                    {
                        continue;
                    }
                    currentAggregateTransformation = Vector3.zero;
                    toBeRemoved.Clear();
                    foreach (QIGradualMovement qmov in mov.movements)
                    {
                        Vector3 trans = qmov.GetApplyTransformation(time);
                        if (trans.x == Vector3.negativeInfinity.x)
                        {
                            //the movement is done! remove it handle logic and then continue.
                            toBeRemoved.Add(qmov);
                            continue;
                        }
                        if (!qmov.IsWorldTranslation())
                        {
                            trans    = rb.transform.rotation * trans;
                            trans.x /= rb.transform.lossyScale.x;
                            trans.y /= rb.transform.lossyScale.y;
                            trans.z /= rb.transform.lossyScale.z;
                        }
                        currentAggregateTransformation += trans;
                    }
                    //do the transformation
                    if (currentProperties.useRigidBodyMovement)
                    {
                        rb.MovePosition(rb.transform.position + currentAggregateTransformation);
                    }
                    else
                    {
                        rb.position = rb.transform.position + currentAggregateTransformation;
                    }
                    foreach (QIGradualMovement qmov in toBeRemoved)
                    {
                        if (!mov.movements.Contains(qmov))
                        {
                            continue;
                        }
                        if (qmov.IsStacked())
                        {
                            //just a stacked movement that has finished.
                            qmov.OnMovementFinish(false);
                            mov.movements.Remove(qmov);
                        }
                        else
                        {
                            //the non stacked movement has finished!
                            qmov.OnMovementFinish(false);
                            mov.RemoveStaticMovement();
                            OnCurrentRigidMovementEnd(rb);
                        }
                    }
                    if (mov.movements.Count == 0)
                    {
                        //movement of this object has completely finished.
                        rigidbodiesToBeRemoved.Add(rb);
                    }
                }
                foreach (Rigidbody rb in rigidbodiesToBeRemoved)
                {
                    rigidGradualMovements.Remove(rb);
                    currentRigidGradualMovements.Remove(rb);
                }
            }
            enumerationRunning = false;
        }