Example #1
0
    void Awake()
    {
        // Begin parsing the sequence file
        // First, throw out comments
        Regex  rgx       = new Regex(@"\/\*(\*(?!\/)|[^*])*\*\/");   // Find block comments
        string sceneText = rgx.Replace(sequenceFile.text, "");

        rgx       = new Regex(@"\/\/.*\n");    // Find single line comments
        sceneText = rgx.Replace(sceneText, "");

        // Now split the file into lines
        string[] sequence_lines = sceneText.Split(new string[] { "\n", "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);
        // Regular expression to extract the function name
        Regex funcRgx = new Regex(@"([a-zA-Z0-9]*)\(.*\);");
        // Regular expression to extract the function parameters
        Regex paramRgx = new Regex(@"(?<param>[0-9]+)|""(?<param>.*)""");

        // For each line, extract the function name and parameters into a StageDirection class and store it
        for (int i = 0; i < sequence_lines.Length; i++)
        {
            StageDirection dir  = new StageDirection();
            Match          func = funcRgx.Match(sequence_lines[i]);
            dir.func = func.Groups [1].Value;
            MatchCollection data = paramRgx.Matches(sequence_lines[i]);
            for (int j = 0; j < data.Count; j++)
            {
                dir.data.Add(data [j].Groups ["param"].Value);
            }
            directions.Add(dir);
        }
        // Get a reference to the scene
        parentScene = GetComponentInParent <Scene>();
        if (parentScene == null)
        {
            Debug.LogError("Sequence could not obtain parent scene");
        }
    }
Example #2
0
    protected void PlayDirection()
    {
        StageDirection dir = directions [curDirectionIndex];

        // Figure out what to do as the stage direction
        switch (dir.func)
        {
        case "speakLine":
            int actorIndex = int.Parse(dir.data [0]);
            if (actorIndex >= parentScene.actors.Length)
            {
                Debug.LogWarningFormat("Attempted to give actor index {0} a direction, but that actor index is not in the scene!", actorIndex);
                return;
            }
            GameObject actor = parentScene.actors [actorIndex];
            int        wordTime;
            if (dir.data.Count < 3 || !int.TryParse(dir.data [2], out wordTime))
            {
                wordTime = defaultWordTime;                 // Default to 400 ms
            }
            parentScene.lib.SpeakLine(actor, dir.data [1], wordTime, this);
            return;

        case "moveToSpike":
            actorIndex = int.Parse(dir.data [0]);
            if (actorIndex >= parentScene.actors.Length)
            {
                Debug.LogWarningFormat("Attempted to give actor index {0} a direction, but that actor index is not in the scene!", actorIndex);
                return;
            }
            actor = parentScene.actors [actorIndex];

            int spikeIndex = int.Parse(dir.data [1]);
            if (spikeIndex >= parentScene.spikes.Length)
            {
                Debug.LogWarningFormat("Attempted to get spike index {0}, but that spike index is not in the scene!", spikeIndex);
                return;
            }
            GameObject spike = parentScene.spikes [spikeIndex];

            float movetime = float.Parse(dir.data [2]);
            parentScene.lib.MoveTo(actor, spike.transform.position, movetime, this);
            return;

        case "delay":
            float delay = float.Parse(dir.data [0]);
            if (delay <= 0)
            {
                Debug.LogWarning("Delay command with negative or 0 length. Why is this even here?");
                Next();
                return;
            }

            parentScene.lib.Delay(delay, this);
            return;

        default:
            Debug.LogWarning(string.Format("Sequence attempted to call unknown direction: {0}", dir.func));
            Next();
            return;
        }
    }