private T ShowInternal <T>(string name, string canvas, DialogTransitionDelegate onComplete, Action <T> setup = null) where T : DialogController { if (_dialogs.ContainsKey(name)) { // This dialog is already active. DialogController dialog = _canvases[_dialogs[name]].Dialogs[name]; if (dialog.IsExiting) { // The dialog is on it's way out. As soon as it has completed exiting, show the dialog. Debug.Log("Cannot show the active dialog " + name + " yet, Exited() has not been called!"); dialog.ExitCompleteActions.Add((bool s) => { dialog.IsExiting = false; ShowInternal <DialogController>(name, canvas, onComplete); }); dialog.ExitActionIsEnter = true; return((T)dialog); } if (dialog.IsEntering) { Debug.Log("This dialog is already on it's way in. Do not need to call Enter again."); dialog.EnterCompleteActions.Add(onComplete); return((T)dialog); } if (dialog.IsEntered) { Debug.Log("This dialog has already entered. Invoking onComplete immediately."); if (onComplete != null) { onComplete(true); } return((T)dialog); } dialog.EnterCompleteActions.Add(onComplete); dialog.BaseEnter(); return((T)_canvases[_dialogs[name]].Dialogs[name]); } // Make sure the canvas target exists. if (!_canvases.ContainsKey(canvas)) { Debug.LogError("There is no canvas: " + canvas + " for this Dialog: " + name); return(null); } // Instantiate the dialog Prefab. GameObject go = GameObject.Instantiate(_loadedDialogs[name]) as GameObject; DialogController dc = go.GetComponent <DialogController>(); if (dc == null) { Debug.LogWarning("The Dialog " + name + " does not have a controller."); return(null); } dc.Name = name; ActivateDialog(canvas, dc); // Do the dialog Setup before initialization. if (setup != null) { setup((T)dc); } // Initialize the dialog and call its Enter Function. dc.Initialize(name); dc.EnterCompleteActions.Add(onComplete); dc.BaseEnter(); return((T)dc); }