コード例 #1
0
ファイル: Game.cs プロジェクト: Victorma/arbustos-go
 //#################################################################
 //#################################################################
 //#################################################################
 #region Misc
 public void ActionCanceled()
 {
     if (isSomethingRunning())
     {
         this.actionCanceled = true;
         Delegate[] delegateList = OnActionCanceled.GetInvocationList();
         for (int counter = delegateList.Length - 1; counter >= 0; counter--)
         {
             ((ActionCanceledDelegate)delegateList[counter])();
         }
     }
     OnActionCanceled = null;
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: Victorma/arbustos-go
        public bool Execute(Interactuable interactuable, ExecutionEvent callback = null)
        {
            // In case any menu is shown, we hide it
            if (MenuMB.Instance)
            {
                MenuMB.Instance.hide(true);
            }

            if (executeStack.Count == 0)
            {
                AutoSave();
            }

            // Then we execute anything
            if (executeStack.Count == 0 || executeStack.Peek().Key != interactuable)
            {
                Debug.Log("Pushed " + interactuable.ToString());
                executeStack.Push(new KeyValuePair <Interactuable, ExecutionEvent>(interactuable, callback));
            }
            while (executeStack.Count > 0)
            {
                var preInteractSize = executeStack.Count;
                var toExecute       = executeStack.Peek();
                var requiresMore    = false;

                try
                {
                    requiresMore = toExecute.Key.Interacted() == InteractuableResult.REQUIRES_MORE_INTERACTION;
                }
                catch (System.Exception ex)
                {
                    Debug.LogError("Interacted execution exception: " + ex.Message + ex.StackTrace);
                }

                if (requiresMore && !actionCanceled)
                {
                    uAdventureRaycaster.Instance.Override = this.gameObject;
                    return(true);
                }
                else
                {
                    Debug.Log("Execution finished " + toExecute.ToString());
                    if (!actionCanceled)
                    {
                        if (preInteractSize != executeStack.Count)
                        {
                            Debug.Log("The size was different");
                            var backupStack = new Stack <KeyValuePair <Interactuable, ExecutionEvent> >();
                            // We backup the new stacked things
                            while (executeStack.Count > preInteractSize)
                            {
                                backupStack.Push(executeStack.Pop());
                            }
                            // Then we remove our entry
                            executeStack.Pop();
                            // Then we reinsert the backuped stuff
                            while (backupStack.Count > 0)
                            {
                                executeStack.Push(backupStack.Pop());
                            }
                        }
                        else
                        {
                            executeStack.Pop();
                        }
                    }

                    try
                    {
                        if (actionCanceled)
                        {
                            while (executeStack.Count > 0)
                            {
                                var removed = executeStack.Pop();
                                if (removed.Value != null)
                                {
                                    removed.Value(removed.Key);
                                }
                            }
                        }
                        else if (toExecute.Value != null)
                        {
                            toExecute.Value(toExecute.Key);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.Log("Execution OnFinished execution exception: " + ex.Message);
                        if (actionCanceled)
                        {
                            executeStack.Clear();
                        }
                    }
                }
            }
            if (uAdventureRaycaster.Instance)
            {
                uAdventureRaycaster.Instance.Override = null;
            }
            if (executeStack.Count == 0)
            {
                if (GameState.ChangeAmbitCount > 0)
                {
                    Debug.LogWarning("There are still some opened change ambits! " + GameState.ChangeAmbitCount);
                }
                OnActionCanceled = null;
                AutoSave();
            }
            // In case any bubble is bugged
            GUIManager.Instance.DestroyBubbles();
            actionCanceled = false;
            return(false);
        }