Unity Inventory System Plug-in - Ultimate Inventory System (2) Custom Items


foreword

This article is about customizing items. We will explore together how to customize various items and make synthesis; the article is a bit long, because there is a lot to say in this section, and you can watch the parts you need as appropriate.
In the previous article, we have a general understanding of the functions and simple use of the inventory system. We all use the sample templates for the item part. As independent game developers, to realize the strange ideas in our minds, we must customize them freely. OK; after all, solo travel relies on innovation, and it is likely to abandon the blood and blue bars of traditional games and integrate new and interesting gameplay to attract players.


1. Preparatory work (inventory type definition)

0. Thinking about the design idea, I decided to choose the Xianxia category. Item types are divided into the following 5 categories, currency 4 categories, forging and elixir synthesis formulas to be determined. (Well, I haven't thought about it yet, I guess I'll think about it when I write it)
insert image description here
1. Prepare a large number of related item icons for future use. If you can't find it, you can go to the unity store for free materials .
2. Open the toolbar Tools -> Opsive -> Ultimate Inventory System -> Main Manager (hereinafter referred to as Main Manager), click New to create an empty inventory (because it is new, you need to create the scene again, if you find it troublesome, take the first Create an example of an article, if you encounter problems, refer to the fifth part or leave a message).
insert image description here
Note that the UI also needs to be generated. To avoid problems, you can delete the Demo folder of the plugin first, and the examples in the previous chapter can also be deleted. Note that before deleting, find the ExampleMove script and the two prefabs on the Equipment Item View Slots Container and move them to your own project prefab folder, and there will be no error when the regeneration is achieved.
insert image description here
insert image description here

Next, click to generate the folder shown in the figure below, and finally click Spawn In Scene to instantiate the UI in the scene.
insert image description here

3. Click the Item Categories item type here, the default is uncategorized and all two types. Add the type we need as shown in the picture (it’s okay to try it in Chinese, I don’t know if there are other coding problems, if it’s a formal project, it’s recommended to use English; let me bear all this here, haha).
insert image description here
4. Overview of item definition interface
In actual projects, items of the same type will have the same attributes, which is human nature; and the implementation method is usually done by using c# inheritance. One parent class allows multiple subclasses to inherit, logic The code will also be much easier, which can greatly reduce the workload.
Therefore, the plugin also provides this kind of operation. We can not only create the general type attribute to let the subordinate item types inherit, but also remove it freely (provide multiple ways to remove the inherited attribute of the subordinate item type or not to remove it), making the project more flexible .
insert image description here
5. Create an item type
ok. After knowing so much, let’s create an indispensable attribute for All—the type icon.
Each attribute has three ways for everyone to use, as shown in the figure below; we use I, O, M to abbreviate them, why? Look at the two small pink icons in front of the type icon attribute is its abbreviation, I is inheritance, O is rewriting, M is modification, the most important thing to pay attention to is modification, we can superimpose the properties of the parent class, for example: the parent class is the blood return class 10 points of blood, the small return blood pill returns 1 blood to the parent , and the large return returns 5 blood to the parent, which is very practical (the second part elaborates).
![
Add two more descriptions and icons required by the item. Note that the attribute name cannot be repeated; if the above picture uses "icon" as the category attribute, then "icon" cannot be used here.
insert image description here
Next, select one of the categories, as shown in the figure below, Parents select All (equivalent to inheriting the attributes of All)
insert image description here
successfully! For the inherited attributes, it is displayed as the pink color of All, and the small pink icon of I represents the "inheritance" we choose by default. At this time, if the parent class is deleted, the icon will change to its own green color.
insert image description here
6. Add and delete precautions
If we add any attribute in the parent class All, we will find that the subclass will add the attribute accordingly. When we accidentally add it or need to delete it, we have three options. Delete it from the parent class, and the attribute of the subclass will remain as its own. Colors also become their own shades. Deleting from the relationship graph and everywhere is currently the same, and subclasses will clear this property at the same time.
insert image description here
7. Skill: left and right mutual blog
The defined attributes can be switched back and forth under several large attribute categories, which also explains the above problem: why can't there be attributes with the same name under several large attribute categories.
insert image description here

Summary: We have learned to add types and types of attributes, and then we need to create modular types, such as "upgradable" types, "store" types, "sellable" types, etc.; it is convenient for us to directly add when creating items in the future The parent class can quickly realize most of the attributes of a certain item. Since different projects have different requirements, please create it yourself, and we will not expand it here.

2. Item definition

First of all, let me explain why the item type and item definition are separated. Generally speaking, we need to determine 90% of the basic content at the beginning of the project, and the type definition belongs to a module of the overall structure; Many, separated individually to show her importance. In addition, brick experts suggest that only a small amount of modification should be made after the type is determined.
1. Create items
Open Item Definitions, create two magic weapons and consumables, and set Item Category to the type we created earlier.
insert image description here
The settings are as shown in the figure below. After reading it, I believe everyone understands the meaning and color of the small icons I and C. Clicking this small icon will jump to the place where the attribute is defined, which is similar to the F12 of VS. Wonderful, the relevant explanation will not be explained later. Next, everyone is free to play, add icons and descriptions, and rewrite them as exclusive to the item; if there are health points, this can also be done in the same way.
insert image description here

2. Set the property of the item
. We want to set the property of Juqi Powder to 10, and if the Lingqi Pill is more advanced, it is 5 times that of Juqi Powder.
The prerequisites are as follows, consumables need at least one attribute - here it is Reiki. Qi
insert image description here
Gathering Powder is set to rewrite
insert image description here
, and the value of Reiki is 10 points <Inherited> * 5. Documents , customizable properties)
insert image description here
3. Built-in properties of items

mutable: The mutable item class sets its direct item as mutable. Mutable items can change property values ​​at runtime. By making the item class immutable, we can assume that it will not change after the item is created. This improves memory usage by having a single item instance instead of multiple items.
unique: The unique item category sets its immediate item as unique. Unique items do not stack in the default item collection. Mutable common (non-unique) items will be merged with similar items when added to the items collection, which may lose property values.
Abstract: Abstract categories do not appear as options for the Item Definition category. The purpose of abstract classes is to organize project definitions in a clean way.

insert image description here

For example, if the material is a property that we want to be able to stack, we can set it to be immutable and non-unique.

3. Currency system

The currency system is very simple, just deal with the conversion relationship; the following three figures are examples of mutual exchange, Base Exchange Rate is the conversion ratio, and Overflow Currency is the overflow currency. If you have special needs, you can change it to make it a single conversion.
insert image description here
insert image description here
insert image description here

4. Item production

Objective: To make flying swords, flying swords need 5 iron essences to synthesize, and iron essences need 2 irons to synthesize
1. Create materials and material types
Create material types
insert image description here

Creates two materials, iron and iron ore.
insert image description here

2. Open the Crafting Categories process category (commonly known as recipes)
and briefly explain that the process belongs to a large category, so there is no parent category constraint. The types are Recipe and Recipe with Currency respectively.
insert image description here
Although there is no parent class constraint, for the convenience of classification, we create three categories: "All Recipes", "Default Recipes", and "Recipes with Currency", and set the Parent of the latter two recipes to "All Recipes". By the way, all recipes are set as abstract as shown in the figure below, and the properties of the recipe are set to the corresponding type, refer to the type description in the above figure.
insert image description here

3. Create a flying sword recipe and set Category as the default recipe.
insert image description here
Add the materials Iron Essence + Sword Embryo, and then open the store to see if it can be synthesized.
As for the synthesis of 1 iron essence by several irons, I will not elaborate too much. You can add money or spirit stones to see the difference between the two.

As an aside, specific materials can be synthesized into equipment, but abstract ones, of course, can also be used.
insert image description here

5. Problem Summary

1. The problem of prefab reference confusion
Many new prefabs will refer to the original prefab, which will cause considerable trouble during use, so it is best to click the Spawn In Scene button to generate the UI after performing the following operations.
Find the Classic Schema Full Layout prefab in your new inventory management, find the grid components inside and drag it into your new inventory prefab
insert image description here

In the Classic Schema Full Layout, search for Monitor, add or modify the currency type,
insert image description here
insert image description here
modify the store-related prefab reference problem,
insert image description here
open the Item View For Shop prefab to modify the currency,
insert image description hereand finally in the Classic Schema Full Layout, search for Monitor, add or modify the currency type
insert image description here

2. Adding Currency Attributes
After currency is added, we can set the corresponding currency attributes for the item to make the item have value, just add the CurrencyAmounts attribute as shown in the figure below.
insert image description here
Hey, it’s not over yet, we add sales and purchase values ​​to the consumables category; then assign values ​​to the attributes of the drug solution and modify the
insert image description here
attributes of the store to our field attributes-purchase value/sales value, the modifier below is a multiple correction, we fill in 1
insert image description here
Add Reiki Scatter and Gathering Scatter to the store, run the store, well, except for some UI adaptation issues, everything else is normal - the reason is because the maximum number of samples is 99. We can also make the conversion of 99 or change the UI.
insert image description here


Summarize

OK, the custom item article is basically completed. Um, why do I say basic, because there are not 4 pieces of content now. Considering that some content may not be involved, the fifth piece may be updated in the future. (It may be about skills. The current content covers 90% of the daily use functions, so don’t worry about it.)
Preview: View chapter includes items such as floating panel, quantity overflow, right-click expansion function menu, etc., character item slot settings, store backpack Categorize, sort, search, drag and drop; by the way, there are multiple and different store settings. Not much nonsense, see you in the next chapter on custom views.

Guess you like

Origin blog.csdn.net/qq_41912124/article/details/129811060