SR EndPoints - Smehi/WaveOne GitHub Wiki

As a user you have to option to enable end points for your objects. End points are specific per object with wave components. This means that you can have the same enemy with different end points with different spawners.

Properties

Name Description
EndPoints List of custom struct which contains the end point and a list of GameObjects.
NoEndPointEnemies List of GameObjects which don't have any end points.

Methods

public void SetValidEndPointsPerEnemy(GameObject enemy)

This method acts as a initializer. It takes enemy and find all end points that are available for this GameObject and stores that in a dictionary.

You would use this in the spawner script like this:

private void Start()
{
    ... 

    endPoints = GetComponent<EndPoint>();

    // If we found a component it's not null so we assume we want end points.
    if (endPoints)
    {
        SetEndPoints = true;

        // Loop through each wave and in each wave each enemy.
        // Call SetValidEndPointsPerEnemy with each enemy to initialize them.
        // If that enemy is already initialized it will just be skipped.
        for (int i = 0; i < waves.Count; i++)
            for (int j = 0; j < waves[i].enemies.Count; j++)
                endPoints.SetValidEndPointsPerEnemy(waves[i].enemies[j].gameObject);
    }

    ...
}

public List<Transform> GetEndPoints(GameObject enemyPrefab)

After we have initialized the dictionary with enemy/end points pairs we can use this method to get the list of valid end points for that enemy.

Example usage:

private IEnumerator WaveDeployment()
{
    ... 

    GameObject instance = null;

    // If we don't do this we will get different end points for enemies in the same formation.
    presetIndexEndPoint = Random.Range(0, endPoints.GetEndPoints(waves[currentWave].enemies[currentEnemy].gameObject).Count);

    // Loop for the amount of enemies we want to spawn.
    for (int i = 0; i < spawnAmount; i++)
    {
        // Save a reference to the enemy we spawned.
        instance = Instantiate(list[currentWave].enemies[enemyIndex].gameObject);

        if (SetEndPoints)
        {
            SetEndPoint(waves[currentWave].enemies[currentEnemy].gameObject,
                        instance,
                        presetIndexEndPoint);
        }
    }

    ...
}

public void SetEndPoint(GameObject prefabGameObject, GameObject instanciatedGameObject, int presetIndex)
{
    // Automatic end points currently only work with the supplied SetAgentDestination script.
    instanciatedGameObject.AddComponent(typeof(SetAgentDestination));
    SetAgentDestination sad = instanciatedGameObject.GetComponent<SetAgentDestination>();
    List<Transform> result = endPoints.GetEndPoints(prefabGameObject);

    if (result != null)
        sad.CalculateValidPath(result, presetIndex);
}

Structs

SinglePoint

[System.Serializable]
public struct SinglePoint
{
    [HideInInspector] public string name;
    public Transform endPoint;
    public List<GameObject> enemies;
}

EndPoints is a list of the SinglePoint struct. This struct contains the actual end point and enemies that are allowed to go to this point. When editing the EndPoints list you will have to make use of this struct as well.

Examples:

Remove item

EndPoint ep = GetComponent<EndPoint>();
ep.EndPoints.RemoveAt(3);

Add item

public Transform myPoint;
public List<GameObject> myEnemies;
EndPoint ep = GetComponent<EndPoint>();

ep.EndPoints.Add(new EndPoint.SinglePoint
{
    // name is automatically set by the Unity validation method.
    name = "",
    endPoint = myPoint,
    enemies = myEnemies
});

Set list

public Transform myPoint1, myPoint2, myPoint3;
public List<GameObject> myEnemies1, myEnemies2, myEnemies3;
EndPoint ep = GetComponent<EndPoint>();

ep.EndPoints = new List<EndPoint.SinglePoint>
{
    new EndPoint.SinglePoint
    {
        name = "",
        endPoint = myPoint1,
        enemies = myEnemies1
    },
    new EndPoint.SinglePoint
    {
        name = "",
        endPoint = myPoint2,
        enemies = myEnemies2
    },
    new EndPoint.SinglePoint
    {
        name = "",
        endPoint = myPoint3,
        enemies = myEnemies3
    }
};
⚠️ **GitHub.com Fallback** ⚠️