Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Power Grid Inventory: Diablo II style inventory

Discussion in 'Assets and Asset Store' started by Sluggy, May 26, 2015.

  1. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960

    UPDATE:

    A new version of Power Grid Inventory is under construction! It is being designed from the ground up in Unity 2022 to take advantage of all the new features Unity has to offer including an updated version of C# and the new GUI system UIToolkit. It also relies more on ScriptableObjects for shared data as well as provides uses both MonoBehaviour and Non-MonoBehaviour data models.

    This is not a commercial project and will not be up for sale. I am simply in need of a system like this for my own personal projects and thought I would share it as I know there are a handful of others dying for such a system. As such I will not be taking feature requests or providing offical support in any way. Exceptions might be made for answering simple questions on use... if I've had enough coffee that morning.

    Odin is absolutely required for this project. I have zero desire to write editors and drawers if I don't have to. Strictly speaking, one could work around it by removing the drawer attributes or by providing their own attribute drawers to mimic behavior.

    You can find the link to the new project repo here


    For historical sake and backwards compatibility I still have the old version here. I HIGHLY recommend you use the version linked above.
    https://github.com/Slugronaut/PGI
     
    Last edited: Mar 12, 2023
    Appokalopps likes this.
  2. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    I came upon this by chance on the Asset Store (sorting by release date) and I'm compelled to say that this asset looks wonderful!

    What caught my eye was...<drum roll>...multi-cell inventory items! I feel like a broken record but NO ONE seems to want to do this yet here it is, practically undiscovered!

    Solid asset James and I wanted to help by giving you a shout out and encourage you to pimp this a bit more! Lets hear more about it! :D

    Cheers

    -Steven
     
  3. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Thank for your words of encouragement! I agree that there is a severe lack of multi-cell inventory system which is exactly why I decided to release it here.

    The other major feature that I feel PGI gives its users is the freedom to move away from any particular game-specific functionality. I'm already finding really neat ways I can use it for puzzles, doors and locks, and crafting stations. I really look forward to seeing what other people might do with it.

    Expect quite a few updates in the future as I plan to adapt it to work better with gamepads and provide more control over rendering the inventory view.

    Peace
    ~James
     
  4. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    You know I should've mentioned that too!

    A great many of the systems aim directly at not only just Fantasy, but World of Warcraft. Every new system that I felt had potential, I would also request that they make it non-game specific.

    That said, are you free to talk about some of the ideas you've had? :D

    Thank you James!

    -Steven
     
  5. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    I certainly can! Although, some of this is theory since I'm working on other parts of the game right now.

    The game being developed is a dungeon crawler of sorts but plays more like a 2D side-scroller. In keeping in fashion with its inspirational source material - Diablo II - I want to add a kind of crafting to the game similar to runes and runewords. The main difference being that instead of socked and socket-able items I want a crafting station with a series of slots. I also want players to be able to 'program' their own bonuses rather than have preset stats applied.

    It works like this: The first slot holds the item to be modified, and each slot after can take an 'enhancement chip'. Each chip provides a certain bonus to the item as well as a 'rule'. For example some chips aren't compatible with others. Some chips can 'loop' a previous slot's chip, etc... When the player places all of the chips they wish to use plus the item into the crafting screen and presses the craft button the 'program' is run and the item is regenerated with the new stats applied... if everything goes well. If any 'rules' are broken then enhancement chips or even the item may be destroyed in the process. As well, each new chip added has a chance to cause a power surge which can also end in disaster.

    The actual UI for all of this can be set up in a matter of minutes, rigged events and everything. The real work will obviously come from programming the interaction of the chip's rules. and how they combine to create new stats.
     
  6. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    So is it rather non-trivial (within your system) to give or derive added functionality to slots/sockets/cells as you describe, programmatically or otherwise, so the inventory knows more explicitly what item is being slotted/socketed/stored?
     
    Last edited: Jun 12, 2015
  7. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Assuming you know at least a little basic programming it is quite trivial in fact!
    Items, Models, Views, and Equipment slots all have a set of triggered events that you can rig up just like any built-in Unity event (like what you see for the new UI system). The real power of PGI comes from this fact and it's what lets it stay out of game-specific territory.

    Capture.PNG

    In fact, many of the nicer features I listed (like item-filtering equipment slots) aren't even core PGI components. They are simple example scripts that can be written in minutes. You can check out more in the documentation files and user manual posted here: http://ancientcraftgames.com/pgi/docs/docs.html
     
  8. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Awesome James!

    Yea I perused the docs after I purchased it, but haven't delved any further into it, yet of course. :D

    This sounds quite light actually. The reason I posed my question as such is many times assets are (needlessly?) complex that one isn't quite sure where to dig in without fear of breaking the asset. I'm a fairly confident programmer for someone who's an animator by day, but not confident enough to muck around in someone else's code, moreso when they're far more advanced than I. :D

    Again thank you for your time answering, and I'm really looking forward to integrating all this.

    Cheers man

    -Steven
     
  9. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    An update has been submitted with a few bug fixes and minor features added.
    • FEATURE: PGIModel can now be set to automatically detect items that were added to, or removed from, its transform hierarchy.
    • FEATURE: Model grid can now change rows and columns at runtime. Items will be dropped from inventory if this happens.
    • FEATURE: Provided a 'PGIModel.Drop()' convenience method that automatically triggers the necessary events for unequipping and removing from inventory.
    • CHANGE: Breaking Change: Moved many files from the 'Examples' folder to the 'Extensions' folder. Also changed some example component names. If you used any of these scripts you may have to relink the files.
    • CHANGE: 'Inventory Item' container extension now uses double-clicks rather than right-clicks to open its PGIView.
    • CHANGE: Updated manuals to reflect new features. Expanded the user manual's explaination of the major components. Shortened the Getting Started guide.
    • CHANGE: Changed e-mail support address that is given in documentation. Now points to pgi-support@ancientcraftgames.com
    • FIX: Normalized input for mouse and touchscreen. They now work identically.
    • FIX: Properly initialized the UnityEvent objects in PGIModel, PGIView, PGISlot, and PGISlotItem so they don't throw null exceptions when added to a GameObject at runtime.
    • FIX: Fixed errors that popped up when a model had no equipment slots but were being queried.
    • FIX: Corrected drop-down menu titles for 'Linked Equip Slot' and 'Simple Pickup'.
    • FIX: Inventory grid will now properly update its view in the editor when its parent's RectTransform is resized.
     
  10. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Version 1.1 is now live with the aforementioned features. Next up on the todo list: Socketed and Socketable items!
     
  11. siblingrivalry

    siblingrivalry

    Joined:
    Nov 25, 2014
    Posts:
    384
    Nice work. Is it using ugui?
     
  12. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Thanks! And yes - It uses Unity's new 4.6 UI system.
     
  13. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Just a heads up. A little bug managed to creep its way into the code with the last release that will not allow PGI projects to be built outside of the editor. I'm not sure when the next version will be out in the asset store so here is a quick hotfix guide.

    In the file PGIModel.cs locate the following reference on line 11 and remove it.
    Code (CSharp):
    1. using UnityEditor.AnimatedValues;
    In the file PGIView.cs around line 310 you'll see four lines of code at the very end of the CreateGrid() method. Surround them with and UNITY_EDITOR conditional compilation so that they look like the following:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. CachedSizeX = Model.GridCellsX;
    3. CachedSizeY = Model.GridCellsY;
    4. CachedRectX = ParentRect.rect.width;
    5. CachedRectY = ParentRect.rect.height;
    6. #endif

    EDIT: There is another small bug that was found in the file PGIModel.cs around line 434. It currently reads:
    Code (CSharp):
    1. foreach (PGISlotItem item in items)
    2. {
    3.     if (item.transform.parent != this.transform) Drop(item);
    4. }
    And it should read:
    Code (CSharp):
    1. if(items != null)
    2. {
    3.     foreach (PGISlotItem item in items)
    4.     {
    5.          if (item.transform.parent != this.transform) Drop(item);
    6.     }
    7. }
    This will be fixed in the next release. Sorry about that.
     
    Last edited: Jul 18, 2015
  14. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    As I type this I'm wrapping up the next package to submit to the asset store. Version 1.2 will have some much needed bug fixes and performance improvements (in the form of reduced Draw Calls) as well as socket-able and socket-ed items!
     
  15. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    PGI version 1.2 is now live on the store and has the following updates!

    • FEATURE: Socketed and Socketable Items components.
    • UPDATE: Added a system to re-arrange slots in order to greatly reduce draw calls at runtime (when in play mode). This should improve rendering performance in many situations.
    • FIX: Removed an editor only import from PGIModel and added Conditional-compilation tag to PGIView that allow stand-alone builds to compile properly.
    • FIX: Fixed null reference exception in PGIModel.
    • FIX: Removed several leftover debug logs in PGIModel.
    I've already begun loads of fixes, features, and updates for the next release so it should actually come along relatively soon.
     
  16. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Just a heads up. Version 1.3 is nearing completion and should be submitted in the next day or so. It will have tons of small fixes and updates and some improved performance on top of that.

    But the big addition is that 3D meshes will now be usable as inventory icons! Even better, you'll have a UI component you can use to display meshes in any UI system you are working on. I've also included a complete project I made for a 48-hour game jam that uses PGI. You can play the webdemo here. http://ancientcraftgames.com/duelwizard/
     
  17. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    I'm pretty excited about the new 3D model icons. Since I won't be providing any 3D models due to limited resources I'll instead be making a few tutorial videos showing how to use them as well as other basic features. Here's a quick video that doubled as a recording test and a preview of the new icon system.



    Special thanks to xiaolianhuastudio and 7XFGames for their 'MYFG - Weapon Pack Lite' and 'Modern Weapons Pack' assets respectively. They are excellent free assets you can pick up in the Asset Store.
     
  18. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Version 1.3 has just been submitted with the following updates:

    FEATURES:
    • Addition of a 3D mesh UI element similar to Unity's 'UnityEngine.UI.Image'. Its fully qualified name is 'AncientCraftGames.UI.Image3D'.
    • 3D meshes now supported for icons.
    • Items can now have their own individual slot color that the view will use for a slot's highlight when that item is stored.
    • Addition of an array of MonoBehaviour references to PGISlotItem. This way you can simply cast these references for commonly and frequently access components rather than use GetComponent<>() inside hooked events.
    • Added a toggle to PGIView entitled 'DiableWorldDropping' than can be used to disallow users from dropping items from the inventory by dragging them into an empty region.
    • Added horizontal and vertical ordering settings to PGIView. These allow the view's grid to start at different corners when displayed. Note that internally the model's grid does not change, only the way the view interprets it.

    UPDATES & FIXES:
    • ***breaking change*** All classes are now under a namespace. The root namespaces are 'PowerGridInventory' and 'AncientCraftGames'.
    • PGIView's 'Batch Equipment' and 'Batch Grid' have now been combined into a single 'Batch Slots' toggle.
    • Slot elements that are unused or completely transparent are now disabled to help improve rendering performance.
    • Batching works much better overall, even when PGIView.BatchSlots is disabled.
    • CanSwap...() events are now only triggered a single time when the mouse first drags over an equipment slot rather than every time the mouse changes position whiled dragging.
    • Mobile devices now no longer count it as a click when a user ends a touch after hovering over a slot for more than 3/4 of a second. This should help normalize touch and mouse input more.
    • Removal of the 'DragIcon' prefab for views. It is now implicitly created a runtime when the first PGIView becomes active and share between all views from that point on.
    • Lots and lots of null-reference exceptions fixed.
    • Spruced up the inspector views a bit to make them more readable and user-friendly.
    • Changed a few minor public variable names. They all use [PreviouslySerializedAs] to ensure data isn't lost during update.
    • When a view is disabled during a drag operation the drag is now canceled properly.
    • When using 'Batch Slots' for PGIView, the z-depth for UI elements is now properly maintained.
    • Fixed a bug in 'Socketed.EmptySockets' that would return the incorrect number.
    • Added 'PGIModel.HasRoomForItem' method.
    • Added a new example project - Duel Wizard. It's a 48-hour game-jam project I did recently using PGI.
     
  19. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    355
    Hi, I'm eagerly awaiting this update. Any word on it, or are they just taking a while to approve it? (We submitted an update on Sept 4 for one of our products and it's still pending, so I know how it goes...)
     
  20. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Hello zangad! I'm glad you're excited for the next update and I apologize for the delay. It appears they are simply taking a while to approve. If it remains pending for another day or so I will likely re-submit. Sometimes that just happens. Either way I will post an update soon to let you and others know what is going on.
     
  21. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Version 1.3 has gone live with the aforementioned features!
     
  22. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Hmmm hey Sluggy! Small bug...

    ...I was able to open the small bag, then drag the bag from my main inventory into the bag's inventory and both the bag itself and its inventory window disappear.

    Also do you anticipate allowing for rotating non-square items?

    Thanks man!
     
  23. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Ah man! It's those little quick changes that get you every time. I'll fix that up as soon as I can. Thanks for the heads up!

    Now by 'rotating non-square items' what exactly do you mean? I'm guessing that you mean that when you rotate a 3D item it maintains its size rather than rescale to fit the RectTrans?
     
  24. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Yay!!

    ...as for non-square rotations: If you have an item that is 2 x 6, you could simple rotate it so it becomes 6 x 2. It's just another organizational level to fit everything into your inventory just the way you want it. It's really not necessary but the option to be able to is nice. I suspect it wouldn't be much more than a simple runtime re-size of the item and rotating the image associated.

    Again not necessary really but cool if it's not too much trouble. Heck just the fact that you have non-square, multi-tile items sets you apart from the rest of the inventory assets on the store!

    Thanks man! :D

    -Steven
     
  25. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    355
    Oooh, I completely agree that this would be a very nice feature. It solves an issue that will come up sooner or later in every dev's game that uses a grid inventory system. The player can't pickup that 6x2 item, but sees that he has plenty of inventory space at the bottom. But since he can't rotate the items, he has to leave the item behind (or drop other items), and rage ensues...

    Also, one criticism I see a lot with grid-based inventories is the need to play "inventory Tetris" to get items to fit. (I'm still going to have a grid-based inventory in my game because *I* like it. :p) But it would be great if there was an "optimize inventory" button that rotates and packs items into the upper left corner of the inventory as efficiently as possible for the player. I think that would mitigate the "inventory Tetris" complaint, and would go right along with the rotate feature SteveB suggested.

    Can I spend all my votes on these two features? :D
     
    Last edited: Sep 17, 2015
  26. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Ok, I see what you're saying. It should be simple enough for the rotation but I'll probably have to play around with the options for setting an 'origin cell' that the rotation takes place around.

    As for the 'auto arrange' feature, I've already got that on the official todo list (the making of Duel Wizard convinced me to add it) but since it is now in demand I'll bump it to the top of the list.

    Thanks for the input!
     
  27. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Just a heads up on the state of this bug. So I thought this would be a quick five minute fix but things are rapidly devolving into 'this-is-literally-impossible' land. I'm guessing something weird is going on with Unity's serialization because right now the storage bag shouldn't even work since I don't appear to have any events hooked to it. Hopefully I'll have this figured out in the next day or so. Once I get it working I'll post a hotfix for it.
     
  28. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Still haven't sorted out the issues with the nested inventory but I do have something else. A couple users were interested in how to add draggable windows to their PGI-based interfaces so I've gone and made a tutorial video.
     
  29. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Ok, I found the bug with the storage bag and it has to do with some logic changes I made inside the model so that highlighting would work differently. The problem is actually much larger and affect all items.

    It appears that if you have multiple events attached to a single 'Can' trigger (CanStore, CanDrop, CanEquip) the last one will override all others. Instead it should be that if any fail the whole process fails. I'll have to figure out a way around this but for now the storage bag in the example project can be fixed by simply removing the SimplePickup.CanStore event attached to the bag's PGISlotItem.OnCanStore trigger. Here is a picture - just remove the event highlighted in blue.

    Capture.PNG

    Just a heads up to everyone: I'm working towards having the next version out sometime around the beginning of November. It should include several bug fixes (including the one above), an inventory-wide item filtering extension (so that you can exclude entire item classes from an inventory). Item auto-arrangement and rotation.
     
  30. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    355
    That's great news, thanks for sharing. I'm eager to integrate this inventory system into my game, so I'm definitely looking forward to the November release!
     
  31. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Can't wait for the update! Can I suggest a few features? (I've already made these changes but would be better if the asset has the features, for update compatibility)

    * When a dragging item is dropped on a slot which already has an item, swap the dragging item rather than canceling the dragging.

    * When a dragging item is dropped on a storage item, it should be put in the storage.

    * Click to drag behaviour(Single click to start dragging and another click to drop the item.)

    While they aren't necessary for the inventory system to work, I believe they will give you "polished" feeling.
     
    Last edited: Oct 19, 2015
  32. DanielKolex

    DanielKolex

    Joined:
    Mar 24, 2013
    Posts:
    419
    Hey, just purchased this asset for my game. It is PERFECT. Keep up the great work! Awesome asset. Totally worth the cash. :) Looking forward to new features etc.
     
  33. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Umm....I'm having problem trying to make 30x30 inventory grids.
    It takes 10+ seconds to load up the inventory(the demo scene) and FPS becomes low.
    Looking at profiler, it seems PGIView.Start() is generating 30MB GC at the start and eventSystem.Update() being a heavy update.
     
  34. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    Hi! First of all thank you for nice asset!
    Do you have any plans or recommendations about saving somewhere my inventory between game sessions?
     
  35. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    The first and third feature are already planned. I just put them on the backburner for the sake of the rotation features. The second one should be simple enough if I add a drop-on-item event.
     
  36. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    The initial delay is due to the grid deleting and recreating all of the slots at startup as well as the slot arrangement for batching. The slots themselves are also performing an update. The first issue can be avoided in some cases by enabling the menu during a loading scene so that all of the slots are preallocated. The second issue might be be fixed with this next update as I've rearranged the way slots get updated and when. Once I get a few other features worked out I'll try to come up with a different way to initialize the grid.
     
  37. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Thank you and yes, at some point I will provide a built-in way of saving and loading but that might be a ways off yet. I can reccommend a few ideas right away though. I'm replying by mobile and it's a bit involved so I'll wait until I'm home to give a detailed explanation.
     
  38. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    sure, I really need that;)
     
  39. Petethegoat

    Petethegoat

    Joined:
    Jun 12, 2013
    Posts:
    39
    I'm implementing containers in the world (not in inventory), and I feel like the obvious way to do this is to give each container their own model, and have one view that looks at each different model when the container is opened.
    My naive implementation just changes the view's model whenever a different container is opened, and this doesn't work as expected, as there's not an easy way to refresh the view, and it shows everything from the first container you open.

    So I'm requesting a way to entirely refresh a PGIView, if you agree that this is the correct way to approach this.
    For testing you can add an extra storage bag to the example scene, and modify InventoryItem.cs to set the model of the stash PGIView to that of the opened bag.

    I'd also like to see dragging inventory items keep the offset from the cursor, instead of snapping to the middle of the item, but of course not so important.
     
  40. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    As you mentioned, I've just tested and the start up time has been significantly reduced when deleting slots in the editor before going to play mode. I'm going to see later if they can be reused rather than deleting them.

    As for the second issue, it's great that the next update will improve the performance. It's just fyi but I've replaced GraphicsRaycaster with Physic2dRaycaster and so far it's also working nice(as it doesn't iterate over each Graphic component).

    Thank you for your replies. Looking forward to the update!
     
  41. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    You'll be happy to know that I felt the same way about the view/model and have already implemented a new refresh mechanism. It will be a part of the soon-to-be sumited update 1.4. (It's also one of the reasons this update took a little longer than I expected). The new system will also make it much easier for save/load systems and network syced inventories. As for the offset issue: I'll certainly add it to the todo list but I won't promise it'll be at the very top. Thanks for the input!
     
  42. Petethegoat

    Petethegoat

    Joined:
    Jun 12, 2013
    Posts:
    39
    Wonderful, looking forward to the update.
     
  43. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Okay, so the basic gist of saving and loading inventories boils down to two seemingly simple steps: 1) Collecting the data that represents the items and storing to or loading it from a file, and 2) informing the model and view if something changes.

    The reason I say 'seemingly' is because there are a lot of ways that first step can be accomplished. One approach (and possibly the easiest though I haven't tried it) is to use some kind of universal serializer on the entire GameObject representing the model to save and load the entire inventory in one action. Another method might be to use the same kind of serializer to save and then load individual GameObjects representing items and then manually place them into the model using PGIModel.Store() and PGI.Equip(). Yet another approach (and then one I am currently using in my own game) is to pick out specific bits of data from classes (or MonoBehaviours) save them to file and when loading. Then later, re-create the items from scratch using these key bits of data. In my case this work perfectly because most of the data is simply index numbers that refer to entries in a database that my item generator uses anyway.

    The real trick in this case is letting the view know when the model has become dirty. In the event that you manually called the Store or Equip methods the model should update the dirty regions and the view will pick out those cues and update itself accordingly. In the event that you serialized the entire model or did not place the items by using the aforementioned methods then you will likely have to manually call AddDirtyArea, AddDirtyEquipmentSlot, or MarkDirty on the model to let the view know that something has changed.

    Take Note! The 'Dirty Region' flagging system is only for the current version of PGI and I am phasing it out for a simpler one where the view simply makes periodic checks and updates everything if the model's single 'dirty' flag is set. This new system will be present in the next update and will greatly simplify the whole process of keeping model and view in sync. It should also fix a whole slew of other issues I've had in the past including the one mention above in Petethegoat's post.

    Overall the topic of object serialization is a very big one so if you're not that familiar with it, you'll need to get up to speed before you can really tackle this issue. It's also why I've not focused on a built-in solution for now as there are currently other products that more than likely do much better jobs than I can hack together in a few weeks. I'd rather spend that time working on something new for PGI ;) If you're interested in trying out a full GameObject serialization system I might recommend Runtime Serialization in the asset store or unityserializer-ng on github. I haven't tried either yet but they look promising and the latter is free.

    EDIT: Oh one other thing! If you're game depends on the events being triggered after a restoration of an inventory (an example might be an item that provides a buff to players stats when in the inventory and applies this buff during through an event hooked to the model's OnStoreItem event) then you will need to manually trigger these events as well. You can see a list of methods to call in the PGISlotItem's reference. They all begin with 'Trigger' e.g. TriggerStoreEvents.
     
    Last edited: Oct 27, 2015
  44. mm_ASH

    mm_ASH

    Joined:
    Nov 15, 2013
    Posts:
    358
    Thank you for such a broad answer!
    I will try different approaches you proposed .. will see what will be more suitable :)
     
  45. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Just a heads up to everyone waiting for the next update: It appears to be taking longer than I expected because I re-arranged some internals to allow for a more flexible system. But I need to test and confirm everything really is working correctly and indeed better than before. It is taking some extra time as I squash bugs popping up due to earlier design decisions.

    Long-story-short, I'm pushing for the new submit by the end of this week. I apologize for those of you waiting for this next release and I promise you won't have to wait much longer.
     
    Petethegoat, sVr90 and noanoa like this.
  46. sVr90

    sVr90

    Joined:
    Nov 3, 2015
    Posts:
    1
    Hey Sluggy,

    I did send you a conversation (private message) two days ago. As it seems you probably overlooked it :p Could you take a glimpse at it? Thank you for your time.

    Kind regards,
    -Matthew
     
  47. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Okay! version 1.4 is being finalized and submitted now. I apologize that it took so long but I think the improved internals were well worth it. Future updates should be easier now that I can focus on making new stuff without worrying so much about retro-fitting all of it to the old view-update system.

    Version 1.4 Updates
    • Items can now be rotated using PGISlotItem.Rotate(PGISlotItem.RotationDirection). Rotation is in the form of three non-relative states. 'None', 'Clockwise', and 'Counter-Clockwise'. When rotating items in an inventory they may shift position slightly in order to attempt to fit into available spaces. *
    • Added an auto-arrange method for models that can optionally support rotation of items. This is still very experimental and will likely give sub-optimal results in some cases. *
    • Removed update methods from PGIView and PGISlot. This should boost performance, specially in the case of large grids.
    • Greatly simplified the internal drity updating system in the model and how the view uses it. The model now triggers an event of the type 'public event DirtyEvent OnUpdateDirty' when something changes. This should greatly increase robustness, maintainablity, extensibility, and reduce bugs for future updates. It should also increase performance in the case of large inventory grids due to the fact that each slot no longer has its own update. The view might take a little extra time to update when the model changes since the whole thing is refreshed at once but this happens very infrequently so it should not be much of an issue.
    • Fixed a bug that would occur when multiple 'Can..' event hooks where attached to the same event and the last one would override the 'CanPerformAction' flags set by all the previous ones. It now properly ensures that if the flag is set as false it stays that way and will not allow other events to reset it.
    • Fixed an error in the slot batcher that would choke if any child elements of the slot did not have SlotBatch component attached.
    • Added PGIView.UpdateViewStep() for forcing view to update.
    • If a view's reference to a model is changed it now properly updates to reflect the state of the new model. **
    • Model now properly supports having multiple active views attached to it at the same time. **

    * These features are still very experimental and will often given results that are less than optimal. This will be an ongoing project to improve their performance and reliability.
    ** Currently equipment slots do not play well when switching models for a view and don't support multiple views at the same time period. The problem stems from the fact that they are attached directly to the model and bypass the view entirely. I may change this at some point in the future.

    For the Future
    In other news, here is a rough list of some of the features I'd like implement in future updates. This is in no particular order so if there is anything here you would like to see prioritized (or even anything not here that you would like to see on the list) feel free to let me know.

    • Hotkey slots. They can have items dropped into them but do not remove the item from it's original equipment/grid slot.
    • Drag Triggers: Regions that trigger events when dragged over/away from/dropped into.
    • Item grid swapping.
    • Equipment slots should not be assigned to the model. This welds the view-oriented slots to the model which is bad.
    • Allow for attempted item re-arrangement when picking up a new item and there is not enough room for it.
    • Click n' Drag controls.
    • Non-pointer support (gamepads, keyboards).
    • Support for rotating while dragging.
    • Better support for equipment slots when switching a view's model.
    • Auto-resizing grid container to match given slot ratio.
    • Configurable spacing between grid slots.
    • Built-in saving and loading.
    • Inventory editor (requires built-in saving and loading).
    • Drag Icon offsets based on where the icon was dragged from.
    • Better support for dragging items between views with different slot sizes (currently the drag icon size is based on the view the item came from).
     
  48. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @ Sluggy - if I am reading this Asset and the Manual correctly (getting started) it is up to me (which is a good thing!) to design how I save and load my inventory items (list, perhaps database, perhaps scriptable objects), I can define how the inventories look etc etc.

    What about GUI for crafting items?
     
  49. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Yep, that's spot on. While PGI does refer to a view and a model, the model is more for the sake on maintaining the internal structure of the grid, and where items are placed in it and the view simply displays the model in its current state. It is not really meant to be a ready-made inventory system that you can pop into a game and expect it to magically work. It is up to the user to define any databases, item structures, or gameplay mechanics their game requires. PGI is more-or-less in the realm of user-interface design. That being said, PGI does provide lot event hooks to allow you to trigger any important game-specific actions when things like items leaving the inventory, or being socketed, or dragged to a new location occur. As an example of the kinds of things you can do I have several 'extenions' that come with PGI that perform things like item-filtering and multi-slot equipment to show how useful this can be.

    I am currently looking in to adding a built-in saving/loading system that will use unity's default serializer (which mean that it will be rather limited) but you can certainly use any other save/load system you want and as long as you let the PGI model know what is going on it will work just fine. PGI also uses a prefab to define the grid cells using the new UGUI system so it is very easy to customize the look of your inventory grids by simply making your own prefabs and referencing them in the inventory views.

    As far as crafting, again that is game-specific territory and PGI provides no functionality there. However, it exposes all of the data and events you need to implement your own crafting system using it (you can simply query the model for what items are in it and provide your own system for how they should combine to craft something). Take note that you don't even need a grid if you don't want it. PGI allows you to setup individual cells called 'equipment slots' which are very handy for things like crafting stations.

    Hope that answered your questions. If you have any more I'll be happy to answer.
     
  50. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    That's great Sluggy, makes sense. As long as I'm prepared to get my hands dirty with some coding it allows for far more flexibility as it's far less prescriptive.

    Once I've got my scriptableobject databases working I'll be purchasing this... ;)