Creating a new Win Condition

To create a new win condition, create a new class and derive it from the WinCondition.

There is an abstract method, bool IsGameEnded(IReadOnlyList<Player> playersIngame, out int winnerTeam), which you need to override with your own. It receives the list of players currently in the match, and should return true if one of them (or their team) wins. It should also fill the winnerTeam variable, so the asset knows which team won.

Don’t forget to add CreateAssetMenu, since this is a Scriptable Object and you will need a way to create an asset of your WinCondition type.

Final code can look like this (the actual built-in Collect Resources Amount condition, as an example):

using System.Collections.Generic;
using InsaneSystems.RTSKit.Core;
using UnityEngine;

namespace InsaneSystems.RTSKit.Data
{
  [CreateAssetMenu(fileName = "CollectResourcesAmount", menuName = Globals.AssetName + "/Win Conditions/Collect Resources Amount")]
  public sealed class CollectResourcesAmount : WinCondition
  {
    [Tooltip("At least 1 resource should always be in this list for the condition to work properly.")]
    public ResourceDatasDictionary NeededResources = new ();

    [Tooltip("Enable this if the AI player should not win upon collecting this amount of money.")]
    public bool OnlyForNonAIPlayers = true;

    public override bool IsGameEnded(IReadOnlyList<Player> playersIngame, out int winnerTeam)
    {
      foreach (var player in playersIngame)
      {
        if (OnlyForNonAIPlayers && player.IsAIPlayer)
          continue;

        foreach (var kvp in NeededResources)
        {
          if (player.HasResource(kvp.Key.GetResourceId(), kvp.Value))
          {
            winnerTeam = player.TeamIndex;
            return true;
          }
        }
      }

      winnerTeam = -1;
      return false;
    }
  }
}

You can add any parameters, and they will be shown in the asset of your win condition.