Home
Getting Started - Ancient Craft Games
Contents
1. BR SRBPBEBaEaa Y CompleteExample SRMERR ERE View Art i rT E vE Icons Y M Box Collider 2D w mena Edit Collider bag EE gt BigSword Material None Physics Mater gt default armor Is Trigger gt 1 default offhand Used By Effector O gt default weapon Offset gt Dirk x0 Yo gt Helmet Goa Shield xis S lt try iio gt Sword trashcan i gt Ge UI YC PGI Slot Item Inv Width Inv Height 3 Icon Sword Events Script 2 El Console Clear Collapse Clear on Play Error Pause For now you can ignore the StackID MaxStack and StackCount values They obviously pertain to stacking items You can learn more about stacking in the Manual 7 At this point we have a valid item to place in our inventory all you need is a GameObject with a PG SlotItem attached really You can test it by turning on the auto detect flag of the model running the scene and then dragging your item to make it a child of the model But obviously we still don t have a way of actually getting it into our system from a player s standpoint Next you ll create a simple script to do just that by allowing you to click on the item sitting in the middle of the scene First create a new Script and entitle it MyPickup and then open it up in your favorite code editor At the top of the behaviour add the RequireComponent attributes for PG SlotItem just
2. them Next drag a sprite into the Sprite Renderer would recommend using the sword sprite found under Example CompleteExample Art Icons Resize the sword image so that it fits nicely in your scene somewhere Next resize the box collider so that it is as large as the sprite s bounding area and check the Is Trigger box This collider will be used to detect mouse clicks later Finally add a PGI Slot Item component to it Leave the icon asset type as Sprite and drag the Same image you used for the sprite into the Icon field of the Slot Item Take note this icon represents what the item looks like inside of the inventory but it does not have to correspond to what the item looks like in the game world We are just using the same image here for clarity At this time you can also set the width and height of the item in slot cells when Stored in the grid I would recommend a width of 2 and a height of 3 When this is all done your scene should look something like this z Project Create Q Hierarchy Inspector L Create 7 All M Sword E Static v Tag Untagged Layer Default vA Transform Position xX 2 18 Y 2 09 Z 0 Rotation XO yio jzfo Scale X 0 3242C Y 0 32420 Z 0 3242C YE Plugins Y6 Power Grid Inventory gt E Assets gt Ge Editor YE Example Main Camera Inventory gt Canvas EventSystem
3. Inv Width 3 default weapon Inv Height 3 gt Dirk Icon 4 BigSword o gt E Helmet b Even i gt Shield ZENI gt Sword YC My Pickup Script ka gt trashcan Script MyPickup a UI Default Inventory Inventory PGIMo gt E Prefabs a A Scripts me Add Component 4 Now that we have some different items we need a way to tell them apart Create a new script and call it MyItemType Inside this script all you need to do is declare a public string variable called Type Attach this script to each of the items Set the Type to weapon for the two swords and shield for the shield 5 Create another script called MyItemFilter In this script create a public List lt string gt called AllowedTypes After that define a public method called IsTypeValid with the following signature public void IsTypeValid PGISlotitem item PGIModel model PGISlot slot This method will be hooked to the Can Equip Item event in the slot But in ores for it to work you have to know how it works Any time one of these Can events triggers a method that method can access the PGI Model CanPerformAction flag If this flag is set to false in any of the triggered methods the action will be disallowed These method are called frequently and are used even for highlighting effects so try to keep them somewhat simple 6 In the new filter script you ll want to get the MyltemType component from the PGIItem passed
4. Power Grid Inventory Getting Started Guide Setup To begin using Power Grid Inventory or PGI for short simply locate it in the Unity Asset Store purchase and then download All related files will be found under the Assets Plugins PowerGridInventory directory Simple as that You can take a look at the scene in the examples folder for an idea of how to set things up and what PGI can do Basic Grid Setup This guide will show you how to get a quick and dirty grid based inventory working in a minimalized number of steps Along the way a few basic concepts will be explained as well 1 To begin create a new project and a new scene Add an empty GameObject to the scene and name it Inventory This object will represent the storage object of our inventory data Add a PGI Inventory Model component to this GameObject either through the Component gt Power Grid Inventory menu or through the Add Component button 2 Next add a UI Panel to the scene For ease of editing you may wish to change the newly generated Canvas s rendering mode to Screen Space Camera and attach our default camera to it Next set the Ui Scale Mode to Scale With Screen Size in the Canvas Scaler component of the canvas After that resize your Panel so that it only takes up most of the top half of the camera view This way you ll have pleny of screen space to work with later Your scene should look something like this now Hierarchy S
5. cene or All Main Camera Inventory Y Canvas EventSystem Project a v Create 7 2 P G Plugins gt G UnityvsS 3 Next add another empty GameObject to the scene and make it a child of the UI Panel Name this GameObject Inventory View and attach to it a PGI Inventory View You ll notice that a RectTransform will be added automatically as well This area will represent the space that your grid will fill 4 Now that we have our basic scene set up it s time to explain some of the data in our scene PGI uses a View Model approach to make it easier to add new functionality by developing different kinds of views for example one that uses Game Pads as well as better support for saving loading inventories and networked games For the most part if the model is changed in some way the view should automatically update to represent the new state Let s take a look at the PGIView component we just created Prefabs ee Slot Prefab Dark Slot 5 Drag Icon Prefab Dark Drag Icon I Model w Inventory Model Drag amp Drop Toggles Disable Dragging Disable Dropping Disable World Dropp Grid Behaviour Batch Slots Horizontal Order Left To Right a Vertical Order Top To Bottom Slot Colors Normal Color Te Highlight Color a Socket Valid Color _ ss Invalid Color Eee Blocked Color E F P Events The third element entitles Model should be pretty obvious It is a reference t
6. e item enter the grid as well as change its location in the heirarchy view panel if you left MessWithTransforms on in the inventory model However it probably seems strange that the item still exists in the world as a sprite when it s also in your inentory So what you ll do next is make it disappear when it enters and inventory and make it re appear when it leaves And to do this we ll need to take a look at the triggered events under the foldout tab in your PGISlotItem 11 Click on the Events foldout tab on the Sword s PGI SlotItem component and locate the On Store In Inventory and On Remove From Inventory events These two events correspond to when the item enters and leaves an inventory s storage model For each of these events add a new method to trigger by clicking the little plus sign and dragging the Sword GameObject from the heirarchy panel into the slot Next use the dropdown to locate the GameObject gt SetActive method Check the little box that represents the bool parameter for the event triggered upon leaving the inventory On Store In Inventory PGISlotItem PE Runtime C GameObjectSetActive 4 On Remove From Inventory PGISlotIte Runtime ee GameQbject SetActive aii Next run the game again and try picking up your item by clicking on it It should disappear from the scene view To test if it returns when you drop the item from the inventory simply drag and drop the item anywhere outside of th
7. e main UI panel While this is a little ham handed what you are doing is simply activating and deactivating the gameobject and thus all components like renderers and such when the item moves to and from inventories These events can be found on the items models slots and views in PGI and are an extremely powerful way to customize PGI to meet your needs In fact almost all of the advanced features advertized in PGI aren t even core elements They are simply components with event handlers that are tied to these events So that wraps it up for the basics of PGI Next up you re going to learn about equipment slots Equipment Slots The main difference between equipment slots and the grid you have been using so far refered to as grid slots sometimes is that while the grid is generated for you the equipment slots must be manually placed by hand by dragging prefabs into the scene Another important factor is that while the grid takes item size into account and requires there to be enough empty cells for an item to be placed in it equiment slots do not care about the item s size by default although if you wanted one to I suppose you could make a component do that and wire it to the slot s CanEquipItem event 1 You should start up where you left off in the above tutorial Find the Grid Slot prefab in the Plugins Power Grid Inventory Prefabs folder and make a duplicate of it then move that duplicate to another location in your projec
8. for safety Then add a public variable to our behaviour of the type PG Model and entitle it DefaultInventory This will reference the inventory we want our item to enter when we pick it up Also add a private variable of the type PG SlotItem and name it Item This will reference this object s own PGISlotItem component 8 Next you ll want to add an Awake method in which you ll want to get a reference to our PG SlotItem 9 Create a method called OnMouseDown to detect mouse click and in it call the DefaultInventory Pickup method with the Item reference passed to it Your file should look like this now note that I added BoxCollider2D and SpriteRenderer to the requirements but you don t have to 1 Eusing UnityEngine using System Collections RequireComponent typeof PGISlotItem RequireComponent typeot BoxCollider2D RequireComponent typeot SpriteRenderer PaGlpublic class MyPickup MonoBehaviour i public PGIModel DefaultInventory private PGISlotItem Item void Awake I L Item GetComponent lt PGISlotItem gt void OnMouseDown if DefaultInventory null amp amp Item null DefaultInventory Pickup Item 10 Attach the new script to the sword and drag the Inventory GameObject from the heirarchy into the Default Inventory reference of the script You should now be able to run the scene click on your item and watch it enter the inventory You should see th
9. mping them right back out once we are finished 9 Now locate the trashcan sprite in the examples folder and drag it to the Source Image for the Icon GameObject that is a child of the trashcan This will be the default icon used by the slot when nothing is equipped to it However in this case as soon as we equip anything to it we are going to drop the item at which point the slot will switch back to its default icon automatically 10 Create another script called MyTrashcan and add a method like so ie es as UnityEngine Svetey F Yo jj 1 Col li inv Unequip item An important thing to note here is that we are using the Unequip method rather than the Remove method of the model This will ensure the item is processed properly As well we must manually trigger all events associated with both the unequipping and the removal of the item from the ionventory This is very important because events are not triggered by the model but rather the view However since we are removing the item through code rather than through the use of the view these events never get triggered You can learn more about when and why you should trigger these events in the Manual Update The above step is no longer necessary strickly speaking A convienience method called PGIModel Drop can be used in place of the three methods shown in the example above inv Unequip item TriggerUnequipEvents and item TriggerRemoveEvents Howe
10. o the model we created in Step 1 Drag that GameObject into this slot now to assign it The rest of the elements are explained in the user manual and you can just leave them alone for now Now let s take a look at our model Y C M PGI Model Script Lal s Grid Stats Grid Columns es Grid Rows es Behaviour Auto Detect Items _ Modify Transforms Auto Equip Auto Equip First w Auto Stack Allow Socketing w gt Equipment gt Events 5 Set the Grid Columns to 10 and Grid Rows to 5 Once you assign the model to the view you ll notice that the view begins displaying the grid you defined in the model This grid is scaled to fill out the containing RectTransform Change the view s RectTransform so that its width is 300 and its height is 150 This will make the cells appear square Again the rest of these variables are explained in depth in the user manual and you can just leave them alone for now Congradulations At this point you have a working inventory and grid view up and running You can run your scene to see how it look Obviously however we don t have anything to put in it just yet The next thing we ll need to do is create a few dummy items to test it with 6 Create yet another empty GameObject in the root of our scene and entitile it Sword Add a BoxCollider2D and Sprite Renderer component to it These aren t required for use in PGI but they will let us see and interact with the items so that we can test
11. size of the Equipment array to 1 and drag our new Weapon Slot from the hierarchy into the first element Now run the scene and you will be able to use the equipment slot as part of your inventory Pretty spiffy but let s try something more ambitious Let s make an equipment slot that only accepts a certain kind of item 3 First thing we ll need to do is create different kinds of items So let s duplicate our Sword a few times and then movwe them apart a bit Change the new items names to Shield and Big Sword Next switch the sprite used for the SpriteRenderer and PGISlotItem components in both items I chose to use the Big Sword and Shield sprites in the examples folder Also change the inventory height and width of the items I chose to make the big sword 3x3 and the shield 2x2 Hierarchy Project PP O inspector ff a aS gt V Li a eS ae 7 ppu ae o a Create GrAl Zh 2D 7 Gizmos 7 cr All p ae CU DICIS Si Gp Bis Sword DStatic v Main Camera YE Plugins a Tag Untagged Layer Default l Inventory Y Power Grid Inventory PA Transform 4 gees d es V ei af Sprite Renderer U Signed Vida Example Sprite BigSword O Shield 3 i j v amp CompleteExample Color LC Big Sword 7 Material WSprites Default YE Icons Sorting Layer Default gt a Armor s Se Order in Layer 0 BigSword M Box Collider 2D gt default armor VG PGI Slot Item Script w default offhand
12. t panel This is always a good idea to do so that you don t accidentally make changes to the default prefab Rename this prefab to whatever you like I choose EquipSlot Prefab and then drag it into your scene to make an instance of it In the hiearchy panel make it a child of the UI panel we created in the previous tutorial Make sure the scale is set to 1 in all dimensions and then resize and place to your liking Finally name this GameObject Weapon Slot Your scene should look something like this now Hierarchy Project Inspector Create C _ 4 W Weapon Slot OStatic v _ a 4 bette E Create gt for All A Main Camera YE Plugins Tag Untagged Layer ur 4 pales teu Grid Inventory Prefab Select Revert Apply Y Canvas gt i Assets ab g Y Panel gt Ga Editor vos Rect Transform w gt Inventory View _ _ gt Gal Example EAMA pora Pos Y Adele Zz Weapon Slot z E j Ww Prefabs 90 59 4060 EventSystem h Dragging Icon Width Height Sword gt h Grid Slot s 64 gt Scripts gt Anchors gt E Unityvs Pivot x 0 5 yos iS aai an Pratas Rotation x0 YO zo T tutorial sane X1 Yi Zi v Canvas Renderer w gt M Image Script w Y C M PGI Slot Script Skip Auto Equip Highlight Highlight Image Icon Image Icon Image 0 Events Flcansale W n m Add Component 2 In the Inventory model set the
13. to the method If the component does not exist or its Type value does not exist in the AllowedTypes list set this flag to false and the item will not be allowed to be equipped using UnityEngine using System Collections using System Collections Generic iss MyltemFilter MonoBehayiour ing gt AllowedTypes ic void IsTypeValid PGISlotItem item PGIModel model PGISlot slot if AllowedTypes null amp amp AllowedTypes Count gt typ reed y Item Type gt a E S yp ll amp 8 Fergie ana Contains type Type 7 Attach this script to your equipment slot GameObject and add weapon to the list of allowed types in the inspector Open the list of events in the equipment slot and locate the on On Can Equip Item Drag the Weapon Slot into the event object and select the method MyltemFilter gt IsTypeValid in the dropdown Now run your scene and try to pickup the shield You ll notice that it cannot be equipped to the slot But the other two sowrds can Once again I ll stress the power of using these events And just as one more example you ll learn how to make a trashcan slot 8 Create another Equipment slot just as you did in step 1 and name it Trashcan don t forget to add it to the model s list of quipment slots or it won t do anything Be sure to un check the Skip Auto Equip flag Doing this will ensure the model does not try to auto equip items to this slot and immdiately which will result in du
14. ver I ve left them in as an example of how to manually trigger these events 11 Attach the script to your trashcan GameObject Now locate the On Equip Item event in the trashcan slot and as before rig it up to the MyTrashcan gt TrashItem method And with that I ve covered most of the basics used by Power Grid Inventory Hopefully by now you have learned the basics neccessary for it and maybe along way the have even become a little inspired with tricks and ideas that it can be used to realize Once again I d like to stress the usefulness of the triggered events in the various components as they are the key to all advanced functionality For more examples please have a look at the examples folder that came with PGI and try out the demo scenes they came with I hope this guide has been useful in explaining PGI but if for any reason you are still having trouble or aren t sure how you can implementing a particularly tricky idea please feel free to contact me at pgi support ancientcraftgames com for help 10
Download Pdf Manuals
Related Search
Related Contents
取扱説明書 Mode d`emploi SU Shredder Bedienungsanleitung ペリメーターヒーター - インターセントラル Canon 650D Digital Camera User Manual Copyright © All rights reserved.
Failed to retrieve file