- Home /
Question by
Cruzer19993 · Dec 05, 2016 at 07:32 AM ·
assetinventory systemproblem during runtimecrafting
The imported type 'Inventory' is defined multiple times :<<<<
Hi i got problem with this code.The error is The imported type 'Inventory' is defined multiple times.Anybody have idea to resolve that problem . I dont got 2 files with that script.\
Here`s the code:
using UnityEngine; using System.Collections; using UnityEditor; using UnityEngine.UI; using UnityEngine.EventSystems;
[CustomEditor(typeof(Inventory))] public class InventoryEditor : Editor { Inventory inf;
SerializedProperty inventoryHeight;
SerializedProperty inventoryWidth;
SerializedProperty inventorySlotSize;
SerializedProperty inventoryIconSize;
SerializedProperty inventoryStackable;
SerializedProperty mainInventory;
SerializedProperty slotsPaddingBetweenX;
SerializedProperty slotsPaddingBetweenY;
SerializedProperty slotsPaddingLeft;
SerializedProperty slotsPaddingRight;
SerializedProperty slotsPaddingTop;
SerializedProperty slotsPaddingBottom;
SerializedProperty positionNumberX;
SerializedProperty positionNumberY;
private bool showStackableItems;
private bool showInventorySettings = true;
private bool showInventoryPadding = false;
private bool showStackableItemsSettings = false;
private int itemID;
private int itemValue = 1;
private int imageTypeIndex;
void OnEnable()
{
inf = target as Inventor;
inventoryHeight = serializedObject.FindProperty("height");
inventoryWidth = serializedObject.FindProperty("width");
inventorySlotSize = serializedObject.FindProperty("slotSize");
inventoryIconSize = serializedObject.FindProperty("iconSize");
slotsPaddingBetweenX = serializedObject.FindProperty("paddingBetweenX");
slotsPaddingBetweenY = serializedObject.FindProperty("paddingBetweenY");
slotsPaddingLeft = serializedObject.FindProperty("paddingLeft");
slotsPaddingRight = serializedObject.FindProperty("paddingRight");
slotsPaddingTop = serializedObject.FindProperty("paddingTop");
slotsPaddingBottom = serializedObject.FindProperty("paddingBottom");
inventoryStackable = serializedObject.FindProperty("stackable");
positionNumberX = serializedObject.FindProperty("positionNumberX");
positionNumberY = serializedObject.FindProperty("positionNumberY");
mainInventory = serializedObject.FindProperty("mainInventory");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
GUILayout.BeginVertical("Box");
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(mainInventory, new GUIContent("Player Inventory"));
if (EditorGUI.EndChangeCheck())
{
inf.setAsMain();
}
GUILayout.EndVertical();
GUILayout.BeginVertical("Box");
EditorGUI.indentLevel++;
GUILayout.BeginVertical("Box");
showInventorySettings = EditorGUILayout.Foldout(showInventorySettings, "Inventory Settings");
if (showInventorySettings)
{
sizeOfInventoryGUI();
}
GUILayout.EndVertical();
if (!inf.characterSystem())
{
GUILayout.BeginVertical("Box");
showStackableItemsSettings = EditorGUILayout.Foldout(showStackableItemsSettings, "Stacking/Splitting");
if (showStackableItemsSettings)
{
stackableItemsSettings();
GUILayout.Space(20);
}
GUILayout.EndVertical();
}
EditorGUI.indentLevel--;
GUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
SceneView.RepaintAll();
GUILayout.BeginVertical("Box");
addItemGUI();
GUILayout.EndVertical();
}
void stackableItemsSettings()
{
EditorGUILayout.PropertyField(inventoryStackable, new GUIContent("Splitting/Stacking"));
if (inventoryStackable.boolValue)
{
EditorGUI.indentLevel++;
showStackableItems = EditorGUILayout.Foldout(showStackableItems, "StackNumberPosition");
if (showStackableItems)
{
inventoryStackable.boolValue = true;
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
positionNumberX.intValue = EditorGUILayout.IntSlider("Position X:", positionNumberX.intValue, -(inventorySlotSize.intValue / 2), inventorySlotSize.intValue / 2);
positionNumberY.intValue = EditorGUILayout.IntSlider("Position Y:", positionNumberY.intValue, -(inventorySlotSize.intValue / 2), inventorySlotSize.intValue / 2);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
inf.stackableSettings();
}
}
else
{
inf.stackableSettings();
}
EditorGUI.indentLevel--;
}
else
{
inf.stackableSettings();
}
}
void sizeOfInventoryGUI()
{
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.IntSlider(inventoryHeight, 1, 10, new GUIContent("Height"));
EditorGUILayout.IntSlider(inventoryWidth, 1, 10, new GUIContent("Width"));
if (EditorGUI.EndChangeCheck())
{
inf.setImportantVariables();
inf.updateSlotAmount();
inf.adjustInventorySize();
inf.updatePadding(slotsPaddingBetweenX.intValue, slotsPaddingBetweenY.intValue);
inf.updateSlotSize(inventorySlotSize.intValue);
inf.stackableSettings();
}
EditorGUI.BeginChangeCheck();
EditorGUILayout.IntSlider(inventorySlotSize, 20, 100, new GUIContent("Slot Size")); //intfield for the slotsize
if (EditorGUI.EndChangeCheck()) //if intfield got changed
{
inf.setImportantVariables();
inf.adjustInventorySize();
inf.updateSlotSize(inventorySlotSize.intValue);
}
EditorGUI.BeginChangeCheck();
EditorGUILayout.IntSlider(inventoryIconSize, 20, 100, new GUIContent("Icon Size")); //intfield for the slotsize
if (EditorGUI.EndChangeCheck()) //if intfield got changed
{
inf.updateIconSize(inventoryIconSize.intValue);
}
GUILayout.BeginVertical("Box");
showInventoryPadding = EditorGUILayout.Foldout(showInventoryPadding, "Padding");
if (showInventoryPadding)
{
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
slotsPaddingLeft.intValue = EditorGUILayout.IntField("Left:", slotsPaddingLeft.intValue);
slotsPaddingRight.intValue = EditorGUILayout.IntField("Right:", slotsPaddingRight.intValue);
slotsPaddingBetweenX.intValue = EditorGUILayout.IntField("Spacing X:", slotsPaddingBetweenX.intValue);
slotsPaddingBetweenY.intValue = EditorGUILayout.IntField("Spacing Y:", slotsPaddingBetweenY.intValue);
slotsPaddingTop.intValue = EditorGUILayout.IntField("Top:", slotsPaddingTop.intValue);
slotsPaddingBottom.intValue = EditorGUILayout.IntField("Bottom:", slotsPaddingBottom.intValue);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
inf.adjustInventorySize();
inf.updatePadding(slotsPaddingBetweenX.intValue, slotsPaddingBetweenY.intValue);
}
}
GUILayout.EndVertical();
EditorGUI.indentLevel--;
}
void addItemGUI() //add a item to the inventory through the inspector
{
if (!inf.characterSystem())
{
GUILayout.Label("Add an item:");
inf.setImportantVariables(); //space to the top gui element
EditorGUILayout.BeginHorizontal(); //starting horizontal GUI elements
ItemDataBaseList inventoryItemList = (ItemDataBaseList)Resources.Load("ItemDatabase"); //loading the itemdatabase
string[] items = new string[inventoryItemList.itemList.Count]; //create a string array in length of the itemcount
for (int i = 1; i < items.Length; i++) //go through the item array
{
items[i] = inventoryItemList.itemList[i].itemName; //and paste all names into the array
}
itemID = EditorGUILayout.Popup("", itemID, items, EditorStyles.popup); //create a popout with all itemnames in it and save the itemID of it
itemValue = EditorGUILayout.IntField("", itemValue, GUILayout.Width(40));
GUI.color = Color.green; //set the color of all following guielements to green
if (GUILayout.Button("Add Item")) //creating button with name "AddItem"
{
inf.addItemToInventory(itemID, itemValue); //and set the settings for possible stackedItems
inf.stackableSettings();
}
inf.OnUpdateItemList();
EditorGUILayout.EndHorizontal(); //end the horizontal gui layout
}
}
}
Comment