Search Unity

S-Inventory: Equipment, Crafting, Skill Bar, Item Groups, Containers & Merchant (C# & JS)

Discussion in 'Assets and Asset Store' started by OussamaB, Jul 29, 2013.

Thread Status:
Not open for further replies.
  1. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    ok I am going to be completely honest! I do not like the new update for S-Inventory.... The version before this one I had no problems setting it up now When I am adding an inventory system to RFPS Nothing shows up.
     
  2. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    I have the RFPS with the S-inventory, I also own a copy of the Dialogue System, but I tried to follow the third party support guide on pixelCrushers website, but it seamed outdated, as the third party for S-inventory is looking for the old GUI and not the new uGUI system. Also getting error when trying to add the script described in the guide to the gameObject "the *script* does not exist, check name" something, can remember the exact error message, I can double check the error message when I get home.

    For the RFPS, how can I edit it the pickup script to only show the hand and not do anything on pickup as its just using s-inventorys method atm.

    The item.cs script in S-Inventory has an OnMouseEnter and OnMouseExit, wouldn't it be possible to edit the code to show a pickup icon when mouse is hovering the object?
     
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    I hear you. The new Unity UI version is definitely more tedious to set up. And if you miss even a single hookup between S-InventoryC# and InvCanvasC#, it will just inexplicably not work right. But once you get everything hooked up, it works great! It's much faster than the old version since it uses the new UI system. You might find it helpful to follow the tip on step 1 of the Setup Actors section. This is in the Dialogue System documentation for S-Inventory support (not the RFPS + S-Inventory support page). This tip is useful even if you're not using the Dialogue System.

    In brief:
    • I multi-selected S-InventoryC# and InvCanvasC# in a working scene and copied them to the clipboard. (On Windows, Ctrl-click to multi-select, Ctrl-C to copy to clipboard.) It's critical to copy both at the same time so they retain references to each other.
    • Then I opened my new scene and pasted them in. (Click in Hierarchy view, Ctrl-V to paste.)
    • Finally, I moved S-InventoryC# under my player GameObject.
    • Since my scene didn't already have an EventSystem, I added one (GameObject > UI > EventSystem).
    Once you've confirmed that everything's working, you can swap out the textures with your own to customize the look.

    For the latest support, please check these steps:
    • Imported S-Inventory v1.21.
    • Imported Dialogue System v1.4.3.
    • Imported Dialogue System/Third Party Support/Realistic FPS Prefab Support.
    • Imported Dialogue System/Third Party Support/S-Inventory Support.
    • Imported Dialogue System/Third Party Support/S-Inventory Support/RFPS S-Inventory Support.
    All five of those packages above contain updates. You can import the v1.4.3 version of S-Inventory Support, or get this updated version. The updated version includes a fix to consumables (a bug previously let you eat so much that your hunger went negative) and adds beer and cake to the example scene.

    Refresh your browser. It might be using old, cached versions of the Dialogue System S-Inventory Support and RFPS / S-Inventory Support pages.

    If you're using RFPS, try this:
    • Add an S-Inventory Item component (from S-Inventory's scripts; make sure to use the C# version).
    • Add an SInventory Pickup component (from Dialogue System's scripts; Component > Dialogue System > Third Party > S-Inventory > RFPS).
    • Set the Tag to Usable and the Layer to Ragdolls/Pickups.
    The Dialogue System's SInventory Pickup script just ties it into RFPS's hand cursor. It otherwise leaves the pickup work to S-Inventory's Item component. In the example scene, chop down the tree near the player's starting position. This will spawn a log that you can pick up using this method.

    That should work, too. Make sure the item has a collider so it can receive OnMouseEnter/Exit messages.
     
    Last edited: Jan 16, 2015
  4. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Please PM me your e-mail so that I can send you the modified code which will allow you to do the following:

    - Left click does nothing.
    - Double click sends the item to the equipment window/skill bar if it's usable there.
    - Right click consumes the item directly from the inventory menu if it's usable.

    This might actually be added in the next update.
     
  5. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    Hello....I am not sure what developer to go to but I figured you reply the fastest but I am working with an older copy of your inventory system and I am trying to use a function from your script and call it to another script in UFPS so below is a rough outline in the code of what I am trying to do.

    Here is from yours:

    publicvoidUpdate (){
    if(Input.GetKeyDown(Key)) //CheckiftheplayerpressedtheIkeywhichenables/disablestheinventory.
    {
    if(ShowInv)
    {
    ShowInv = false; //Hidetheinventory.
    Action = false;
    audio.PlayOneShot(CloseBag);
    }
    else
    {
    ShowInv = true; //Showtheinventory.
    audio.PlayOneShot(OpenBag);
    }
    }

    and I need to to do something like this

    //togglepausingandabortifpaused
    UpdatePause();

    if(FPPlayer.Pause.Get() == true)
    return;
    //checkifinventoryisdisplayedornotandassingmousefreeze
    if (ShowInv() == true)
    MouseCursorForced = false;


    where as the bold text is the important factor here, so how would I ask that....I am sorry if it is simple I come from 3d modeling and PHP so not to sure of coding with JS and C#
     
  6. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    You should call the InventoryGUI script first in your UFPS script. In C#, you would have to do like this:

    Code (csharp):
    1. //Create a variable to assign the InventoryManager to it:
    2. InventoryGUI InvGUI;
    3.  
    4. void Awake()
    5. {
    6.     //Assign it on awake in the UFPS script.
    7.     InvGUI = FindObjectOfType(typeof(InventoryGUI)) as InventoryGUI;
    8. }
    9.  
    10. //When you want to check if the inventory window is open then do this:
    11. if(InvGUI.ShowInv == true)
    12. {
    13.     //Your code here...
    14. }
    EDIT:

    S-Inventory v1.21 is now available on the asset store!
     
  7. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    Is there anyway to revert back to the old version of S-Inventory? Still having problems with the latest update... I did everything that I was told to do copy and paste from the example scene etc. But now the inventory does not show up at all, I can hear the sounds that it is opening but I don't see it.
     
  8. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Would you mind sending me your project or simply a scene where you have the Invnetory asset so that I can investigate the issue? Does S-Inventory work on its own in the demo scenes or does it stop working with you tried linking it with RFPS and Dialogue System?
     
  9. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    It works perfectly with the RFPS demo scene of S-Inventory but when I try to set it up in my scene it does not work correctly.
     
  10. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Feel free to send me a copy of the project, too. SoumiDelRio is the expert in S-Inventory, of course, but I'll be happy to take a look in case it's related to RFPS or the Dialogue System. If it's too big to email to tony (at) pixelcrushers.com, PM or email me and I'll send you FTP instructions.
     
  11. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    Do you have UFPS? If so any idea what code is used to stop making mouse disappear on click? I want to be able to drag and drop in the inventory. I am using latest UFPS and the older version of S Inventory.
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    If you have the Dialogue System, you can use FPFreezePlayer.Freeze() and Unfreeze(). If not, here's the code it uses. You can adapt it to your needs. Call Freeze() before opening any inventory windows, and Unfreeze() when they're all closed.
    Code (csharp):
    1.        /// <summary>
    2.         /// Freeze the UFPS player (i.e., gameplay) and show the cursor.
    3.         /// </summary>
    4.         public void Freeze() {
    5.             if (fpPlayerEventHandler != null) fpPlayerEventHandler.Attack.Stop();
    6.             if (fpController != null) {
    7.                 fpController.SetState("Freeze", true);
    8.                 fpController.Stop();
    9.             }
    10.             wasCrosshairVisible = (fpCrosshair != null) && fpCrosshair.enabled;
    11.             if (fpCrosshair != null) fpCrosshair.enabled = false;
    12.             if (fpCamera != null) fpCamera.SetState("Freeze", true);
    13.             if (fpInput != null) fpInput.enabled = false;
    14.             if (hideHUD && (fpHUD != null)) fpHUD.enabled = false;
    15.             StartCoroutine(ShowCursorAfterOneFrame());
    16.         }
    17.        
    18.         /// <summary>
    19.         /// Unfreeze the UFPS player (i.e. gameplay) and restore the previous cursor state.
    20.         /// </summary>
    21.         public void Unfreeze() {
    22.             if (fpController != null) fpController.SetState("Freeze", false);
    23.             if ((fpCrosshair != null) && wasCrosshairVisible) fpCrosshair.enabled = true;
    24.             if (fpCamera != null) fpCamera.SetState("Freeze", false);
    25.             if (fpInput != null) fpInput.enabled = true;
    26.             if (hideHUD && (fpHUD != null)) fpHUD.enabled = true;
    27.             RestorePreviousCursorState();
    28.         }
    29.        
    30.         /// <summary>
    31.         /// Shows the cursor after one frame. We wait one frame to allow UFPS to do any closeout
    32.         /// that might try to regain cursor control.
    33.         /// </summary>
    34.         private IEnumerator ShowCursorAfterOneFrame() {
    35.             wasCursorVisible = Screen.showCursor;
    36.             wasCursorLocked = Screen.lockCursor;
    37.             yield return null;
    38.             Screen.showCursor = true;  
    39.             Screen.lockCursor = false;
    40.         }
    41.        
    42.         private void RestorePreviousCursorState() {
    43.             Screen.showCursor = wasCursorVisible;
    44.             Screen.lockCursor = wasCursorLocked;
    45.         }
    You can get further help on the VisionPunk forums.
     
  13. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    I am trying to get help on there as well, I have gotten it to freeze everything no problem using several methods even a simple pause event and unlock the cursor, however I am curious how do I wrap the bottom code with a keypress?

    e.g. I assigned "I" to a key called Inventory

    Code (CSharp):
    1. if (vp_Input.GetButtonDown ("Inventory")){
    2.             {
    3.             private IEnumerator ShowCursorAfterOneFrame()
    4.                 wasCursorVisible = Screen.showCursor;
    5.                 wasCursorLocked = Screen.lockCursor;
    6.                 yield return null;
    7.                 Screen.showCursor = true;
    8.                 Screen.lockCursor = false;
    9.             }
    10.            
    11.             private void RestorePreviousCursorState() {
    12.                 Screen.showCursor = wasCursorVisible;
    13.                 Screen.lockCursor = wasCursorLocked;
    14.             }
    15.         }
     
  14. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    You have to do more than show the cursor; otherwise UFPS will hide it during the next frame. Put the code I posted above in its own script. You'll need to fill in the rest, like defining and assigning the variables fpController, fpCrosshair, etc. Oh, here you go, the whole thing. :)

    FPFreezePlayer.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. //--- (removed namespace for this forum post to make it easier)
    5. //---namespace PixelCrushers.DialogueSystem.UFPS {
    6.  
    7.     /// <summary>
    8.     /// This component provides methods to freeze and unfreeze the UFPS player.
    9.     /// It also freezes the player during conversations.
    10.     /// </summary>
    11.     [AddComponentMenu("Dialogue System/Third Party/UFPS/Freeze Player")]
    12.     public class FPFreezePlayer : MonoBehaviour {
    13.      
    14.         public bool hideHUD = true;
    15.         public bool freezeDuringConversations = true;
    16.      
    17.         // If you don't assign these properties, the Awake() method will automatically assign them.
    18.         public vp_FPController fpController = null;
    19.         public vp_FPCamera fpCamera = null;
    20.         public vp_FPPlayerEventHandler fpPlayerEventHandler = null;
    21.         public vp_FPInput fpInput = null;
    22.         public vp_SimpleHUD fpHUD = null;
    23.         public MonoBehaviour fpCrosshair = null;
    24.      
    25.         private bool wasCrosshairVisible;
    26.         private bool wasCursorVisible;
    27.         private bool wasCursorLocked;
    28.      
    29.         void Awake() {
    30.             if (fpController == null) fpController = GetComponentInChildren<vp_FPController>();
    31.             if (fpCamera == null) fpCamera = GetComponentInChildren<vp_FPCamera>();
    32.             if (fpPlayerEventHandler == null) fpPlayerEventHandler = GetComponentInChildren<vp_FPPlayerEventHandler>();
    33.             if (fpInput == null) fpInput = GetComponentInChildren<vp_FPInput>();
    34.             if (fpHUD == null) fpHUD = GetComponentInChildren<vp_SimpleHUD>();
    35.             if (fpCrosshair == null) fpCrosshair = GetComponentInChildren<vp_SimpleCrosshair>();
    36.         }
    37.      
    38.         /// <summary>
    39.         /// When a conversation starts, freeze the UFPS player (i.e., gameplay) and show the cursor.
    40.         /// </summary>
    41.         /// <param name='actor'>
    42.         /// Actor participating in the conversation.
    43.         /// </param>
    44.         public void OnConversationStart(Transform actor) {
    45.             if (freezeDuringConversations) Freeze();
    46.         }
    47.      
    48.         /// <summary>
    49.         /// When a conversation ends, unfreeze the UFPS player (i.e., gameplay) and restore the
    50.         /// previous cursor state.
    51.         /// </summary>
    52.         /// <param name='actor'>
    53.         /// Actor participating in the conversation.
    54.         /// </param>
    55.         public void OnConversationEnd(Transform actor) {
    56.             if (freezeDuringConversations) Unfreeze();
    57.         }
    58.      
    59.         /// <summary>
    60.         /// Freeze the UFPS player (i.e., gameplay) and show the cursor.
    61.         /// </summary>
    62.         public void Freeze() {
    63.             if (fpPlayerEventHandler != null) fpPlayerEventHandler.Attack.Stop();
    64.             if (fpController != null) {
    65.                 fpController.SetState("Freeze", true);
    66.                 fpController.Stop();
    67.             }
    68.             wasCrosshairVisible = (fpCrosshair != null) && fpCrosshair.enabled;
    69.             if (fpCrosshair != null) fpCrosshair.enabled = false;
    70.             if (fpCamera != null) fpCamera.SetState("Freeze", true);
    71.             if (fpInput != null) fpInput.enabled = false;
    72.             if (hideHUD && (fpHUD != null)) fpHUD.enabled = false;
    73.             StartCoroutine(ShowCursorAfterOneFrame());
    74.         }
    75.      
    76.         /// <summary>
    77.         /// Unfreeze the UFPS player (i.e. gameplay) and restore the previous cursor state.
    78.         /// </summary>
    79.         public void Unfreeze() {
    80.             if (fpController != null) fpController.SetState("Freeze", false);
    81.             if ((fpCrosshair != null) && wasCrosshairVisible) fpCrosshair.enabled = true;
    82.             if (fpCamera != null) fpCamera.SetState("Freeze", false);
    83.             if (fpInput != null) fpInput.enabled = true;
    84.             if (hideHUD && (fpHUD != null)) fpHUD.enabled = true;
    85.             RestorePreviousCursorState();
    86.         }
    87.      
    88.         /// <summary>
    89.         /// Shows the cursor after one frame. We wait one frame to allow UFPS to do any closeout
    90.         /// that might try to regain cursor control.
    91.         /// </summary>
    92.         /// <returns>
    93.         /// <c>null</c> (coroutine).
    94.         /// </returns>
    95.         private IEnumerator ShowCursorAfterOneFrame() {
    96.             wasCursorVisible = Screen.showCursor;
    97.             wasCursorLocked = Screen.lockCursor;
    98.             yield return null;
    99.             Screen.showCursor = true;
    100.             Screen.lockCursor = false;
    101.         }
    102.      
    103.         private void RestorePreviousCursorState() {
    104.             Screen.showCursor = wasCursorVisible;
    105.             Screen.lockCursor = wasCursorLocked;
    106.         }
    107.      
    108.     }
    109.  
    110. //---}
    111.  
    Add this to your UFPS player GameObject.

    When you show the inventory (in InventoryUI.cs:ToggleInventory() or elsewhere), call:
    Code (csharp):
    1. FindObjectOfType<FPFreezePlayer>().Freeze();
    and when you hide the inventory, call:
    Code (csharp):
    1. FindObjectOfType<FPFreezePlayer>().Unfreeze();
    And if you want to do more, such as saving and loading games, and adding barks, quests, and conversations, the Dialogue System (with UFPS integration) is on sale until the end of the weekend. ;)
     
    Joseph-Townsend likes this.
  15. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    WOW you are AMAZING!!!! I really mean that, this has solved what I have been ripping my hair out trying to do, if you want I can send a tip your way for the troubles if you send me your paypal email. One last thing.....I know I know I am overstaying any welcome I have here lol; but for the unfreeze part, any ideas how to integrate that into this

    Code (CSharp):
    1.     protected virtual void UpdatePause()
    2.     {
    3.  
    4.         if(vp_Input.GetButtonDown("Pause"))
    5.             FPPlayer.Pause.Set(!FPPlayer.Pause.Get());
    6.         if (vp_Input.GetButtonDown ("Inventory")) {
    7.             FindObjectOfType<FPFreezePlayer>().Freeze();
    8.              
    9.                 }
    10.     }
    EDIT: Sorry I misread the last part you said and put it in the InventoryGUI script and it works like a charm! Thank so very very much just so I do not struggle could you please still answer the above incase I need to ever move this or anything else, I really am only 2.5 days new to C# programming so I have my challenges....also I will still definitely tip if you send me your paypal email; final thing, if you want to make $5-$10 here and there to solve problems for me let me know and I will keep in touch.
     
    Last edited: Jan 19, 2015
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    I'm happy I could help! If you ever need to add conversations (or quests or UFPS saving and loading) to one of your projects, I hope you'll keep the Dialogue System in mind.
     
  17. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Sorry for a really dumb question, but how would I approach using a custom script to add / remove items from inventory?

    Say something like interact with a object, and at the end after the player have completed, say a mini-game, the item is added to inventory.

    A simple script that is called after the mini game.
     
  18. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    @TonyLi I will definitely keep it in mind, not sure what I would use it for at this moment, however even if not for this game I may need it for an upcoming rpg, so I have already favorited the page :)

    @Saturn Ent I am not good with C# as I come from PHP which there is a huge difference, however unless someone corrects me, you would attach the item.cs script to the object and then add custom vars that will tell it which item they got ,then make that item show up maybe on a scoreboard then they can click it to claim; or if you absolutely want it to be automated you will need to go into the inventory manager script and create a new item pick up type and then call on it similar to how the mouse or keyboard pickup types work but based on your vars instead.
     
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Create the item as @Trim Studio Designs describes (create a GameObject, add Item.cs, etc.). Add the GameObject to your scene, and deactivate it. When you want to give the item to the player, run some code like this:
    Code (csharp):
    1. // Add the item:
    2. item.SetActive(true);
    3. var invManager = FindObjectOfType<InventoryManager>();
    4. invManager.AddItem(item.transform);
    5.  
    6. // Refresh the UI:
    7. var originalInvID = invManager.InvUI.InvID;
    8. invManager.InvUI.InvID = 1; // Special code for items.
    9. invManager.InvUI.RefreshItems();
    10. invManager.InvUI.InvID = originalInvID;
    If you're using the Dialogue System integration, you can just call SInventoryLua.AddItem(). This also lets you add items from prefabs so you don't have to keep a GameObject in the scene.
     
  20. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Hmm, I thought it could be done with a small additem script, and add the item prewritten in the code or just by a variable.

    Lets say you are doing some stuff like searching a cabinet, then when the search timer is done, you call the additem script, adding the item to your inventory.

    Or lets say you press a GUI button, and it will add a item ot multiple items to your inventory.
     
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Items are GameObjects. It's easiest to create them in the editor, but you can create them in code. For example:
    Code (csharp):
    1. var item = new GameObject("MyItem", typeof(Item));
    2. invManager.AddItem(item.transform);
    You'll want to actually set the properties inside the Item component (e.g., item.Name) before adding it to the inventory manager.
     
  22. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61

    Still having issues with your third party support.
    The S-Inventory works just fine alone.

    Following you guide gives me errors, and the S-Inventory menu is missing in the component list in Dialogue system.

    See pictures:

    Tried to manually drag and drop the script in the guide to the !!!FPS Player:


    S-Inventory is missing in the component list.



    The pack also gives me a few errors in the console.




    Using Latest version of all packages.
     
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Hi @Saturn Ent - It looks like you just need to update to S-Inventory v1.21.


    The complete checklist of packages to import is:
    • S-Inventory v1.21+
    • Dialogue System v1.4.3+
    • Dialogue System/Third Party Support/Realistic FPS Prefab Support
    • Dialogue System/Third Party Support/S-Inventory Support
    • Dialogue System/Third Party Support/S-Inventory/RFPS S-Inventory Support
    The good news is that this should be the last of the confusing dependencies where you need to update one product to use the latest version of the other. S-Inventory v1.21 introduced the one last feature that the Dialogue System integration needed.
     
    Last edited: Jan 21, 2015
  24. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    According to Unity Asset store I have 1.21 installed already.
     
  25. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Try re-importing the "Third Party Support/S-Inventory Support" and "Third Party Support/S-Inventory/RFPS S-Inventory Support" that came with v1.4.3+. If this doesn't help, consider deleting the Dialogue System and S-Inventory folders and reimporting them fresh.
     
  26. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    Will do, Im also going to test in a clean project, ill report back when I have tested it.
     
  27. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    An update!

    It works fine in a fresh project, but somehow not in my existing project.
     
  28. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    Does anyone have any code to make it so when you click equip in s-inventory it forces ufps character to equip the item?
     
  29. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Try deleting all the folders inside the Script/Dialogue System/Third Party Support folder. Then re-import the packages you need (RFPS, S-Inventory, and S-Inventory+RFPS).

    It that doesn't work, check for stray files like SInventoryDialogueActor.cs that might have been accidentally dragged into another folder somewhere. They might be conflicting with the freshly-imported version. From your screenshots, it definitely looks like there's an issue with the S-Inventory support files.

    If you use the C# version of S-Inventory, you can hook into the InventoryEvents.PlayerEquippedItem event.

    First, add a script to your item that specifies what weapon number it is. Something like:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class UFPSWeaponNumber : MonoBehaviour {
    4.     public int weaponNumber;
    5. }
    Then add a script to your player that hooks into the event:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class SInventoryEquipUFPS : MonoBehaviour {
    4.  
    5.     void OnEnable() {
    6.         GetComponentInChildren<InventoryEvents>().PlayerEquippedItem += OnEquip;
    7.     }
    8.  
    9.     void OnDisable() {
    10.         GetComponentInChildren<InventoryEvents>().PlayerEquippedItem -= OnEquip;
    11.     }
    12.  
    13.     void OnEquip(string ItemName) {
    14.         var item = GetComponentInChildren<InvManager>().gameObject.Find(ItemName);
    15.         var weaponNumber = item.GetComponent<UFPSWeaponNumber>().weaponNumber;
    16.         GetComponent<vp_FPPlayerEventHandler>().SetWeapon.TryStart(weaponNumber);
    17.     }
    18. }
    Note: I just typed in the code above. It doesn't do any error checking, and it might have typos.

    [EDIT: (1) Fixed "MonoBehaviour". (2) Requires S-Inventory 1.21+]
     
    Last edited: Jan 23, 2015
  30. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    So there was only one typo in the word "MonoBehavior" it is spelt "MonoBehaviour" so over they have have the typo not you....anyways I get one other error, it stats InventoryEvents does not contain a definition for PlayerEquippedItem, any ideas how to fix that?
     
  31. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Thanks. I just un-Americanized the typo. ;) The script requires S-Inventory v1.21+. SoumiDelRio added InventoryEvents.PlayerEquippedItem in v1.21.
     
  32. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    I have the 1.2 from 01/06/15 .... although I wonder if it did not properly update....is there a way to check in unity which one I have installed, like an about page or anything?

    EDIT:
    The closest thing I have is

    Code (CSharp):
    1. public void OnPlayerEquipItem (string ItemName, string EquipmentSlot)
    2.     {
    3.         //Your code here.
    4.         Debug.Log("Just equipped "+ItemName+" on "+EquipmentSlot+" slot.");
    5.     }

    is that what you are referring to?
     
    Last edited: Jan 23, 2015
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    SoumiDelRio submitted v1.21 on 01/12/15. I think it was available on the Asset Store starting around 01/17/15. Try updating from the Asset Store.
     
  34. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    Oh did not see your reply as I had not refreshed the page, alright will try.
     
  35. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    I am glad you asked me to update, I am not able to login...strange....I will contact unity support but probably will be a week or so before I am able to actually work on this again, so if I come out of the blue referring back to this, that is why :p
     
  36. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    PM me your e-mail and invoice and I will send you the updated version.
     
    TonyLi likes this.
  37. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    Hmm.....got the updated version, updated unity as well and now I can not open inventory or crafting menu, also it appears a lot of values are empty see the inspector window on the right side of screen.

     
  38. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    nvm, I see that you must completley re-set everything up....I am having difficulty following the instruction though....can someone please upload a tutorial video on setup with UFPS....please....I already spent a lot of hours with the last version trying to reverse code it so I can understand how it works I do not want to have to do the same here :(


    EDIT: I got it all figured out I will create an upload a video sometime over the next two days to help other that are new to setting this up, I will also include integrating into UFPS like we have been going over these past few days
     
    Last edited: Jan 25, 2015
    TonyLi likes this.
  39. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    That'll be great, and it'll help a lot of people. The new UI works great in S-Inventory, but it's a chore to set up. Here's a tip from the Dialogue System's S-Inventory support documentation:
    It's still useful even if you don't use the Dialogue System, but your video will probably be even more helpful.
     
  40. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    @TonyLi I think I may have messed something up....or I am not doing something right but I can not get action menu working...if you could or @SoumiDelRio please review the video below to let me know what is going on here.

     
  41. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    For inventory not saving: If you're using the Dialogue System's S-Inventory support scripts, just add an SInventoryDialogueActor to your player, and use the Dialogue System's Save System. The SInventoryDialogueActor automatically includes S-Inventory info in saved games.

    The alternative is to tick "Save and Load" on all of the scripts under S-InventoryC#. This will tell S-Inventory to save the current inventory state to PlayerPrefs.

    For the action menu and other interaction with the UI: UFPS intercepts all input. When you open any S-Inventory windows, you should freeze UFPS. Then unfreeze UFPS when all S-Inventory windows have been closed. I'll add S-Inventory + UFPS integration to the Dialogue System "to do" list, although it may be a little while before I have a chance to work on it.

    Here's the equivalent code used to freeze Realistic FPS Prefab:
    Code (csharp):
    1.         private bool wasGUIOpen = false;
    2.  
    3.         /// <summary>
    4.         /// If the inventory GUI state has changed, hides or shows the RFPS HUD/controls.
    5.         /// </summary>
    6.         public void Update() {
    7.             CheckInventoryGUI();
    8.         }
    9.  
    10.         public void CheckInventoryGUI() {
    11.             var isGUIOpen = IsInventoryGUIOpen();
    12.             if (isGUIOpen && !wasGUIOpen) HideHUD();
    13.             if (!isGUIOpen && wasGUIOpen) Invoke("ShowHUD", 0.2f); // Wait for window to close.
    14.             wasGUIOpen = isGUIOpen;
    15.         }
    16.  
    17.         public bool IsInventoryGUIOpen() {
    18.             return (sInventoryDialogueActor != null) &&
    19.                 (sInventoryDialogueActor.invUI != null) &&
    20.                 (sInventoryDialogueActor.invUI.ShowInv ||
    21.                     sInventoryDialogueActor.equipUI.Panel.activeInHierarchy ||
    22.                     sInventoryDialogueActor.craftUI.Panel.activeInHierarchy ||
    23.                     sInventoryDialogueActor.vendorUI.Panel.activeInHierarchy);
    24.         }
    25.  
    26.         public void HideHUD() {
    27.             // (freeze UFPS here)
    28.         }
    29.  
    30.         public void ShowHUD() {
    31.             // (unfreeze UFPS here)
    32.         }
     
    Last edited: Jan 25, 2015
  42. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    I am freezing it like below, is this correct, if not what would be the proper section? If so what would be causing the freezing up

    InventoryUI.cs snippet

    Code (CSharp):
    1. public void  ToggleInventory (){
    2.         ShowInv = !ShowInv; //Hide the inventory.
    3.  
    4.      
    5.         if(ShowInv == false)
    6.         {
    7.             Action = false;
    8.             Panel.SetActive(false);
    9.             audio.PlayOneShot(CloseBag);
    10.          
    11.             CloseActionMenu ();
    12.             FindObjectOfType<FPFreezePlayer>().Unfreeze(); //return control back to UFPS
    13.  
    14.         }
    15.         else
    16.         {
    17.             FindObjectOfType<FPFreezePlayer>().Freeze(); //take control from UFPS
    18.             Panel.SetActive(true);
    19.             audio.PlayOneShot(OpenBag);
    20.         }
    21.     }
     
  43. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    It looks like that should work.

    Do you have an EventSystem in your scene?

    (I'm logging off for the day, but I'll check back in the morning.)
     
  44. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    No I didn't totally spaced the event triggers would need something to interact with :p So I added one now when I hover over the buttons they toggle the button look indicating my mouse is over, and I can bring up the action menu; it is however offset to the right and click any of the buttons on the screen at all still does nothing except change mouse over look, see below. Also have a good night :)

     
  45. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    UPDATE: rather than continuing to struggle I went ahead and ditched my custom setup and copied the INVCanvas and and sinventoryc# from the demo c scene and got it working; I wish the save/load was read/write and done with an MYSQL DB, from running WoW servers I would be more familiar with that :p at least I think I would.
     
    Last edited: Jan 25, 2015
  46. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    I tried adding this now that other things are slowly working and changed InvManager to InventoryManager as that is the new script name and InvManager does not exist.

    I get this error though;

    Error CS0176: Static member `UnityEngine.GameObject.Find(string)' cannot be accessed with an instance reference, qualify it with a type name instead (CS0176) (Assembly-CSharp)
     
  47. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Can you post the line that's reporting that error, including a few lines above it for context?
     
  48. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    Here is all of the code it is rather small so I figured I would post the whole thing

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class vp_PlayerDefineItem : MonoBehaviour {
    4.  
    5.     void OnEnable() {
    6.         GetComponentInChildren<InventoryEvents>().PlayerEquippedItem += OnEquip;
    7.     }
    8.  
    9.     void OnDisable() {
    10.         GetComponentInChildren<InventoryEvents>().PlayerEquippedItem -= OnEquip;
    11.     }
    12.  
    13.     void OnEquip(string ItemName) {
    14. //this var item line is the one that causes the error
    15.         var item = GetComponentInChildren<InventoryManager>().gameObject.Find(ItemName);
    16.         var weaponNumber = item.GetComponent<vp_ItemDefineNumber>().weaponNumber;
    17.         GetComponent<vp_FPPlayerEventHandler>().SetWeapon.TryStart(weaponNumber);
    18.     }
    19. }
    20.  
     
  49. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,706
    Sorry, should've been "transform", not "gameObject" in the original post. Try:
    Code (csharp):
    1. var item = GetComponentInChildren<InventoryManager>().transform.Find(ItemName);
     
  50. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    well....that now does something....but more or less it is doing a spawn, it just "drops" like when you choose drop from action menu....I am looking for 1 of 2 things, either A.) set an empty container in the hand of the player and whatever item you equip goes there, or B.) making it when equipped be in ufps inventory (I can make separate models for each item to be held) and then when unequipped it removes it from ufps inventory....also on a side note did I miss anywhere is there a way to drag out the inventory window to drop an item?
     
Thread Status:
Not open for further replies.