示例#1
0
文件: AISequence.cs 项目: pffft/ld42
        /*
         * 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));
        }
示例#2
0
文件: AISequence.cs 项目: pffft/ld42
        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
        }
示例#3
0
文件: AISequence.cs 项目: pffft/ld42
        /*
         * 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);
        }
示例#4
0
文件: AISequence.cs 项目: pffft/ld42
        /*
         * 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: "
            });
        }
示例#5
0
文件: AIPhase.cs 项目: pffft/ld42
 public AIPhase AddRepeatingScriptedSequence(int everyX, AISequence sequence)
 {
     repeatingScriptedSequences.Add(new AIPhaseScriptedComponent(everyX, sequence));
     return(this);
 }
示例#6
0
文件: AIPhase.cs 项目: pffft/ld42
 public AIPhase AddScriptedSequence(int when, AISequence sequence)
 {
     scriptedSequences.Add(new AIPhaseScriptedComponent(when, sequence));
     return(this);
 }
示例#7
0
文件: AIPhase.cs 项目: pffft/ld42
 public AIPhase AddSequence(int weight, AISequence sequence)
 {
     phaseSequences.Add(new AIPhaseComponent(weight, sequence));
     totalWeight += weight;
     return(this);
 }
示例#8
0
文件: AIPhase.cs 项目: pffft/ld42
 public AIPhaseScriptedComponent(int everyX, AISequence sequence)
 {
     this.everyX   = everyX;
     this.sequence = sequence;
 }
示例#9
0
文件: AIPhase.cs 项目: pffft/ld42
 public AIPhaseComponent(int weight, AISequence sequence)
 {
     this.weight   = weight;
     this.sequence = sequence;
 }
示例#10
0
文件: AISequence.cs 项目: pffft/ld42
 /*
  * Returns this AISequence, followed by the events in "seq", in order.
  */
 public AISequence Then(AISequence seq)
 {
     return(new AISequence(this, seq));
 }