Exemplo n.º 1
0
    protected IEnumerator HandleCurrentInstruction(SpawnInstruction instruction)
    {
        yield return(WaitForTime(instruction.SpawnDelay));

        SpawnInstructionEnemy(instruction);
        CompleteNextInstruction();
    }
Exemplo n.º 2
0
    protected void SpawnInstructionEnemy(SpawnInstruction instruction)
    {
        var newAgent = Instantiate(instruction.SpawnAgent);

        newAgent.StartingNode            = instruction.StartingNode;
        newAgent.transform.parent        = instruction.StartingNode.transform;
        newAgent.transform.localPosition = new Vector2(0, 0);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Tries to setup the next spawn
    /// </summary>
    /// <returns>true if there is another spawn instruction, false if not</returns>
    protected bool TrySetupNextSpawn()
    {
        bool hasNext = spawnInstructions.Next(ref m_CurrentIndex);

        if (hasNext)
        {
            SpawnInstruction nextSpawnInstruction = spawnInstructions[m_CurrentIndex];
            if (nextSpawnInstruction.delayToSpawn <= 0f)
            {
                SpawnCurrent();
            }
            else
            {
                m_SpawnTimer.SetTime(nextSpawnInstruction.delayToSpawn);
            }
        }

        return(hasNext);
    }
Exemplo n.º 4
0
    private void SpawnInstructionEnemy(SpawnInstruction instruction)
    {
        var newAgent = Instantiate(instruction.SpawnAgent);

        newAgent.StartingNode = instruction.StartingNode;
    }
    // ********************************************************************
    // Function:	ProcessInstructions()
    // Purpose:		Processes the instructionString and creates a list
    //                of SpawnInstruction structs.
    // ********************************************************************
    public void ProcessInstructions()
    {
        // If the string is empty, leave requirements as an empty list
        if (m_instructionString == "") return;

        // Split string into separate requirements to process individually.
        string[] instructionStrings = m_instructionString.Split(';');

        // For each requirement...
        foreach(string instructionString in instructionStrings)
        {
            SpawnInstruction instruction = new SpawnInstruction();

            // Break the instruction into three fields
            string[] instructionFields = instructionString.Split(',');
            // Deal with possible leading white space
            if (instructionFields.Length > 0 && instructionFields[0] == " ")
            {
                string newinstructionString = instructionString.Remove(0,1);
                instructionFields = newinstructionString.Split(',');
            }

            // If there are not exactly three fields, there was a formatting error.
            if (instructionFields.Length < 1 || instructionFields.Length > 3)
            {
                Debug.LogError("Instruction parsing problem. Obtained "+instructionFields.Length+" fields when parsing "+instructionString);
                for (int i=0; i<instructionFields.Length; ++i)
                {
                    Debug.LogError("   Field "+i+" = "+instructionFields[i]);
                }
                return;
            }

            // Parse and record the type of creature to be spawned
            instruction.m_enemy =  (GameObject)Resources.Load(instructionFields[0], typeof(GameObject));
            instruction.m_name = instructionFields[0];

            // Parse and record the creature level
            if (instructionFields.Length >= 2)
            {
                int level;
                bool isInteger = int.TryParse(instructionFields[1], out level);
                // If it wasn't numeric, there was an error
                if (!isInteger)
                {
                    Debug.LogError("Second argument must be an integer, failed parsing ("+instructionFields[1]+") from instruction string "+instructionString);
                    return;
                }
                instruction.m_level = level;
            } else
                instruction.m_level = 1;

            // Parse and record the time between spawns
            if (instructionFields.Length >= 3)
            {
                float time;
                bool isFloat = float.TryParse(instructionFields[2], out time);
                // If it wasn't numeric, there was an error
                if (!isFloat)
                {
                    Debug.LogError("Third argument must be a float, failed parsing ("+instructionFields[2]+") from instruction string "+instructionString);
                    return;
                }
                instruction.m_time = time;
            } else
                instruction.m_time = 1;

            // Log results
            Debug.Log("Parsed instruction: "+instruction);

            // Add our new instruction to the list
            m_instructions.Add (instruction);

        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Spawns the current agent
    /// </summary>
    protected void Spawn()
    {
        SpawnInstruction spawnInstruction = spawnInstructions[m_CurrentIndex];

        SpawnAgent(spawnInstruction.agentUnit, spawnInstruction.startingNode);
    }