using UnityEngine; using System.Collections; #if UNITY_EDITOR using UnityEditor; [CustomEditor (typeof (inventoryBankManager), true)] public class inventoryBankManagerEditor : Editor { SerializedProperty gameSystemManager; SerializedProperty mainInventoryManager; SerializedProperty inventoryListManagerList; SerializedProperty bankInventoryList; SerializedProperty loadCurrentBankInventoryFromSaveFile; SerializedProperty saveCurrentBankInventoryToSaveFile; SerializedProperty useMaxInventoryBankSlotsAmount; SerializedProperty maxInventoryBankSlotsAmount; inventoryBankManager manager; int categoryIndex; int elementIndex; GUIStyle buttonStyle = new GUIStyle (); void OnEnable () { gameSystemManager = serializedObject.FindProperty ("gameSystemManager"); mainInventoryManager = serializedObject.FindProperty ("mainInventoryManager"); inventoryListManagerList = serializedObject.FindProperty ("inventoryListManagerList"); bankInventoryList = serializedObject.FindProperty ("bankInventoryList"); loadCurrentBankInventoryFromSaveFile = serializedObject.FindProperty ("loadCurrentBankInventoryFromSaveFile"); saveCurrentBankInventoryToSaveFile = serializedObject.FindProperty ("saveCurrentBankInventoryToSaveFile"); useMaxInventoryBankSlotsAmount = serializedObject.FindProperty ("useMaxInventoryBankSlotsAmount"); maxInventoryBankSlotsAmount = serializedObject.FindProperty ("maxInventoryBankSlotsAmount"); manager = (inventoryBankManager)target; } public override void OnInspectorGUI () { GUILayout.BeginVertical (GUILayout.Height (30)); EditorGUILayout.Space (); buttonStyle = new GUIStyle (GUI.skin.button); buttonStyle.fontStyle = FontStyle.Bold; buttonStyle.fontSize = 12; GUILayout.BeginVertical ("Main Inventory Elements", "window", GUILayout.Height (30)); EditorGUILayout.PropertyField (gameSystemManager); EditorGUILayout.PropertyField (mainInventoryManager); EditorGUILayout.Space (); EditorGUILayout.PropertyField (useMaxInventoryBankSlotsAmount); if (useMaxInventoryBankSlotsAmount.boolValue) { EditorGUILayout.PropertyField (maxInventoryBankSlotsAmount); } GUILayout.EndVertical (); EditorGUILayout.Space (); GUILayout.BeginVertical ("Inventory List Manager List", "window", GUILayout.Height (30)); showInventoryListManagerList (inventoryListManagerList); GUILayout.EndVertical (); EditorGUILayout.Space (); if (GUILayout.Button ("Get Inventory Manager List")) { manager.getInventoryListManagerList (); } EditorGUILayout.Space (); if (GUILayout.Button ("Set Inventory Object List Names")) { manager.setInventoryObjectListNames (); } EditorGUILayout.Space (); GUILayout.BeginVertical ("Bank Inventory List (DEBUG)", "window"); showInventoryList (bankInventoryList); GUILayout.EndVertical (); EditorGUILayout.Space (); GUILayout.BeginVertical ("Save/Load Bank Inventory Settings", "window", GUILayout.Height (30)); EditorGUILayout.PropertyField (loadCurrentBankInventoryFromSaveFile); EditorGUILayout.PropertyField (saveCurrentBankInventoryToSaveFile); EditorGUILayout.Space (); if (GUILayout.Button ("Save Inventory Bank List")) { manager.saveCurrentInventoryListToFile (); } EditorGUILayout.Space (); GUILayout.EndVertical (); GUILayout.EndVertical (); EditorGUILayout.Space (); if (GUI.changed) { serializedObject.ApplyModifiedProperties (); } } void showInventoryListElementInfo (SerializedProperty list, bool expanded, int index) { GUILayout.BeginVertical ("box"); EditorGUILayout.PropertyField (list.FindPropertyRelative ("Name")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("inventoryGameObject")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("objectInfo")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("icon")); GUILayout.BeginHorizontal (); GUILayout.Label ("Object Icon Preview \t"); GUILayout.BeginHorizontal ("box", GUILayout.Height (50), GUILayout.Width (50)); if (list.FindPropertyRelative ("icon").objectReferenceValue && expanded) { Object texture = list.FindPropertyRelative ("icon").objectReferenceValue as Texture2D; Texture2D myTexture = AssetPreview.GetAssetPreview (texture); GUILayout.Label (myTexture, GUILayout.Width (50), GUILayout.Height (50)); } GUILayout.EndHorizontal (); GUILayout.Label (""); GUILayout.EndHorizontal (); EditorGUILayout.PropertyField (list.FindPropertyRelative ("infiniteAmount")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("amount")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("amountPerUnit")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("canBeUsed")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("canBeEquiped")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("canBeDropped")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("canBeCombined")); if (list.FindPropertyRelative ("canBeCombined").boolValue) { EditorGUILayout.PropertyField (list.FindPropertyRelative ("objectToCombine")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("combinedObject")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("combinedObjectMessage")); } EditorGUILayout.PropertyField (list.FindPropertyRelative ("canBeDiscarded")); EditorGUILayout.Space (); EditorGUILayout.PropertyField (list.FindPropertyRelative ("vendorPrice")); EditorGUILayout.Space (); EditorGUILayout.PropertyField (list.FindPropertyRelative ("isWeapon")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("isArmorClothAccessory")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("canBeExamined")); EditorGUILayout.Space (); EditorGUILayout.PropertyField (list.FindPropertyRelative ("button")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("menuIconElement")); GUILayout.EndVertical (); } void showInventoryList (SerializedProperty list) { GUILayout.BeginVertical (); EditorGUILayout.Space (); if (GUILayout.Button ("Show/Hide Bank Inventory List", buttonStyle)) { list.isExpanded = !list.isExpanded; } EditorGUILayout.Space (); if (list.isExpanded) { EditorGUILayout.Space (); GUILayout.Label ("Number Of Objects: \t" + list.arraySize); EditorGUILayout.Space (); GUILayout.BeginHorizontal (); if (GUILayout.Button ("Expand All")) { for (int i = 0; i < list.arraySize; i++) { list.GetArrayElementAtIndex (i).isExpanded = true; } } if (GUILayout.Button ("Collapse All")) { for (int i = 0; i < list.arraySize; i++) { list.GetArrayElementAtIndex (i).isExpanded = false; } } GUILayout.EndHorizontal (); EditorGUILayout.Space (); for (int i = 0; i < list.arraySize; i++) { bool expanded = false; GUILayout.BeginHorizontal (); GUILayout.BeginHorizontal ("box"); EditorGUILayout.Space (); if (i < list.arraySize && i >= 0) { EditorGUILayout.BeginVertical (); SerializedProperty currentElement = list.GetArrayElementAtIndex (i); string amountValue = " - " + currentElement.FindPropertyRelative ("amount").intValue; EditorGUILayout.PropertyField (currentElement, new GUIContent (currentElement.displayName + amountValue), false); if (currentElement.isExpanded) { expanded = true; showInventoryListElementInfo (currentElement, expanded, i); } EditorGUILayout.Space (); GUILayout.EndVertical (); } GUILayout.EndHorizontal (); if (expanded) { GUILayout.BeginVertical (); } else { GUILayout.BeginHorizontal (); } if (GUILayout.Button ("x")) { list.DeleteArrayElementAtIndex (i); } if (GUILayout.Button ("v")) { if (i >= 0) { list.MoveArrayElement (i, i + 1); } } if (GUILayout.Button ("^")) { if (i < list.arraySize) { list.MoveArrayElement (i, i - 1); } } if (expanded) { GUILayout.EndVertical (); } else { GUILayout.EndHorizontal (); } GUILayout.EndHorizontal (); } } GUILayout.EndVertical (); } void showInventoryListManagerListElement (SerializedProperty list) { GUILayout.BeginVertical ("box"); EditorGUILayout.PropertyField (list.FindPropertyRelative ("Name")); EditorGUILayout.PropertyField (list.FindPropertyRelative ("infiniteAmount")); if (!list.FindPropertyRelative ("infiniteAmount").boolValue) { EditorGUILayout.PropertyField (list.FindPropertyRelative ("amount")); } if (manager != null && manager.inventoryManagerListString.Length > 0) { list.FindPropertyRelative ("categoryIndex").intValue = EditorGUILayout.Popup ("Category", list.FindPropertyRelative ("categoryIndex").intValue, manager.inventoryManagerListString); categoryIndex = list.FindPropertyRelative ("categoryIndex").intValue; if (categoryIndex < manager.inventoryManagerListString.Length) { list.FindPropertyRelative ("inventoryCategoryName").stringValue = manager.inventoryManagerListString [categoryIndex]; } if (manager.inventoryManagerStringInfoList.Count > 0) { list.FindPropertyRelative ("elementIndex").intValue = EditorGUILayout.Popup ("Inventory Object", list.FindPropertyRelative ("elementIndex").intValue, manager.inventoryManagerStringInfoList [categoryIndex].inventoryManagerListString); elementIndex = list.FindPropertyRelative ("elementIndex").intValue; if (elementIndex < manager.inventoryManagerStringInfoList [categoryIndex].inventoryManagerListString.Length) { list.FindPropertyRelative ("inventoryObjectName").stringValue = manager.inventoryManagerStringInfoList [categoryIndex].inventoryManagerListString [elementIndex]; } } } GUILayout.EndVertical (); } void showInventoryListManagerList (SerializedProperty list) { GUILayout.BeginVertical (); EditorGUILayout.Space (); if (GUILayout.Button ("Show/Hide Inventory Manager List", buttonStyle)) { list.isExpanded = !list.isExpanded; } EditorGUILayout.Space (); if (list.isExpanded) { EditorGUILayout.Space (); GUI.color = Color.cyan; EditorGUILayout.HelpBox ("Configure every inventory object of this Bank", MessageType.None); GUI.color = Color.white; EditorGUILayout.Space (); GUILayout.Label ("Number Of Objects: \t" + list.arraySize); EditorGUILayout.Space (); GUILayout.BeginHorizontal (); if (GUILayout.Button ("Add Object")) { manager.addNewInventoryObjectToInventoryListManagerList (); } if (GUILayout.Button ("Clear List")) { list.arraySize = 0; } GUILayout.EndHorizontal (); EditorGUILayout.Space (); GUILayout.BeginHorizontal (); if (GUILayout.Button ("Expand All")) { for (int i = 0; i < list.arraySize; i++) { list.GetArrayElementAtIndex (i).isExpanded = true; } } if (GUILayout.Button ("Collapse All")) { for (int i = 0; i < list.arraySize; i++) { list.GetArrayElementAtIndex (i).isExpanded = false; } } GUILayout.EndHorizontal (); EditorGUILayout.Space (); for (int i = 0; i < list.arraySize; i++) { bool expanded = false; GUILayout.BeginHorizontal (); GUILayout.BeginHorizontal ("box"); EditorGUILayout.Space (); if (i < list.arraySize && i >= 0) { EditorGUILayout.BeginVertical (); EditorGUILayout.PropertyField (list.GetArrayElementAtIndex (i), false); if (list.GetArrayElementAtIndex (i).isExpanded) { expanded = true; showInventoryListManagerListElement (list.GetArrayElementAtIndex (i)); } EditorGUILayout.Space (); GUILayout.EndVertical (); } GUILayout.EndHorizontal (); if (expanded) { GUILayout.BeginVertical (); } else { GUILayout.BeginHorizontal (); } if (GUILayout.Button ("x")) { list.DeleteArrayElementAtIndex (i); } if (GUILayout.Button ("v")) { if (i >= 0) { list.MoveArrayElement (i, i + 1); } } if (GUILayout.Button ("^")) { if (i < list.arraySize) { list.MoveArrayElement (i, i - 1); } } if (expanded) { GUILayout.EndVertical (); } else { GUILayout.EndHorizontal (); } GUILayout.EndHorizontal (); } } GUILayout.EndVertical (); } } #endif