/// <summary> /// Remove the view type at the list index. /// </summary> private void OnViewTypeListRemove(ReorderableList list) { var viewTypes = new List <ViewType>(m_CameraController.ViewTypes); // Select a new view type if the currently selected view type is being removed. var removedSelected = viewTypes[list.index].GetType().FullName == m_CameraController.ViewTypeFullName; var viewTypeFullName = viewTypes[list.index].GetType().FullName; // Remove the element. InspectorUtility.RecordUndoDirtyObject(target, "Change Value"); // Allow the ability to perform any destruction. var viewType = viewTypes[list.index]; var inspectorDrawer = InspectorDrawerUtility.InspectorDrawerForType(viewType.GetType()) as ViewTypeInspectorDrawer; if (inspectorDrawer != null) { inspectorDrawer.ViewTypeRemoved(viewType, target); } viewTypes.RemoveAt(list.index); m_CameraController.ViewTypes = viewTypes.ToArray(); // Update the default first/third view type. if (m_CameraController.FirstPersonViewTypeFullName == viewTypeFullName) { m_CameraController.FirstPersonViewTypeFullName = string.Empty; UpdateDefaultViewTypes(); } else if (m_CameraController.ThirdPersonViewTypeFullName == viewTypeFullName) { m_CameraController.ThirdPersonViewTypeFullName = string.Empty; UpdateDefaultViewTypes(); } SerializeViewTypes(); // Don't show the remove button if there is only one view type left. list.displayRemove = m_CameraController.ViewTypes.Length > 1; // Update the index to point to no longer point to the now deleted view type. list.index = list.index - 1; if (list.index == -1 && viewTypes.Count > 0) { list.index = 0; } if (removedSelected) { m_CameraController.ViewTypeFullName = viewTypes[list.index].GetType().FullName; } EditorPrefs.SetInt(SelectedViewTypeIndexKey, list.index); // The view type's state list should start out fresh to prevent the old view type states from being shown. m_ReorderableViewTypeStateList = null; }
/// <summary> /// Adds the view type with the specified type. /// </summary> private void AddViewType(object obj) { var viewType = ViewTypeBuilder.AddViewType(m_CameraController, obj as Type); m_ReorderableViewTypeList.displayRemove = m_CameraController.ViewTypes.Length > 1; // Select the newly added view type. m_ReorderableViewTypeList.index = m_CameraController.ViewTypes.Length - 1; EditorPrefs.SetInt(SelectedViewTypeIndexKey, m_ReorderableViewTypeList.index); // The view type's state list should start out fresh to prevent the old view type states from being shown. m_ReorderableViewTypeStateList = null; // Allow the view type to perform any initialization. var inspectorDrawer = InspectorDrawerUtility.InspectorDrawerForType(viewType.GetType()) as ViewTypeInspectorDrawer; if (inspectorDrawer != null) { inspectorDrawer.ViewTypeAdded(viewType, target); } }