1 / 11

Exploring Transitions

Exploring Transitions. Chapter 10. Processing Auxiliary Objects. function ProcessObject ( newState : int ) { processing = true; // turn on flag to block picks // tell the GameManager to suppress the cursor controlCenter.GetComponent ( GameManager ). suppressPointer = true;

tadeo
Download Presentation

Exploring Transitions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Exploring Transitions Chapter 10

  2. Processing Auxiliary Objects function ProcessObject (newState : int) { processing = true; // turn on flag to block picks // tell the GameManager to suppress the cursor controlCenter.GetComponent(GameManager).suppressPointer = true; // start timer pickTimerTime = Time.time + 0.5; // set the timer to go for 0.5 seconds pickTimer = true; // turn on the flag to check the timer currentState = newState; // update the object's current state // update more of the data with the new state currentObjectName = objectName[currentState]; currentObjectDescription = description[currentState]; currentLocation = location[currentState]; currentVisibility = visibility[currentState]; // assign the current clip and delay and audio for the new state if (animates) currentAnimationClip = animationClip[currentState]; if (animates) currentAnimationDelay = animationDelay[currentState]; // if there is a clip, add its length and delay together if(currentAnimationClip) aniLength = currentAnimationClip.length + currentAnimationDelay; else aniLength = 0.0; // there is no animation for this state currentSound = soundClip[currentState]; currentAudioDelay = audioDelay[currentState]; // send it off for handling in case it has a visibility state that is processed at the start HandleVisibility(); // block player input while action plays out if (aniLength != 0.0) {gameObject.Find("First Person Controller"). SendMessage("ManageInput",aniLength); } if(animates && animationClip[currentState] != null) { // find out if a alternate animation object was assigned, if not, assign the object itself if (aniObject == null) aniObject = gameObject; //pause before playing the animation yield new WaitForSeconds(currentAnimationDelay); // play the animation aniObject.animation.Play(currentAnimationClip.name); ProcessAudio (currentSound); // send audio clip off for processing // wait the length of primary animation clip yield new WaitForSeconds(currentAnimationClip.length); // check for a looping animation to follow the primary animation if(postLoop) { // if postLoop is checked/ true, there is a looping animation to trigger aniObject.animation.Play(loopAnimation[currentState].name); // play the looping animation ProcessAudio (loopSoundFX[currentState]); // send loop audio clip off for processing } processing = false; // turn off flag to block picks } else { ProcessAudio (currentSound); // send loop audio clip off for processing //print (currentSound ); yield new WaitForSeconds(1.0);// give a short pause if there was no animation processing = false; // turn off flag to block picks } }

  3. Handling Object Visibility • If you turn off the renderer then you should turn off the collider also • There are multiple types of renderers that must be dealt with individually • All components of a hierarchical structure must be dealt with individually • You could deactivate the whole object but then it cannot be “found”. • Techniques used is to create an array of gameobjects in the scene

  4. Using Tags • One or more gameObjects can be labeled with a tag function Awake () { Screen.SetResolution (1280, 800, false); //get a list of the gameObjects with the ActionObject tag varaObjects = GameObject.FindGameObjectsWithTag("ActionObject"); // redefine the ActionObject array with the number of elements in the list actionObjects = new GameObject[aObjects.length]; //save the action objects into the array for easy access when deactivated for (vari : int = 0;i < aObjects.length;i++) { actionObjects[i] = aObjects[i]; //print (actionObjects[i].name); } }

  5. Using Tags function CheckForActive (name : String) { // check to see if the object is active before assigning it to auxObject if(gameObject.Find(name)) varauxObject = gameObject.Find(name); else { // if no match was found, it must need to be activated //load the actionObject array from the GameManager script varactionObjects : GameObject[] = controlCenter.GetComponent(GameManager).actionObjects; for (var y : int = 0; y < actionObjects.length; y++) { // iterate through the array if (actionObjects[y].gameObject.name == name) { // if there is a match for the name actionObjects[y].gameObject.SetActive(true); // activate the matched object from the array auxObject = gameObject.Find(name); // assign the newly activated object } // close the if } // close the for loop } // close the else return auxObject; // return the gameObject to where the function was called }

  6. Visibility function HandleVisibility () { switch (currentVisibility) { case 0 : // deactivate at start if(currentLocation == 0 ) { // turn off the timer for the cursor before deactivating the object pickTimerTime = Time.time; // set timer to now to force it to finish yield; // give timer a chance to stop if(currentSound != null) { ProcessAudio (currentSound); // send audio clip off for processing first yield new WaitForSeconds(currentSound.length); // allow time to play the sound clip } gameObject.SetActive(false); // deactivate the object immediately } break; case 1: // currentVisibility is 1, Show at start print ("here at 1"); if (useAlpha) { startColor = alphaColor; // assign the start color endColor = originalColor; // assign the end color ent = 0; // start the fade } break; case 2: // currentVisibility is 2, Show at start, hide at end if (useAlpha) { startColor = alphaColor; // assign the start color endColor = originalColor; // assign the end color ent = 0; // start the fade } // set up for fade out if (aniLength == 0.0) aniLength = 2.0; // at least let it show a couple of seconds before the fade fadeTimerTime = Time.time + aniLength; fadeTimer = true; // turn on the flag to check the timer break; case 3: // currentVisibility is 3, hide at end // set up for fade out if (aniLength == 0.0) aniLength = 2.0; // at least let it show a couple of seconds before the fade fadeTimerTime = Time.time + aniLength; fadeTimer = true; // turn on the flag to check the timer break; } }

  7. Developing Non-Keyframed Fades function Update () { if (pickTimer && Time.time > pickTimerTime) { // if time is up and flag is on... pickTimer = false; // turn off the flag // turn off the flag to suppress the cursor controlCenter.GetComponent(GameManager).suppressPointer = false; } // timer for visibility fades if (fadeTimer && Time.time > fadeTimerTime) { // if time is up and flag is on... fadeTimer = false; // turn off the flag if(!useAlpha) gameObject.SetActive (false); // deactivate the object // set up for the fade out endColor = alphaColor; startColor = originalColor; ent = 0; // start the fade } if(!useAlpha) return; // skip the fade code if it is not being used else { if(fadeIn) { startColor = alphaColor; endColor = originalColor; } if(fadeOut) { endColor = alphaColor; startColor = originalColor; } if (ent < 1) { // calculate the current color using linear interpolation between start & end while it is less than 1 renderer.material.color = Color.Lerp(startColor, endColor, ent); // increase the ent value using the rate ent = ent + Time.deltaTime/fadeTime; //deactivate the object if it is finished fading out if (ent >= 1 && endColor == alphaColor) gameObject.SetActive (false); } //end the if/ent } // end the else }

  8. Handling Special Cases • a0_ will trigger an animation on a nonaction object. • b0_ will change state only on the object. • c0_ will send a message to call a function called “DoCameraMatch” on any script on the specified object. • s0_ will send a message to call a function called “DoTheJob” on any script on the specified object. • p0_ will instantiate a prefab. • See LookupState function in ObjectLookup script

  9. Ensuring Player Focus • See FPAdventurerInputController script

  10. Exploring Lerp • See CameraMatch script • See CameraMatchData script

  11. Summary In this chapter, you added sophistication and flexibility to your state engine. You finished the auxiliary object parsing code by having it call the state processing code on the auxiliary object itself. In doing so, you made it possible to transition any number of action objects into their own unique states with a single pick event. By adding a special cases section to the object lookup, you provided a means of dealing with typical issues, such as two ways to get into or return to the same state, and any specialty cases that may crop up. You also implemented a code-based means of fading action objects in and out of the scene. It made use of the Lerp function, which provided you with a means of smoothly going between a start and end value over a duration that you could also define. With the state transitions working smoothly, you turned your attention to improving the mechanics of the interactions, by refining the cursor functionality. This helped to prevent the player from missing important transitions. Then you took it one step further by repurposing the Lerp functionality and introducing a camera match. This allowed you to make sure the player was in the perfect spot to watch the action play out and also prevent him or her from leaving or looking elsewhere during the action.

More Related