コード例 #1
0
 public AggregateGradualMovement()
 {
     movements             = new List <QIGradualMovement>();
     paused                = false;
     currentStaticMovement = null;
     aggregateNonStacked   = 0;
 }
コード例 #2
0
 public void RemoveStaticMovement()
 {
     if (currentStaticMovement == null)
     {
         return;
     }
     movements.Remove(currentStaticMovement);
     currentStaticMovement = null;
     aggregateNonStacked--;
 }
コード例 #3
0
        /// <summary>
        /// Adds a gameobject to be moved gradually.
        /// </summary>
        /// <param name="rb"> the rigidbody to be moved. </param>
        /// <param name="movement"> the well-defined gradual movement </param>
        /// <param name="stackWithCurrent"> if this is true and the passed movement is a stacking one, stacks the movement with the current movements being executed for the gameobject. If all movements added so far to the object is already stacked, this boolean will not matter. </param>
        /// <param name="attemptMerge"> attempts to merge this movement with other ones for the object. Stacking and non-stacking movements will never be merged. Keep in mind that when this is checked, though it may potentially increase efficiency for the future, can also produce a process-intensive function-call. </param>
        public static void AddGradualMovement(Rigidbody rb, QIGradualMovement movement, bool stackWithCurrent = false, bool attemptMerge = false)
        {
            if (!rigidGradualMovements.ContainsKey(rb))
            {
                //did not exist before. REMEMBER TO DELETE A MOVEMENT IF IT HAS NO MORE WITHIN THE QUEUE. THERE MUST ALWAYS BE A CURRENT MOVEMENT FOR A MOVEMENT.
                rigidGradualMovements.Add(rb, new Queue <QIGradualMovement>());
                currentRigidGradualMovements.Add(rb, new AggregateGradualMovement());
                currentRigidGradualMovements[rb].movements.Add(movement);
                if (!movement.IsStacked())
                {
                    currentRigidGradualMovements[rb].aggregateNonStacked++;
                    currentRigidGradualMovements[rb].currentStaticMovement = movement;
                }
            }
            else
            {
                //did exist before.

                if (currentRigidGradualMovements[rb].aggregateNonStacked != 0)
                {
                    if (movement.IsStacked())
                    {
                        //the movement is one that stacks.
                        if (stackWithCurrent)
                        {
                            //attempt to merge the current input movement with one of the current ones.
                            if (attemptMerge)
                            {
                                bool merged = false;
                                foreach (QIGradualMovement mov in currentRigidGradualMovements[rb].movements)
                                {
                                    if (mov.IsStacked() && mov.AttemptMerge(movement))
                                    {
                                        merged = true;
                                        break;
                                    }
                                }
                                if (merged)
                                {
                                    return;
                                }
                            }
                            currentRigidGradualMovements[rb].movements.Add(movement);
                        }
                        else
                        {
                            //attempt to merge the current input movement with one of the stacked ones that are enqueued within the latest group.
                            if (attemptMerge)
                            {
                                bool merged = false;
                                QIGradualMovement[] traversedMovements = rigidGradualMovements[rb].ToArray();
                                for (int i = traversedMovements.Length - 1; i > -1; i++)
                                {
                                    if (!traversedMovements[i].IsStacked())
                                    {
                                        break;
                                    }
                                    else if (traversedMovements[i].AttemptMerge(movement))
                                    {
                                        merged = true;
                                        break;
                                    }
                                }
                                if (merged)
                                {
                                    return;
                                }
                            }
                            //otherwise add it to the queue.
                            rigidGradualMovements[rb].Enqueue(movement);
                        }
                    }
                    else
                    {
                        //attempt to merge the current input movement with one of the stacked ones that are enqueued within the latest group.
                        if (attemptMerge)
                        {
                            bool merged = false;
                            QIGradualMovement[] traversedMovements = rigidGradualMovements[rb].ToArray();
                            for (int i = traversedMovements.Length - 1; i > -1; i++)
                            {
                                if (traversedMovements[i].IsStacked())
                                {
                                    continue;
                                }
                                else if (traversedMovements[i].AttemptMerge(movement))
                                {
                                    merged = true;
                                }
                                break;
                            }
                            if (merged)
                            {
                                return;
                            }
                        }
                        //otherwise add it to the queue.

                        rigidGradualMovements[rb].Enqueue(movement);
                        currentRigidGradualMovements[rb].aggregateNonStacked++;
                    }
                }
                else
                {
                    //special case in which everything is stacked up to now.
                    if (!movement.IsStacked())
                    {
                        //wont check for merging as is the only non-stacked.
                        currentRigidGradualMovements[rb].aggregateNonStacked++;
                        currentRigidGradualMovements[rb].currentStaticMovement = movement;
                    }
                    else
                    {
                        //attempt to merge the current input movement with one of the current ones.
                        if (attemptMerge)
                        {
                            bool merged = false;
                            foreach (QIGradualMovement mov in currentRigidGradualMovements[rb].movements)
                            {
                                if (mov.AttemptMerge(movement))
                                {
                                    merged = true;
                                    break;
                                }
                            }
                            if (merged)
                            {
                                return;
                            }
                        }
                    }
                    currentRigidGradualMovements[rb].movements.Add(movement);
                }
            }
        }
コード例 #4
0
 public bool AttemptMerge(QIGradualMovement mov)
 {
     return(false);
 }
コード例 #5
0
 /// <summary>
 /// Attempts to merge the input movement into this current movement. These are often implemented such that similar types of movement, and especially linear ones over similar times, can be handled as a single movement instead to increase performance.
 /// </summary>
 /// <param name="mov"> The movement to be merged. </param>
 /// <returns> whether the input movement has been integrated into this movement. If true, this class is now responsible for adding the displacement of the other movement into itself. If false, the movement that has been attempted to be merged will be queued normally.</returns>
 public bool AttemptMerge(QIGradualMovement mov)
 {
     return(false); //TODO AT LEAST IMPLEMENT SOME MERGES!
 }