/// <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--; }
/// <summary> /// Draws the popup for the camera view types. /// </summary> private void DrawCameraViewTypes() { // Draw the perspective. var selectedPerspective = (Perspective)EditorGUILayout.Popup("Perspective", (int)m_Perspective, m_PerspectiveNames); var isSupported = true; // Determine if the selected perspective is supported. #if !FIRST_PERSON_CONTROLLER if (selectedPerspective == Perspective.First || selectedPerspective == Perspective.Both) { EditorGUILayout.HelpBox("Unable to select the First Person Controller perspective. If you'd like to use a first person perspective ensure the " + "First Person Controller is imported.", MessageType.Error); isSupported = false; } #endif #if !THIRD_PERSON_CONTROLLER if (selectedPerspective == Perspective.Third || selectedPerspective == Perspective.Both) { EditorGUILayout.HelpBox("Unable to select the Third Person Controller perspective. If you'd like to use a third person perspective ensure the " + "Third Person Controller is imported.", MessageType.Error); isSupported = false; } #endif m_Perspective = selectedPerspective; m_CanCreateCamera = isSupported; if (!isSupported) { return; } // Show the available first person ViewTypes. if (m_Perspective == Perspective.First || m_Perspective == Perspective.Both) { var selectedViewType = -1; for (int i = 0; i < m_FirstPersonViewTypes.Count; ++i) { if (m_FirstPersonViewTypes[i].FullName == m_FirstPersonViewType) { selectedViewType = i; break; } } var viewType = selectedViewType == -1 ? 0 : selectedViewType; selectedViewType = EditorGUILayout.Popup("First Person View Type", viewType, m_FirstPersonViewTypeStrings); if (viewType != selectedViewType || string.IsNullOrEmpty(m_FirstPersonViewType)) { m_FirstPersonViewType = m_FirstPersonViewTypes[selectedViewType].FullName; } if (m_Perspective != Perspective.Both) { m_ThirdPersonViewType = string.Empty; } } // Show the available third person ViewTypes. if (m_Perspective == Perspective.Third || m_Perspective == Perspective.Both) { var selectedViewType = -1; for (int i = 0; i < m_ThirdPersonViewTypes.Count; ++i) { if (m_ThirdPersonViewTypes[i].FullName == m_ThirdPersonViewType) { selectedViewType = i; break; } } var viewType = selectedViewType == -1 ? 0 : selectedViewType; selectedViewType = EditorGUILayout.Popup("Third Person View Type", viewType, m_ThirdPersonViewTypeStrings); if (viewType != selectedViewType || string.IsNullOrEmpty(m_ThirdPersonViewType)) { m_ThirdPersonViewType = m_ThirdPersonViewTypes[selectedViewType].FullName; } if (m_Perspective != Perspective.Both) { m_FirstPersonViewType = string.Empty; } } if (m_Perspective == Perspective.Both) { m_StartFirstPersonPerspective = EditorGUILayout.Popup("Start Perspective", m_StartFirstPersonPerspective ? 0 : 1, new string[] { "First Person", "Third Person" }) == 0; } else { m_StartFirstPersonPerspective = (m_Perspective == Perspective.First); } // Show the possible base configurations. var updatedStateConfiguration = EditorGUILayout.ObjectField("State Configuration", m_StateConfiguration, typeof(StateConfiguration), false) as StateConfiguration; if (updatedStateConfiguration != m_StateConfiguration) { if (updatedStateConfiguration != null) { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(updatedStateConfiguration))); } else { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, string.Empty); } m_StateConfiguration = updatedStateConfiguration; } EditorGUI.indentLevel++; if (m_StateConfiguration != null) { var profiles = m_StateConfiguration.GetProfilesForGameObject(null, StateConfiguration.Profile.ProfileType.Camera); // The character can be added without any profiles. profiles.Insert(0, "(None)"); m_ProfileIndex = EditorGUILayout.Popup("Profile", m_ProfileIndex, profiles.ToArray()); m_ProfileName = profiles[m_ProfileIndex]; } EditorGUI.indentLevel--; GUILayout.Space(5); }
/// <summary> /// Draws the UI for new item. /// </summary> private void DrawNewItem() { var canBuild = true; m_Name = EditorGUILayout.TextField("Name", m_Name); if (string.IsNullOrEmpty(m_Name)) { canBuild = false; EditorGUILayout.HelpBox("The item must have a name.", MessageType.Error); } m_ItemType = EditorGUILayout.ObjectField("Item Type", m_ItemType, typeof(ItemType), false) as ItemType; if (canBuild && m_ItemType == null) { canBuild = false; EditorGUILayout.HelpBox("The item must specify an ItemType.", MessageType.Error); } var character = EditorGUILayout.ObjectField("Character", m_Character, typeof(GameObject), true) as GameObject; var characterUpdate = false; if (character != m_Character) { m_Character = character; characterUpdate = true; #if FIRST_PERSON_CONTROLLER // Try to assign the first person objects if they exist. if (m_Character != null) { var firstPersonObjects = m_Character.GetComponentInChildren <FirstPersonController.Character.FirstPersonObjects>(); if (firstPersonObjects != null) { var firstPersonBaseObject = firstPersonObjects.GetComponentInChildren <FirstPersonController.Character.Identifiers.FirstPersonBaseObject>(); if (firstPersonBaseObject != null) { m_FirstPersonObject = firstPersonBaseObject.gameObject; } } m_AddThirdPersonPerspective = m_Character.GetComponent <Animator>() != null; } #endif } if (m_Character == null) { m_SlotID = EditorGUILayout.IntField("Slot ID", m_SlotID); } else { if (EditorUtility.IsPersistent(m_Character)) { if (canBuild) { EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error); canBuild = false; } } else { // The attach to object must be a character already created. if (m_Character.GetComponentInChildren <ItemPlacement>() == null) { if (canBuild) { EditorGUILayout.HelpBox("The character must be an already created character.", MessageType.Error); canBuild = false; } } else { if (m_ItemType != null & m_Character.GetComponent <InventoryBase>() != null) { // The item can automatically be added to the default loadout if the inventory component exists. EditorGUI.indentLevel++; m_AddToDefaultLoadout = EditorGUILayout.Toggle("Add to Default Loadout", m_AddToDefaultLoadout); EditorGUI.indentLevel--; } else { m_AddToDefaultLoadout = false; } } } } m_AnimatorItemID = EditorGUILayout.IntField("Animator Item ID", m_AnimatorItemID); #if FIRST_PERSON_CONTROLLER GUILayout.Space(5); GUILayout.Label("First Person", InspectorStyles.BoldLabel); GUI.enabled = m_FirstPersonObject == null && m_FirstPersonVisibleItem == null; m_AddFirstPersonPerspective = EditorGUILayout.Toggle("Add First Person Item", m_AddFirstPersonPerspective); GUI.enabled = m_AddFirstPersonPerspective; var firstPersonSuccess = DrawFirstPersonObject(m_Character, ref m_FirstPersonObject, ref m_FirstPersonObjectAnimatorController, ref m_FirstPersonVisibleItem, ref m_FirstPersonParent, ref m_FirstPersonItemSlot, ref m_FirstPersonVisibleItemAnimatorController, m_ThirdPersonItemSlot != null ? m_ThirdPersonItemSlot.ID : 0, characterUpdate, canBuild && m_AddFirstPersonPerspective); GUI.enabled = true; if (m_AddFirstPersonPerspective && !firstPersonSuccess) { canBuild = false; } #endif if (m_Character == null || (m_Character != null && m_Character.GetComponent <Animator>() != null)) { GUILayout.Space(10); GUILayout.Label("Third Person (including AI and multiplayer)", InspectorStyles.BoldLabel); GUI.enabled = m_ThirdPersonObject == null; m_AddThirdPersonPerspective = EditorGUILayout.Toggle("Add Third Person Item", m_AddThirdPersonPerspective); GUI.enabled = m_AddThirdPersonPerspective; var thirdPersonSuccess = DrawThirdPersonObject(m_Character, ref m_ThirdPersonObject, ref m_ThirdHumanoidParentHand, ref m_ThirdPersonParent, ref m_ThirdPersonItemSlot, ref m_ThirdPersonObjectAnimatorController, m_FirstPersonItemSlot != null ? m_FirstPersonItemSlot.ID : 0, characterUpdate, canBuild && m_AddThirdPersonPerspective); GUI.enabled = true; if (m_AddThirdPersonPerspective && !thirdPersonSuccess) { canBuild = false; } } if (!m_AddFirstPersonPerspective && !m_AddThirdPersonPerspective) { if (canBuild) { EditorGUILayout.HelpBox("At least one perspective must be added.", MessageType.Error); canBuild = false; } } GUILayout.Space(15); m_ActionType = (ItemBuilder.ActionType)EditorGUILayout.EnumPopup("Action Type", m_ActionType); #if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER if (m_ActionType == ItemBuilder.ActionType.ShootableWeapon && canBuild) { EditorGUILayout.HelpBox("The shooter controller is necessary in order to create shootable weapons.", MessageType.Error); canBuild = false; } #endif #if !ULTIMATE_CHARACTER_CONTROLLER_MELEE if (m_ActionType == ItemBuilder.ActionType.MeleeWeapon && canBuild) { EditorGUILayout.HelpBox("The melee controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif #if FIRST_PERSON_CONTROLLER // The slot IDs must match. if (m_FirstPersonItemSlot != null && m_ThirdPersonItemSlot != null && m_FirstPersonItemSlot.ID != m_ThirdPersonItemSlot.ID && canBuild) { canBuild = false; EditorGUILayout.HelpBox("The first and third person ItemSlots must use the same ID.", MessageType.Error); } #endif if (canBuild && (m_ActionType != ItemBuilder.ActionType.Shield)) { EditorGUI.indentLevel++; m_ActionItemType = EditorGUILayout.ObjectField("Consumable Item Type", m_ActionItemType, typeof(ItemType), false) as ItemType; EditorGUI.indentLevel--; } // Setup profiles. GUILayout.Space(5); var updatedStateConfiguration = EditorGUILayout.ObjectField("State Configuration", m_AddStateConfiguration, typeof(StateConfiguration), false) as StateConfiguration; if (updatedStateConfiguration != m_AddStateConfiguration) { if (updatedStateConfiguration != null) { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(updatedStateConfiguration))); } else { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, string.Empty); } m_AddStateConfiguration = updatedStateConfiguration; } if (m_AddStateConfiguration != null) { EditorGUI.indentLevel++; var profiles = m_AddStateConfiguration.GetProfilesForGameObject(null, StateConfiguration.Profile.ProfileType.Item); if (profiles.Count > 0) { // The item can be added without any profiles. profiles.Insert(0, "(None)"); m_AddProfileIndex = EditorGUILayout.Popup("Profile", m_AddProfileIndex, profiles.ToArray()); m_AddProfileName = profiles[m_AddProfileIndex]; } EditorGUI.indentLevel--; } GUILayout.Space(5); GUI.enabled = canBuild; if (GUILayout.Button("Build Item")) { var item = ItemBuilder.BuildItem(m_Name, m_ItemType, m_AnimatorItemID, m_Character, m_SlotID, m_AddToDefaultLoadout, m_AddFirstPersonPerspective, m_FirstPersonObject, m_FirstPersonObjectAnimatorController, m_FirstPersonVisibleItem, m_FirstPersonItemSlot, m_FirstPersonVisibleItemAnimatorController, m_AddThirdPersonPerspective, m_ThirdPersonObject, m_ThirdPersonItemSlot, m_ThirdPersonObjectAnimatorController, m_InvisibleShadowCaster, m_ActionType, m_ActionItemType); // Setup any profiles on the item. if (m_AddStateConfiguration != null) { if (m_AddProfileIndex > 0) { m_AddStateConfiguration.AddStatesToGameObject(m_AddProfileName, item.gameObject); InspectorUtility.SetDirty(item.gameObject); } } // If the character is null then a prefab will be created. if (m_Character == null) { var path = EditorUtility.SaveFilePanel("Save Item", "Assets", m_Name + ".prefab", "prefab"); if (path.Length != 0 && Application.dataPath.Length < path.Length) { var relativePath = path.Replace(Application.dataPath, ""); #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(item, "Assets" + relativePath); #else PrefabUtility.CreatePrefab("Assets" + relativePath, item); #endif Object.DestroyImmediate(item, true); } } // Remove the original objects if they are in the scene - this will prevent duplicate objects from existing. if (m_FirstPersonVisibleItem != null && !EditorUtility.IsPersistent(m_FirstPersonVisibleItem) && (m_Character == null || !m_FirstPersonVisibleItem.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_FirstPersonVisibleItem, true); m_FirstPersonVisibleItem = null; } if (m_FirstPersonObject != null && !EditorUtility.IsPersistent(m_FirstPersonObject) && (m_Character == null || !m_FirstPersonObject.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_FirstPersonObject, true); m_FirstPersonObject = null; #if FIRST_PERSON_CONTROLLER // The base object should be updated to the new instance. var firstPersonObjects = m_Character.GetComponentInChildren <FirstPersonController.Character.FirstPersonObjects>(); if (firstPersonObjects != null) { var firstPersonBaseObject = firstPersonObjects.GetComponentInChildren <FirstPersonController.Character.Identifiers.FirstPersonBaseObject>(); if (firstPersonBaseObject != null) { m_FirstPersonObject = firstPersonBaseObject.gameObject; } } #endif } if (m_ThirdPersonObject != null && !EditorUtility.IsPersistent(m_ThirdPersonObject) && (m_Character == null || !m_ThirdPersonObject.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_ThirdPersonObject, true); m_ThirdPersonObject = null; } // Select the newly added item. Selection.activeGameObject = item.gameObject; } GUI.enabled = true; }