/// <summary> /// Adds a monster GO to the enemy canvas, initializing its values and setting navigation /// </summary> /// <param name="monsterName"> Name of the monster to be fetched from the DB </param> /// <remark> Assumes there will always be an action at button 0 </remark> private IEnumerator AddMonster(string monsterName) { GameObject newMonster = Instantiate(DataManager.instance.GetLoadedMonster(monsterName)); newMonster.SetActive(true); Monster monsterComponent = newMonster.GetComponent <Monster>(); SelectMonsterDelegate smd = new SelectMonsterDelegate(SelectMonster); monsterComponent.ID = countID++; monsterComponent.SetHealthBar(); monsterComponent.AddSMDListener(smd); monsterComponent.SetNavigation("down", actionsPanel.GetActionButton(0)); newMonster.transform.SetParent(enemyCanvas.transform, false); monsters.Add(monsterComponent); yield break; }
/// <summary> /// Set button's onClick function to the passed in function. /// Also gets external component references (such as the eventDescription) /// </summary> /// <param name="smd"> Delegate function only takes in a monster as a parameter </param> /// <remark> /// When a monster is instantiated, it does not contain the logic or info that the combatManager /// uses to determine if its being attacked.false By passing it an onClick from the combatManager, /// its functionality can be simplified. /// </remark> public void AddSMDListener(SelectMonsterDelegate smd) { b.onClick.AddListener(() => smd(displayedMonster)); eventDescription = EventManager.instance.eventDescription; }
/// <summary> /// Set button's onClick function to the passed in function /// </summary> /// <param name="smd"> Delegate function only takes in a monster as a parameter </param> /// <remark> /// When a monster is instantiated, it does not contain the logic or info that the combatManager /// uses to determine if its being attacked.false By passing it an onClick from the combatManager, /// its functionality can be simplified. /// </remark> public void AddSMDListener(SelectMonsterDelegate smd) { b.onClick.AddListener(() => smd(this)); }