// index is only used when we need to re-create a component in a specific spot (e.g. reset) void CreateEditor(VolumeComponent settings, SerializedProperty property, int index = -1, bool forceOpen = false) { var settingsType = settings.GetType(); Type editorType; if (!m_EditorTypes.TryGetValue(settingsType, out editorType)) { editorType = typeof(VolumeComponentEditor); } var editor = (VolumeComponentEditor)Activator.CreateInstance(editorType); editor.Init(settings, this); editor.baseProperty = property.Copy(); if (forceOpen) { editor.baseProperty.isExpanded = true; } if (index < 0) { m_Editors.Add(editor); } else { m_Editors[index] = editor; } }
static void CopySettings(VolumeComponent targetComponent) { string typeName = targetComponent.GetType().AssemblyQualifiedName; string typeData = JsonUtility.ToJson(targetComponent); EditorGUIUtility.systemCopyBuffer = $"{typeName}|{typeData}"; }
// index is only used when we need to re-create a component in a specific spot (e.g. reset) void CreateEditor(VolumeComponent component, SerializedProperty property, int index = -1, bool forceOpen = false) { var componentType = component.GetType(); if (RenderPipelineManager.currentPipeline != null) { if (componentType.GetCustomAttributes(typeof(VolumeComponentMenuForRenderPipeline), true) .FirstOrDefault() is VolumeComponentMenuForRenderPipeline volumeComponentMenuForRenderPipeline && !volumeComponentMenuForRenderPipeline.pipelineTypes.Contains(RenderPipelineManager.currentPipeline.GetType())) { return; } } var editor = (VolumeComponentEditor)Editor.CreateEditor(component); editor.inspector = m_BaseEditor; editor.baseProperty = property.Copy(); editor.Init(); if (forceOpen) { editor.baseProperty.isExpanded = true; } if (index < 0) { m_Editors.Add(editor); } else { m_Editors[index] = editor; } }
// index is only used when we need to re-create a component in a specific spot (e.g. reset) void CreateEditor(VolumeComponent component, SerializedProperty property, int index = -1, bool forceOpen = false) { var componentType = component.GetType(); Type editorType; if (!m_EditorTypes.TryGetValue(componentType, out editorType)) { editorType = typeof(VolumeComponentEditor); } var editor = (VolumeComponentEditor)Activator.CreateInstance(editorType); //custom-begin: malte: context reference for exposed property resolver editor.Init(component, m_SerializedObject.context, m_BaseEditor); //custom-end editor.baseProperty = property.Copy(); if (forceOpen) { editor.baseProperty.isExpanded = true; } if (index < 0) { m_Editors.Add(editor); } else { m_Editors[index] = editor; } }
void PasteSettings(VolumeComponent targetComponent) { Assert.IsNotNull(s_ClipboardContent); Assert.AreEqual(s_ClipboardContent.GetType(), targetComponent.GetType()); Undo.RecordObject(targetComponent, "Paste Settings"); EditorUtility.CopySerializedIfDifferent(s_ClipboardContent, targetComponent); }
void CopySettings(VolumeComponent targetComponent) { if (s_ClipboardContent != null) { CoreUtils.Destroy(s_ClipboardContent); s_ClipboardContent = null; } s_ClipboardContent = (VolumeComponent)CreateInstance(targetComponent.GetType()); EditorUtility.CopySerializedIfDifferent(targetComponent, s_ClipboardContent); }
static bool CanPaste(VolumeComponent targetComponent) { if (string.IsNullOrWhiteSpace(EditorGUIUtility.systemCopyBuffer)) { return(false); } string clipboard = EditorGUIUtility.systemCopyBuffer; int separator = clipboard.IndexOf('|'); if (separator < 0) { return(false); } return(targetComponent.GetType().AssemblyQualifiedName == clipboard.Substring(0, separator)); }
// Copy/pasting is simply done by creating an in memory copy of the selected component and // copying over the serialized data to another; it doesn't use nor affect the OS clipboard bool CanPaste(VolumeComponent targetComponent) { return(s_ClipboardContent != null && s_ClipboardContent.GetType() == targetComponent.GetType()); }
void OnContextClick(Vector2 position, VolumeComponent targetComponent, int id) { var menu = new GenericMenu(); if (id == 0) { menu.AddDisabledItem(CoreEditorUtils.GetContent("Move Up")); } else { menu.AddItem(CoreEditorUtils.GetContent("Move Up"), false, () => MoveComponent(id, -1)); } if (id == m_Editors.Count - 1) { menu.AddDisabledItem(CoreEditorUtils.GetContent("Move Down")); } else { menu.AddItem(CoreEditorUtils.GetContent("Move Down"), false, () => MoveComponent(id, 1)); } menu.AddSeparator(string.Empty); menu.AddItem(CoreEditorUtils.GetContent("Reset"), false, () => ResetComponent(targetComponent.GetType(), id)); menu.AddItem(CoreEditorUtils.GetContent("Remove"), false, () => RemoveComponent(id)); menu.AddSeparator(string.Empty); menu.AddItem(CoreEditorUtils.GetContent("Copy Settings"), false, () => CopySettings(targetComponent)); if (CanPaste(targetComponent)) { menu.AddItem(CoreEditorUtils.GetContent("Paste Settings"), false, () => PasteSettings(targetComponent)); } else { menu.AddDisabledItem(CoreEditorUtils.GetContent("Paste Settings")); } menu.AddSeparator(string.Empty); menu.AddItem(CoreEditorUtils.GetContent("Toggle All"), false, () => m_Editors[id].SetAllOverridesTo(true)); menu.AddItem(CoreEditorUtils.GetContent("Toggle None"), false, () => m_Editors[id].SetAllOverridesTo(false)); menu.DropDown(new Rect(position, Vector2.zero)); }