Exemplo n.º 1
0
        /*
         * Iterates over the given boundaries, and passes the step value to the ForBody
         * provided in the last parameter. Useful for replacing delegates with basic
         * for loops inside of them. The events returned by this function happen as
         * separate events; if the ForBody's AISequence has a delay, this will appear
         * between all the events produced.
         */
        public static AISequence For(float start, float end, float step, ForBody body)
        {
            Debug.Log("For called!");
            if (Mathf.Approximately(step, 0))
            {
                Debug.LogError("Found for loop with step size 0.");
                return(body(start));
            }

            if (Mathf.Abs(Mathf.Sign(end - start) - Mathf.Sign(step)) > 0.01f)
            {
                Debug.LogError("Found for loop that will never terminate.");
                return(body(start));
            }

            AISequence[] sequences = new AISequence[(int)Mathf.Abs((end - start) / step)];
            int          count     = 0;

            if (start > end)
            {
                for (float i = start; i > end; i += step)
                {
                    sequences[count++] = body(i);
                }
            }
            else
            {
                for (float i = start; i < end; i += step)
                {
                    sequences[count++] = body(i);
                }
            }
            return(new AISequence(sequences));
        }
Exemplo n.º 2
0
        private AIEvent[] FlattenRecur(AISequence sequence)
        {
            AISequence[] seqChildren = sequence.GetChildren();
            if (seqChildren != null)
            {
                List <AIEvent> childrenEvents = new List <AIEvent>();
                for (int i = 0; i < seqChildren.Length; i++)
                {
                    childrenEvents.AddRange(FlattenRecur(seqChildren[i]));
                }
                return(childrenEvents.ToArray());
            }

            if (sequence.events == null)
            {
                Debug.LogError("Failed to flatten AISequence: \"" + sequence + "\". Children and Events are both null.");
            }
            return(sequence.events); // If null, will crash AddRange above
        }
Exemplo n.º 3
0
        /*
         * Returns the provided sequence array, but with every element merged in order
         * respecting wait times. Used to collapse a list of exploded sequences from
         * a Generator function into a single sequence.
         */
        private static AISequence SequentialMerge(AISequence[] sequences)
        {
            if (sequences.Length == 0)
            {
                return(new AISequence(new AIEvent[0]));
            }
            if (sequences.Length == 1)
            {
                return(sequences[0]);
            }

            AISequence sequential = sequences[0];

            for (int i = 1; i < sequences.Length; i++)
            {
                sequential = sequential.Then(sequences[i]);
            }
            return(sequential);
        }
Exemplo n.º 4
0
        /*
         * Returns this AISequence repeated "times" number of times.
         */
        public AISequence Times(int times)
        {
            if (times <= 0)
            {
                Debug.LogError("Cannot repeat sequence 0 or fewer times");
                times = 1;
            }
            if (times == 1)
            {
                return(this);
            }

            AISequence[] newSequences = new AISequence[times];
            for (int i = 0; i < times; i++)
            {
                newSequences[i] = this;
            }
            return(new AISequence(newSequences)
            {
                Description = times + " times: "
            });
        }
Exemplo n.º 5
0
 public AIPhase AddRepeatingScriptedSequence(int everyX, AISequence sequence)
 {
     repeatingScriptedSequences.Add(new AIPhaseScriptedComponent(everyX, sequence));
     return(this);
 }
Exemplo n.º 6
0
 public AIPhase AddScriptedSequence(int when, AISequence sequence)
 {
     scriptedSequences.Add(new AIPhaseScriptedComponent(when, sequence));
     return(this);
 }
Exemplo n.º 7
0
 public AIPhase AddSequence(int weight, AISequence sequence)
 {
     phaseSequences.Add(new AIPhaseComponent(weight, sequence));
     totalWeight += weight;
     return(this);
 }
Exemplo n.º 8
0
 public AIPhaseScriptedComponent(int everyX, AISequence sequence)
 {
     this.everyX   = everyX;
     this.sequence = sequence;
 }
Exemplo n.º 9
0
 public AIPhaseComponent(int weight, AISequence sequence)
 {
     this.weight   = weight;
     this.sequence = sequence;
 }
Exemplo n.º 10
0
 /*
  * Returns this AISequence, followed by the events in "seq", in order.
  */
 public AISequence Then(AISequence seq)
 {
     return(new AISequence(this, seq));
 }