protected BattleUIAgent[] LinkAgents(BattleUIAgent[] agents, bool callAgentDelinkerOnDelink)
        {
            for (int i = 0; i < agents.Length; i++)
            {
                BattleUIAgent agent = agents[i];

                if (agent.IsInvoking("DestroyAgent"))
                {
                    agent.CancelInvoke("DestroyAgent");
                    agent.Delinker += () => { agent.Invoke("DestroyAgent", 12.0f); };
                }

                agent.PerformLinkageOperations(); //Inform the agent that he is being linked

                Action agentDelinkingSubscription = () => { };
                Action agentDelinkingUnsubscriber = () => { Delinker -= agentDelinkingSubscription; };

                if (callAgentDelinkerOnDelink)
                {
                    agentDelinkingSubscription += () => { agent.Delinker(); }
                }
                ;
                else
                {
                    Delinker += () => { agent.Delinker -= agentDelinkingUnsubscriber; }
                };

                agent.Delinker += agentDelinkingUnsubscriber; //Add the following to the its delinker - 1. Delink the agent's delinker from the delinker of the agent linking it 2. Reset the agent's delinker 3. Reset the agent
                Delinker       += agentDelinkingSubscription;
            }

            return(agents);
        }
        protected BattleUIAgent[] CreateAndLinkAgents <T>(string nameFilter, int limit)
        {
            GameObject           battleAgentPrefab = RetrieveDynamicAgentPrefab <T>(nameFilter).gameObject; //Find the object to create
            List <BattleUIAgent> createdAgents     = new List <BattleUIAgent>();

            for (int i = 0; i < limit; i++)
            {
                BattleUIAgent instantiatedAgent = Instantiate(battleAgentPrefab).GetComponent <BattleUIAgent>(); //Create the object
                instantiatedAgent.Delinker += () => { instantiatedAgent.Invoke("DestroyAgent", 3.0f); };         //Make its delinker destroy the object
                createdAgents.Add(instantiatedAgent);
            }

            return(LinkAgents(createdAgents.ToArray(), true));
        }
 protected BattleUIAgent LinkAgent(BattleUIAgent agent, bool callAgentDelinkerOnDelink)
 {
     return(LinkAgents(new BattleUIAgent[] { agent }, callAgentDelinkerOnDelink)[0]);
 }