1 / 6

Managing the Inventory

Managing the Inventory. Chapter 14. Inventory Panel. #pragma strict internal var controlCenter : GameObject ; internal var defaultCursor : Texture; internal var currentCursor : Texture; function Start () { controlCenter = GameObject.Find ("Control Center");

kolina
Download Presentation

Managing the Inventory

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. Managing the Inventory Chapter 14

  2. Inventory Panel #pragma strict internal varcontrolCenter : GameObject; internal vardefaultCursor : Texture; internal varcurrentCursor : Texture; function Start () { controlCenter = GameObject.Find("Control Center"); defaultCursor = controlCenter.GetComponent(GameManager). defaultCursor; } function OnMouseDown () { // check the current cursor against the default cursor currentCursor = controlCenter.GetComponent(GameManager). currentCursor; if (currentCursor == defaultCursor) return; // take no action—it was the default cursor else { // there is an action icon as cursor, so process it // use the cursor texture's name to find the GUI Texture object of the same name varaddObject = GameObject.Find(currentCursor.name); // update the icon's current state to in inventory, 1, in the Interactor script addObject.GetComponent(Interactor).currentState = 1; //after you store the cursor's texture, reset the cursor to default controlCenter.SendMessage("ResetCursor"); // and add the new object to inventory controlCenter.SendMessage("AddToInventory", addObject); } }

  3. Inventory Screen #pragma strict function Start () { // set the GUI Texture to match the screen size on startup guiTexture.pixelInset = Rect (0, 0, Screen.width, Screen.height); } function OnMouseDown () { yield new WaitForSeconds(0.25); // allow time for mouse down evaluation before toggling mode GameObject.Find("Camera Inventory").SendMessage("ToggleMode"); }

  4. Extending the Inventory Size • See Click Arrows script

  5. Combination Objects • The next case is what happens when a non-default cursor is used to pick an inventory object. If the two objects can be combined, both the cursor and the inventory object go out of scene, and the combination object goes into inventory.

  6. Summary In this chapter, you implemented the functionality for the inventory system. Starting with a grid system for the layout, you used GUI Texture objects for the inventory icons. With the use of tags, you were able to access all of the objects tagged as InventoryObjects and iterate through them to load the active objects into an array. Using a bit of math, you were able to design an extensible system to allow any number of inventory items past the visible nine displayed on the panel texture. Using arrows to navigate the inventory grid, you were able to determine visibility, according to the grid’s position and the current number of items in inventory. After you got the grid working, you considered the possibilities for interaction with non-default cursors. You were able to see how the metadata system allows you to combine two cursors in inventory to create a new combination object. Continuing with non-default cursors, you decided to have a pick using a “wrong” cursor pick up the inventory object and drop the current cursor object into inventory in its place. Being able to dynamically add and remove objects from inventory, you then implemented “custom” generic replies for wrong picks in inventory that differed from the reply for wrong picks in the 3D scene. By stretching a small semitransparent texture across the screen, you gave the player a view of the 3D world in action, while accessing inventory that also provided a means of intercepting picks outside the inventory panel. And, finally, you adjusted the cursor size to give a better view of the inventory items when they were used as the current cursor. In the next chapter, you will deal with object visibility using tags, refine object interaction, and experiment with random replies.

More Related