public virtual void Draw() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Center horizontally EditorGUILayout.BeginVertical(InventoryEditorStyles.boxStyle, GUILayout.MaxWidth(1000)); statsScrollPos = EditorGUILayout.BeginScrollView(statsScrollPos); #region Types picker EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Step 1: Pick the item types that you want to scan for character stats.", InventoryEditorStyles.titleStyle); EditorGUILayout.LabelField("Note: You only have to pick the top level classes.", InventoryEditorStyles.labelStyle); EditorGUILayout.LabelField("If EquippableInventoryItem extends from InventoryItemBase, you don't need to pick base. The system handles inheritance.", InventoryEditorStyles.labelStyle); EditorGUILayout.BeginVertical(InventoryEditorStyles.reorderableListStyle); typeList.DoLayoutList(); EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); #endregion EditorGUILayout.LabelField("Step 2: Scan the types for stats.", InventoryEditorStyles.titleStyle); if (GUILayout.Button("Scan types")) { var oldList = new List <InventoryEquipStat>(InventoryEditorUtil.selectedDatabase.equipStats); var displayList = new List <InventoryEquipStat>(64); foreach (var type in InventoryEditorUtil.selectedDatabase.equipStatTypes) { var fields = new List <FieldInfo>(); InventoryEditorUtil.GetAllFieldsInherited(System.Type.GetType(type, true), fields); foreach (var field in fields) { var attr = field.GetCustomAttributes(typeof(InventoryStatAttribute), true); if (attr.Length > 0) { var m = (InventoryStatAttribute)attr[0]; var old = oldList.FindAll(o => o.fieldInfoNameVisual == field.ReflectedType.Name + "." + field.Name); if (old.Count == 0) { displayList.Add(new InventoryEquipStat() { name = m.name, typeName = type, fieldInfoName = field.Name, fieldInfoNameVisual = field.ReflectedType.Name + "." + field.Name, show = false, category = "Default", formatter = InventoryEditorUtil.GetSettingsManager() != null ? InventoryEditorUtil.GetSettingsManager().defaultCharacterStatFormatter : null }); } else { // Item exists more than once. var already = displayList.Find(o => o.fieldInfoNameVisual == field.ReflectedType.Name + "." + field.Name); if (already == null) { displayList.Add(old[0]); } } } } } InventoryEditorUtil.selectedDatabase.equipStats = displayList.ToArray(); resultList.list = InventoryEditorUtil.selectedDatabase.equipStats; // Update list view } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Step 3: Choose what you want to display.", InventoryEditorStyles.titleStyle); EditorGUILayout.BeginVertical(InventoryEditorStyles.reorderableListStyle); resultList.DoLayoutList(); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
public void Draw() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Center horizontally scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, InventoryEditorStyles.boxStyle, GUILayout.MaxWidth(1000)); if (InventoryEditorUtil.GetSettingsManager() == null) { EditorGUILayout.LabelField("Settings are scene depended and require the Inventory managers."); EditorGUILayout.EndScrollView(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); return; } var prevWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 250; if (editor == null) { editor = Editor.CreateEditor(InventoryEditorUtil.GetSettingsManager()); } #region Path selector EditorGUILayout.LabelField("Items are saved as prefabs in a folder, this allows you to add components to objects and completely manage them.", InventoryEditorStyles.labelStyle); if (EditorPrefs.GetString("InventorySystem_ItemPrefabPath") == string.Empty) { GUI.color = Color.red; } EditorGUILayout.BeginHorizontal(InventoryEditorStyles.boxStyle); EditorGUILayout.LabelField("Inventory Item prefab folder: " + EditorPrefs.GetString("InventorySystem_ItemPrefabPath")); if (GUILayout.Button("Set path", GUILayout.Width(100))) { string path = EditorUtility.SaveFolderPanel("Choose a folder to save your item prefabs", "", ""); EditorPrefs.SetString("InventorySystem_ItemPrefabPath", "Assets" + path.Replace(Application.dataPath, "")); } EditorGUILayout.EndHorizontal(); GUI.color = Color.white; EditorGUILayout.Space(); EditorGUILayout.Space(); #endregion editor.DrawDefaultInspector(); EditorGUILayout.EndScrollView(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = prevWidth; if (GUI.changed) { EditorUtility.SetDirty(InventoryEditorUtil.selectedLangDatabase); // To make sure it gets saved. } }