public void Add(Item item) { InventoryItemDefinition itemDefinition = GameFoundationSdk.catalog.Find <InventoryItemDefinition>(item.DefinitionKey); InventoryItem inventoryItem = GameFoundationSdk.inventory.CreateItem(itemDefinition); Add(inventoryItem); Destroy(item.gameObject); }
private bool DefinitionDropAreaGUI(string message, CraftingRecipe pManager) { Event evt = Event.current; Rect drop_area = GUILayoutUtility.GetRect(0.0f, 60.0f, GUILayout.ExpandWidth(true)); GUI.Box(drop_area, "\n\n" + message, EditorStyles.helpBox); switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!drop_area.Contains(evt.mousePosition)) { return(false); } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (UnityEngine.Object dragged_object in DragAndDrop.objectReferences) { // Do On Drag Stuff here if (dragged_object.GetType().IsSubclassOf(typeof(InventoryItemDefinition)) || dragged_object.GetType() == typeof(InventoryItemDefinition)) { InventoryItemDefinition go = dragged_object as InventoryItemDefinition; if (go != null) { if (!pManager.Items.Exists(p => p.Item == go)) { pManager.Items.Add(new InventoryItemDefinitionCount() { Count = 1, Item = go }); return(true); } } } } } break; } return(false); }
/// <summary> /// this creates the inventory item in the UI. /// </summary> void InitInventoryItem(InventoryItem item) { var newItem = Instantiate(itemPrefab, Vector3.zero, Quaternion.identity, itemContainer); var itemData = newItem.GetComponent <InventoryItemView>(); if (itemData) { InventoryItemDefinition itemDefinition = GameFoundation.catalogs.inventoryCatalog.FindItem(item.definition.key); Sprite itemSprite = itemDefinition.GetDetail <AssetsDetail>()?.GetAsset <Sprite>(itemData.iconKey); itemData.SetLabel(item.definition.key); itemData.SetIcon(itemSprite); itemData.SetActionLabel(GetActionLabelByViewMode()); itemData.SetItem(item); mInventoryItemVIews.Add(itemData); } }
private bool GeneralDropAreaGUI(string message, SteamworksInventorySettings settings) { Event evt = Event.current; Rect drop_area = GUILayoutUtility.GetRect(0.0f, 70.0f, GUILayout.ExpandWidth(true)); var style = new GUIStyle(GUI.skin.box); style.normal.background = dropBoxTexture; style.normal.textColor = Color.white; style.border = new RectOffset(5, 5, 5, 5); var color = GUI.backgroundColor; var fontColor = GUI.contentColor; GUI.backgroundColor = SteamUtilities.Colors.SteamGreen * SteamUtilities.Colors.HalfAlpha; GUI.contentColor = SteamUtilities.Colors.BrightGreen; GUI.Box(drop_area, "\n\n" + message, style); GUI.backgroundColor = color; GUI.contentColor = fontColor; switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!drop_area.Contains(evt.mousePosition)) { return(false); } DragAndDrop.visualMode = DragAndDropVisualMode.Link; bool retVal = false; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (UnityEngine.Object dragged_object in DragAndDrop.objectReferences) { // Do On Drag Stuff here if (dragged_object.GetType().IsAssignableFrom(typeof(InventoryItemBundleDefinition))) { InventoryItemBundleDefinition go = dragged_object as InventoryItemBundleDefinition; if (go != null) { if (!settings.ItemBundles.Exists(p => p == go)) { settings.ItemBundles.Add(go); EditorUtility.SetDirty(settings); retVal = true; } } } else if (dragged_object.GetType().IsAssignableFrom(typeof(TagGeneratorDefinition))) { TagGeneratorDefinition go = dragged_object as TagGeneratorDefinition; if (go != null) { if (!settings.TagGenerators.Exists(p => p == go)) { settings.TagGenerators.Add(go); EditorUtility.SetDirty(settings); retVal = true; } } } else if (dragged_object.GetType().IsAssignableFrom(typeof(ItemGeneratorDefinition))) { ItemGeneratorDefinition go = dragged_object as ItemGeneratorDefinition; if (go != null) { if (!settings.ItemGenerators.Exists(p => p == go)) { settings.ItemGenerators.Add(go); EditorUtility.SetDirty(settings); retVal = true; } } } else if (dragged_object.GetType().IsSubclassOf(typeof(InventoryItemDefinition))) { InventoryItemDefinition go = dragged_object as InventoryItemDefinition; if (go != null) { if (!settings.ItemDefinitions.Exists(p => p == go)) { settings.ItemDefinitions.Add(go); EditorUtility.SetDirty(settings); retVal = true; } } } } } return(retVal); } return(false); }