コード例 #1
0
 // Called when script is destroyed
 void OnDestroy()
 {
     if (userKeyboardControls == this)
     {
         // when destroyed remove static reference to itself
         userKeyboardControls = null;
     }
 }
コード例 #2
0
 // When object is created
 void Awake()
 {
     // Check if an eventController already exists
     if (userKeyboardControls == null)
     {
         // If not set the static reference to this object
         userKeyboardControls = this;
     }
     else if (userKeyboardControls != this)
     {
         // Else a different eventController already exists destroy this object
         Destroy(gameObject);
     }
 }
コード例 #3
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_);
        }
    }