/// <summary> /// Draws the UI for existing item. /// </summary> private void DrawExistingItem() { EditorGUILayout.BeginHorizontal(); m_Item = EditorGUILayout.ObjectField("Item", m_Item, typeof(Item), true) as Item; GUI.enabled = m_Item != null; if (GUILayout.Button("Remove", GUILayout.Width(80))) { #if FIRST_PERSON_CONTROLLER var firstPersonVisibleItemObject = m_Item.GetComponent <UltimateCharacterController.FirstPersonController.Items.FirstPersonPerspectiveItem>(); if (firstPersonVisibleItemObject != null) { ItemBuilder.RemoveFirstPersonObject(firstPersonVisibleItemObject); } #endif var thirdPersonVisibleItemObject = m_Item.GetComponent <UltimateCharacterController.ThirdPersonController.Items.ThirdPersonPerspectiveItem>(); if (thirdPersonVisibleItemObject != null) { ItemBuilder.RemoveThirdPersonObject(thirdPersonVisibleItemObject); } // The ItemType should also be removed from the Inventory/ItemSetManager. var inventory = m_Item.GetComponentInParent <InventoryBase>(); if (inventory != null) { var defaultLoadout = new System.Collections.Generic.List <ItemTypeCount>(inventory.DefaultLoadout); for (int i = defaultLoadout.Count - 1; i > -1; --i) { if (defaultLoadout[i].ItemType == m_Item.ItemType) { defaultLoadout.RemoveAt(i); break; } } inventory.DefaultLoadout = defaultLoadout.ToArray(); EditorUtility.SetDirty(inventory); var itemSetManager = inventory.GetComponent <ItemSetManager>(); if (itemSetManager != null && m_Item.ItemType.CategoryIndices != null) { for (int i = 0; i < m_Item.ItemType.CategoryIndices.Length; ++i) { var category = itemSetManager.CategoryItemSets[i]; for (int j = category.ItemSetList.Count - 1; j > -1; --j) { if (category.ItemSetList[j].Slots[m_Item.SlotID] == m_Item.ItemType) { category.ItemSetList.RemoveAt(j); } } } EditorUtility.SetDirty(itemSetManager); } } Undo.DestroyObjectImmediate(m_Item.gameObject); m_Item = null; } GUI.enabled = m_Item != null; EditorGUILayout.EndHorizontal(); // Actions can be removed. if (m_Item != null) { var actions = m_Item.GetComponents <ItemAction>(); if (actions.Length > 0) { var actionStrings = new string[actions.Length]; for (int i = 0; i < actions.Length; ++i) { actionStrings[i] = InspectorUtility.DisplayTypeName(actions[i].GetType(), false); if (actions.Length > 1) { actionStrings[i] += " (ID " + actions[i].ID + ")"; } } EditorGUILayout.BeginHorizontal(); m_RemoveActionTypeIndex = EditorGUILayout.Popup("Remove Action", m_RemoveActionTypeIndex, actionStrings); if (GUILayout.Button("Remove", GUILayout.Width(80))) { ItemBuilder.RemoveAction(actions[m_RemoveActionTypeIndex]); m_RemoveActionTypeIndex = 0; } EditorGUILayout.EndHorizontal(); } } // Actions can be added. GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); m_AddActionType = (ItemBuilder.ActionType)EditorGUILayout.EnumPopup("Add Action", m_AddActionType); var canBuild = true; #if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER if (m_AddActionType == ItemBuilder.ActionType.ShootableWeapon) { EditorGUILayout.HelpBox("The shooter controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif #if !ULTIMATE_CHARACTER_CONTROLLER_MELEE if (m_AddActionType == ItemBuilder.ActionType.MeleeWeapon) { EditorGUILayout.HelpBox("The melee controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif if (canBuild && (m_AddActionType != ItemBuilder.ActionType.Shield)) { EditorGUI.indentLevel++; m_ExistingAddActionItemType = EditorGUILayout.ObjectField("Consumable Item Type", m_ExistingAddActionItemType, typeof(ItemType), false) as ItemType; EditorGUI.indentLevel--; } if (GUILayout.Button("Add", GUILayout.Width(80))) { ItemBuilder.AddAction(m_Item.gameObject, m_AddActionType, m_ExistingAddActionItemType); } EditorGUILayout.EndHorizontal(); GUI.enabled = m_Item != null && canBuild; #if FIRST_PERSON_CONTROLLER GUILayout.Space(5); // The first person objects can be added or removed. EditorGUILayout.LabelField("First Person", InspectorStyles.BoldLabel); EditorGUI.indentLevel++; FirstPersonController.Items.FirstPersonPerspectiveItem firstPersonVisibleItem = null; if (m_Item != null) { firstPersonVisibleItem = m_Item.GetComponent <FirstPersonController.Items.FirstPersonPerspectiveItem>(); GUI.enabled = firstPersonVisibleItem == null; if (firstPersonVisibleItem != null) { m_ExistingFirstPersonObject = firstPersonVisibleItem.Object; m_ExistingFirstPersonVisibleItem = firstPersonVisibleItem.VisibleItem; if (m_ExistingFirstPersonVisibleItem != null) { var firstPersonVisibleItemAnimator = firstPersonVisibleItem.VisibleItem.GetComponent <Animator>(); if (firstPersonVisibleItemAnimator != null) { m_ExistingFirstPersonVisibleItemAnimatorController = firstPersonVisibleItemAnimator.runtimeAnimatorController; } else { m_ExistingFirstPersonVisibleItemAnimatorController = null; } } else { m_ExistingFirstPersonVisibleItemAnimatorController = null; } } var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); DrawFirstPersonObject(character != null ? character.gameObject : null, ref m_ExistingFirstPersonObject, ref m_ExistingFirstPersonObjectAnimatorController, ref m_ExistingFirstPersonVisibleItem, ref m_ExistingFirstPersonParent, ref m_ExistingFirstPersonItemSlot, ref m_ExistingFirstPersonVisibleItemAnimatorController, m_ExistingThirdPersonItemSlot != null ? m_ExistingThirdPersonItemSlot.ID : 0, false, true); GUI.enabled = true; } EditorGUILayout.BeginHorizontal(); GUILayout.Space(InspectorUtility.IndentWidth); GUI.enabled = m_Item != null && firstPersonVisibleItem == null; if (GUILayout.Button("Add")) { var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); ItemBuilder.AddFirstPersonObject(character.gameObject, m_Item.name, m_Item.gameObject, ref m_ExistingFirstPersonObject, m_ExistingFirstPersonObjectAnimatorController, ref m_ExistingFirstPersonVisibleItem, m_ExistingFirstPersonItemSlot, m_ExistingFirstPersonVisibleItemAnimatorController); } GUI.enabled = m_Item != null && firstPersonVisibleItem != null; if (GUILayout.Button("Remove")) { ItemBuilder.RemoveFirstPersonObject(firstPersonVisibleItem); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; #endif // The third person objects can be added or removed. GUI.enabled = m_Item != null; GUILayout.Space(5); EditorGUILayout.LabelField("Third Person", InspectorStyles.BoldLabel); EditorGUI.indentLevel++; ThirdPersonController.Items.ThirdPersonPerspectiveItem thirdPersonVisibleItem = null; if (m_Item != null) { thirdPersonVisibleItem = m_Item.GetComponent <ThirdPersonController.Items.ThirdPersonPerspectiveItem>(); GUI.enabled = thirdPersonVisibleItem == null; if (thirdPersonVisibleItem != null) { m_ExistingThirdPersonObject = thirdPersonVisibleItem.Object; if (m_ExistingThirdPersonObject != null) { var thirdPersonAnimator = thirdPersonVisibleItem.Object.GetComponent <Animator>(); if (thirdPersonAnimator != null) { m_ExistingThirdPersonObjectAnimatorController = thirdPersonAnimator.runtimeAnimatorController; } else { m_ExistingThirdPersonObjectAnimatorController = null; } } else { m_ExistingThirdPersonObjectAnimatorController = null; } } var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); if (character == null || (character != null && character.GetComponent <Animator>() != null)) { DrawThirdPersonObject(character != null ? character.gameObject : null, ref m_ExistingThirdPersonObject, ref m_ExistingThirdHumanoidParentHand, ref m_ExistingThirdPersonParent, ref m_ExistingThirdPersonItemSlot, ref m_ExistingThirdPersonObjectAnimatorController, m_ExistingFirstPersonItemSlot != null ? m_ExistingFirstPersonItemSlot.ID : 0, false, true); } } EditorGUILayout.BeginHorizontal(); GUILayout.Space(InspectorUtility.IndentWidth); GUI.enabled = m_Item != null && thirdPersonVisibleItem == null; if (GUILayout.Button("Add")) { var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); ItemBuilder.AddThirdPersonObject(character.gameObject, m_Item.name, m_Item.gameObject, ref m_ExistingThirdPersonObject, m_ExistingThirdPersonItemSlot, m_ExistingThirdPersonObjectAnimatorController, m_InvisibleShadowCaster, false); } GUI.enabled = m_Item != null && thirdPersonVisibleItem != null; if (GUILayout.Button("Remove")) { ItemBuilder.RemoveThirdPersonObject(thirdPersonVisibleItem); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; GUI.enabled = m_Item != null; // Setup profiles. GUILayout.Space(5); EditorGUILayout.LabelField("State Profile", InspectorStyles.BoldLabel); EditorGUI.indentLevel++; var updatedStateConfiguration = EditorGUILayout.ObjectField("State Configuration", m_ExistingStateConfiguration, typeof(StateConfiguration), false) as StateConfiguration; if (updatedStateConfiguration != m_ExistingStateConfiguration) { if (updatedStateConfiguration != null) { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(updatedStateConfiguration))); } else { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, string.Empty); } m_ExistingStateConfiguration = updatedStateConfiguration; } if (m_ExistingStateConfiguration != null) { var profiles = m_ExistingStateConfiguration.GetProfilesForGameObject(m_Item == null ? null : m_Item.gameObject, StateConfiguration.Profile.ProfileType.Item); EditorGUILayout.BeginHorizontal(); var canSetup = true; if (profiles.Count == 0) { canSetup = false; profiles.Add("(None)"); } m_ExistingProfileIndex = EditorGUILayout.Popup("Profile", m_ExistingProfileIndex, profiles.ToArray()); GUI.enabled = m_Item != null && canSetup; if (GUILayout.Button("Apply")) { m_ExistingStateConfiguration.AddStatesToGameObject(profiles[m_ExistingProfileIndex], m_Item.gameObject); InspectorUtility.SetDirty(m_Item.gameObject); } GUI.enabled = m_Item != null; EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; }