Hello,
as title said , I'm trying to show alert as in example, when quest started (data for Alert stored in Quest asset) but from code.
ShowAlert method have 3 overloads, I saw that when I'm use method with only string parameter code flow bypassing instatiation of Container Template, which messing with my UI design. I was trying using ShowAlert(string questID, List<QuestContent>) but all data nescesary should be Scriptable Object, tryied to ScriptableObject.CreateInstance<HeadingTextQuestContent>() but it's null.
So there is my question, is there any way to use your already written code to show alert from my own code like Quest does or I have to write my own solution?
Showing Alert with Header and Body text from code.
Re: Showing Alert with Header and Body text from code.
Hi,
Here are two ways to do that:
1. Make a subclass of UnityUIQuestAlertUI. Add your own method to show header and body text. Here's a rough example. I just typed it in here, so it might have typos.
2. Or create ScriptableObjects and pass them to ShowAlert(). Make sure to destroy them after calling ShowAlert().
Here are two ways to do that:
1. Make a subclass of UnityUIQuestAlertUI. Add your own method to show header and body text. Here's a rough example. I just typed it in here, so it might have typos.
Spoiler
Code: Select all
public class MyAlertUI : UnityUIQuestAlertUI
{
public void ShowAlert(string header, string body, float duration)
{
var container = Instantiate<UnityUIContainerTemplate>(alertContainerTemplate);
contentManager.Add(container, currentContentContainer);
var mainContentManager = contentManager; // Add sub-contents to sub-container, not main content manager
contentManager = new UnityUIInstancedContentManager();
// Add header:
var instance = Instantiate<UnityUITextTemplate>(GetHeadingTemplate(headingContent.headingLevel));
currentContentManager.Add(instance, currentContentContainer);
instance.Assign(header);
container.AddInstanceToContainer(contentManager.GetLastAdded());
// Add body:
var instance = Instantiate<UnityUITextTemplate>(currentBodyTemplate);
currentContentManager.Add(instance, currentContentContainer);
instance.Assign(bodyContent.runtimeText);
container.AddInstanceToContainer(contentManager.GetLastAdded());
contentManager = mainContentManager;
StartCoroutine(TimedDespawn(container, duration));
}
}
Re: Showing Alert with Header and Body text from code.
I've tried your second solution with scriptable objects and it works perfectly.
Thank you for your fast response, you are the best.
Thank you for your fast response, you are the best.
Re: Showing Alert with Header and Body text from code.
Glad to help!