コード例 #1
0
    private void HideInternal(string name, DialogTransitionDelegate onComplete, bool Remove)
    {
        //Debug.Log("==>  Hide" + name + "  " + Time.time);
        if (!_dialogs.ContainsKey(name) || !_canvases[_dialogs[name]].Dialogs.ContainsKey(name))
        {
            HandleHideFail(name, onComplete);
            return;
        }

        DialogController dc = null;

        _canvases[_dialogs[name]].Dialogs.TryGetValue(name, out dc);
        if (dc == null)
        {
            HandleHideFail(name, onComplete);
            return;
        }

        if (dc.IsEntering)        // If in the process of entering, Hide when done.
        {
            Debug.LogWarning("Cannot hide " + name + " yet, Entered() has not been called!");
            dc.EnterCompleteActions.Add((bool s) =>
            {
                dc.IsEntering = false;
                Hide(name, onComplete);
            });
            return;
        }
        if (dc.IsExiting)
        {
            Debug.LogWarning("Dialog " + name + " is already exiting");
            dc.ExitCompleteActions.Add(onComplete);
            return;
        }
        if (dc.IsExited)
        {
            Debug.Log("Dialog " + name + " is already inactive");
            if (Remove)
            {
                dc.Terminate();
            }
            if (onComplete != null)
            {
                onComplete(false);
            }
            return;
        }

        if (Remove)
        {
            //Managers.AssetBundleHelperManager.UnloadAssetFromMap<GameObject>(name);
            _loadedDialogs.Remove(name);
        }

        dc.ExitCompleteActions.Add(onComplete);
        dc.BaseExit(Remove);
    }
コード例 #2
0
 private void HandleHideFail(string name, DialogTransitionDelegate onComplete)
 {
     Debug.LogWarning("The Dialog" + name + " does not exist.");
     RemoveFromActive(name);
     if (onComplete != null)
     {
         onComplete(false);
     }
 }
コード例 #3
0
    public void Remove(string name, DialogTransitionDelegate onComplete = null)
    {
        if (!_loadedDialogs.ContainsKey(name))
        {
            Debug.LogWarning("The Dialog " + name + " has yet to be loaded.");
            if (onComplete != null)
            {
                onComplete(true);
            }
            return;
        }

        HideInternal(name, onComplete, true);
    }
コード例 #4
0
    public void Hide(string name, DialogTransitionDelegate onComplete = null)
    {
        if (!_dialogs.ContainsKey(name))
        {
            Debug.LogWarning("The Dialog " + name + " is not currently active.");
            if (onComplete != null)
            {
                onComplete(true);
            }
            return;
        }

        HideInternal(name, onComplete, false);
    }
コード例 #5
0
    public IEnumerator ShowAsync <T>(string name, string canvas = "", Action <T> setup = null, DialogTransitionDelegate onEntered = null, Action <T> onLoaded = null) where T : DialogController
    {
        // Shows the specified dialog. before the dialog runs its enter function, the Setup function will be called, allowing for unique situational setup.
        // if the specified dialog does not exist, this will return null.

        //float startTime = Time.time;
        //Debug.Log("==> " + name + " START - <" + startTime + " , " + Time.realtimeSinceStartup + ">");

        // Check to see if this dialog needs to be loaded from Resources.
        T dialog = null;

        if (!_loadedDialogs.ContainsKey(name))
        {
            bool wasLoaded = false;
            //yield return StartCoroutine(Managers.AssetBundleHelperManager.LoadAssetAsyncFromMap<GameObject>(name, false, result =>
            yield return(StartCoroutine(LoadAsset(name, result =>
            {
                if (result != null)
                {
                    wasLoaded = true;
                    _loadedDialogs.Add(result.name, result);
                }
            })));

            // We need to load dialog first
            if (!wasLoaded)
            {
                Debug.LogError("Could not Load Dialog: " + name);
                if (onEntered != null)
                {
                    onEntered(false);
                }
                yield break;
            }
        }
        dialog = _loadedDialogs[name].GetComponent <T>();
        if (dialog == null)
        {
            Debug.LogError("The Dialog " + name + " does not have a DialogController Component. Type" + _loadedDialogs[name].GetType().ToString());
            onEntered(false);
            yield break;
        }

        // Show the specified dialog by name. This returns the specified dialog controller type.
        if (string.IsNullOrEmpty(canvas))
        {
            // Assign to the default canvas unless this dialog already exists.
            canvas = CanvasTags[0];
            if (_canvases.ContainsKey(name))
            {
                canvas = _dialogs[name];
            }
        }

        // Run the special initialization on the dialog. Then Initialize.
        T t = ShowInternal <T>(name, canvas, onEntered, setup);

        //Debug.Log("==> " + name + " END - <" + Time.time + " , " + (Time.time - startTime) + " , " + Time.realtimeSinceStartup + ">");

        if (onLoaded != null)
        {
            onLoaded(t);
        }
    }
コード例 #6
0
    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);
    }