forked from Shardstone/trail-into-darkness
added a disfunctionalk popup system
This commit is contained in:
@@ -9,11 +9,13 @@ namespace Jovian.PopupSystem {
|
||||
readonly PopupSettings settings;
|
||||
readonly PopupReference viewPrefab;
|
||||
readonly Func<IPopupAnimator> animatorFactory;
|
||||
readonly Transform canvasParent;
|
||||
readonly Dictionary<PopupCategory, ViewState> categories = new();
|
||||
|
||||
public PopupSystem(PopupSettings settings, PopupReference viewPrefab, Func<IPopupAnimator> animatorFactory = null) {
|
||||
public PopupSystem(PopupSettings settings, PopupReference viewPrefab, Transform canvasParent = null, Func<IPopupAnimator> animatorFactory = null) {
|
||||
this.settings = settings;
|
||||
this.viewPrefab = viewPrefab;
|
||||
this.canvasParent = canvasParent;
|
||||
this.animatorFactory = animatorFactory ?? (() => new FadePopupAnimator());
|
||||
}
|
||||
|
||||
@@ -110,6 +112,13 @@ namespace Jovian.PopupSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeTriggersInChildren(Transform parent, Action<PopupTrigger> configureTrigger) {
|
||||
var triggers = parent.GetComponentsInChildren<PopupTrigger>(true);
|
||||
foreach(var trigger in triggers) {
|
||||
configureTrigger(trigger);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
foreach(var kvp in categories) {
|
||||
if(kvp.Value.view != null) {
|
||||
@@ -148,14 +157,24 @@ namespace Jovian.PopupSystem {
|
||||
if(state.view != null) {
|
||||
return;
|
||||
}
|
||||
state.view = Object.Instantiate(viewPrefab);
|
||||
state.view.SetVisible(false);
|
||||
state.view.SetMaxWidth(settings.maxPopupWidth);
|
||||
|
||||
if(canvasParent != null) {
|
||||
// Parent under existing scene Canvas — nested Canvas inherits CanvasScaler
|
||||
state.view = Object.Instantiate(viewPrefab, canvasParent);
|
||||
}
|
||||
else {
|
||||
state.view = Object.Instantiate(viewPrefab);
|
||||
}
|
||||
|
||||
// Configure Canvas as override sorting so it renders on top
|
||||
var canvas = state.view.GetComponent<Canvas>();
|
||||
if(canvas != null) {
|
||||
canvas.overrideSorting = true;
|
||||
canvas.sortingOrder = settings.sortingOrder;
|
||||
}
|
||||
|
||||
state.view.SetVisible(false);
|
||||
state.view.SetMaxWidth(settings.maxPopupWidth);
|
||||
}
|
||||
|
||||
private void DismissLowerPriority(int showingPriority) {
|
||||
|
||||
Reference in New Issue
Block a user