/// <summary> /// Creates an instance of <see cref="KillButtonManager"/> when one does not exist. /// </summary> private void CreateButton() { if (KillButtonManager != null || !HudManager.Instance?.KillButton || ImageData == null) { return; } KillButtonManager = Object.Instantiate(HudManager.Instance.KillButton, HudManager.Instance.transform); KillButtonManager.gameObject.SetActive(HudVisible && Visible); KillButtonManager.renderer.enabled = HudVisible && Visible; Texture2D tex = GUIExtensions.CreateEmptyTexture(); ImageConversion.LoadImage(tex, ImageData, false); KillButtonManager.renderer.sprite = ButtonSprite = tex.CreateSprite(); PassiveButton button = KillButtonManager.GetComponent <PassiveButton>(); button.OnClick.RemoveAllListeners(); button.OnClick.AddListener(new Action(() => { if (!IsUsable) { return; } CancelEventArgs args = new CancelEventArgs(); OnClick?.SafeInvoke(this, args, nameof(OnClick)); if (args.Cancel) { return; // Click was cancelled. } if (HasEffect) { StartEffect(); return; } ApplyCooldown(); })); }