コード例 #1
0
    public override IAction ActionOnEnter(Player obj)
    {
        // Get specific event
        EventAction eventAction = EventListManager.GetInstance().GetAction(obj);

        // Pack UI actions
        ActionList result = new ActionList();

        LambdaCompletableAction action = new LambdaCompletableAction(null);                 // 3

        action.preAction = () => {
            NotifyPlotEnter(obj);

            EventDeck.SetActive(true);                                                      // 1
            // Create Event Card
            GameObject EventCardModel = Instantiate(EventModel);
            // ... with the corresponding event sprite
            SpriteRenderer EventCardRenderer = EventCardModel.GetComponentInChildren <SpriteRenderer>();
            EventCardRenderer.sprite
                = EventListManager.GetInstance().EventSprite[eventAction];
            // When target is reached, show the skip button.
            EventCardRenderer
            .GetComponent <EventCardDraw>()
            .ListenTargetReached(
                new LambdaAction(() =>
            {
                SkipButtonUI skipButtonUI = SkipButtonUI.GetInstance();

                skipButtonUI.MaxTime = 5f;
                skipButtonUI.Enable();
                // When the skip button is clicked, destroy the EventCard
                // and hide the event deck
                // note: skip button UI is disabled on click
                skipButtonUI.ListenClick(
                    new LambdaAction(() =>
                {
                    EventDeck.SetActive(false);                                             // 1
                    Destroy(EventCardModel);
                    // Then FINALLY mark this completable action as complete
                    action.PerformOnComplete();                                             // 3
                }));
            }));
        };

        result.AddBlockingAction(action);
        result.AddNonBlockAction(eventAction);

        /* LOGICAL BUG
         * // TODO
         * result.OnActionComplete = new LambdaAction(() =>
         * {
         *  TurnDirector.Ins.EndOfPhase();
         * });
         * //*/
        NotifyPlotEnter(obj);

        return(result);
    }