示例#1
0
    // Creates buttons for event display
    private void CreateButtons(EventDisplayData displayData)
    {
        // Destroy previous buttons
        //DestroyButtons();

        // If there are buttons to create
        if (displayData.btnFunctions_.Length > 0)
        {
            // Loop for each button to create
            for (int i = 0; i < displayData.btnFunctions_.Length; i++)
            {
                /*
                 * // Create new button
                 * GameObject newButton = (GameObject)Instantiate(prefabButton);
                 *
                 * // Get button's transform componenet
                 * RectTransform btnTransform = newButton.GetComponent<RectTransform>();
                 *
                 * // Setup button's transform position/size/anchor/etc...
                 * btnTransform.SetParent(GetComponent<RectTransform>(), false);
                 * btnTransform.localScale = new Vector3(1, 1, 1);
                 * btnTransform.sizeDelta = new Vector2(btnSizeX / displayData.btnFunctions_.Length, btnSizeY);
                 * btnTransform.anchorMax = new Vector2(0, 1);
                 * btnTransform.anchorMin = new Vector2(0, 1);
                 * btnTransform.pivot = new Vector2(0, 1);
                 * btnTransform.anchoredPosition = new Vector3(btnPosX + i * btnTransform.sizeDelta.x, btnPosY, 0);
                 */
                // Set button text

                if (i < 2)
                {
                    if (i < displayData.btnText_.Length)
                    {
                        buttons_[i].GetComponentInChildren <Text>().text = displayData.btnText_[i];
                    }
                    else
                    {
                        buttons_[i].GetComponentInChildren <Text>().text = "option " + (i + 1);
                    }
                    // Create method for button OnClick from function pointer in display data
                    buttons_[i].GetComponent <Button>().onClick.RemoveAllListeners();
                    int       tempInt       = i;
                    ButtonDel tempButtonDel = displayData.btnFunctions_[i];
                    buttons_[i].GetComponent <Button>().onClick.AddListener(() => tempButtonDel(tempInt));

                    // Add new button to button list
                    //buttons_.Add(newButton.GetComponent<Button>());
                }
            }
        }
    }
示例#2
0
    // Called at start of action
    public override void Begin(NarrativeEvent newEvent)
    {
        // Call Base Begin Method
        base.Begin(newEvent);

        // Set action type
        type_ = ACTIONTYPE.DECISION;

        //get the world manager
        worldController  = Terrain.activeTerrain.GetComponent <WorldManager>(); //get script
        keyboardControls = UserKeyboardControls.userKeyboardControls;

        // Create references to eventDisplay and resourceManager
        eventDisplay    = EventDisplay.eventDisplay;
        eventController = EventController.eventController;

        // Start decision timer
        decisionTimer_ = new Timer();
        SetDisplayTimer(mainDisplay_.timerLength_);

        // If there are decisions
        if (decisionEffect_.Length > 0)
        {
            // Create btnFunction list
            mainDisplay_.btnFunctions_ = new ButtonDel[decisionEffect_.Length];

            // For each button
            for (int i = 0; i < mainDisplay_.btnFunctions_.Length; i++)
            {
                // Create all effects when button is pressed

                // Add update star method
                mainDisplay_.btnFunctions_[i] += UpdateStars;


                // If there's an event to add
                if (decisionEffect_[i].addEvent_)
                {
                    // Add the AddEventToPool method
                    mainDisplay_.btnFunctions_[i] += AddEventToPool;
                }

                // If there's sound to play
                if (decisionEffect_[i].playSound_)
                {
                    // Add play sound method
                    mainDisplay_.btnFunctions_[i] += PlaySound;
                }

                // if decision has a list of extra actions
                if (decisionEffect_[i].effects_.Count > 0)
                {
                    // Add StartActionList method
                    mainDisplay_.btnFunctions_[i] += StartActionList;
                }

                // Add Exit Decision Method
                mainDisplay_.btnFunctions_[i] += ExitDecision;
            }
        }
        else
        {
            // Else no decisions, set button function to ContinuePressed()
            mainDisplay_.btnFunctions_ = new ButtonDel[1] {
                ExitDecision
            };
        }


        // Set up effect when timer runs out
        timerFinished = UpdateStars;

        if (timerRanOutEffect_.addEvent_)
        {
            timerFinished += AddEventToPool;
        }

        if (timerRanOutEffect_.playSound_)
        {
            timerFinished += PlaySound;
        }

        if (timerRanOutEffect_.effects_.Count > 0)
        {
            timerFinished += StartActionList;
        }
        else
        {
            timerFinished += ExitDecision;
        }



        // Make event display active
        eventDisplay.gameObject.SetActive(true);

        // Display main
        eventDisplay.Display(mainDisplay_, decisionTimer_);

        if (keyboardControls)
        {
            keyboardControls.SetButtons(mainDisplay_.btnFunctions_);
        }
    }