Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEditor;

namespace SerializeReferenceEditor.Editor.SRActions
{
public class CopyPropertySRAction : BaseSRAction
{
public CopyPropertySRAction(SerializedProperty currentProperty, SerializedProperty parentProperty)
: base(currentProperty, parentProperty)
{
}

protected override void DoApply()
{
SRClipboard.ManagedReferenceValue = Property.managedReferenceValue;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEditor;

namespace SerializeReferenceEditor.Editor.SRActions
{
public class CutPropertySRAction : BaseSRAction
{
public CutPropertySRAction(SerializedProperty currentProperty, SerializedProperty parentProperty)
: base(currentProperty, parentProperty)
{
}

protected override void DoApply()
{
Undo.RegisterCompleteObjectUndo(Property.serializedObject.targetObject, "Cut element");
Undo.FlushUndoRecordObjects();

SRClipboard.ManagedReferenceValue = Property.managedReferenceValue;
Property.managedReferenceValue = null;
Property.serializedObject.ApplyModifiedProperties();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEditor;

namespace SerializeReferenceEditor.Editor.SRActions
{
public class PastePropertySRAction : BaseSRAction
{
public PastePropertySRAction(SerializedProperty currentProperty, SerializedProperty parentProperty)
: base(currentProperty, parentProperty)
{
}

protected override void DoApply()
{
if (!SRClipboard.HasValue)
return;

Undo.RegisterCompleteObjectUndo(Property.serializedObject.targetObject, "Paste element");
Undo.FlushUndoRecordObjects();

Property.managedReferenceValue = SRClipboard.ManagedReferenceValue;
Property.serializedObject.ApplyModifiedProperties();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ public InstanceClassSRAction InstantiateBuild(string type)

public ErasePropertySRAction EraseBuild()
=> new ErasePropertySRAction(_currentProperty, _parentProperty);

public CopyPropertySRAction CopyBuild()
=> new CopyPropertySRAction(_currentProperty, _parentProperty);

public PastePropertySRAction PasteBuild()
=> new PastePropertySRAction(_currentProperty, _parentProperty);

public CutPropertySRAction CutBuild()
=> new CutPropertySRAction(_currentProperty, _parentProperty);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SerializeReferenceEditor.Editor.SRActions
{
public static class SRClipboard
{
public static object ManagedReferenceValue { get; set; }

public static bool HasValue => ManagedReferenceValue != null;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,25 @@ private static List<SearchTreeEntry> GenerateSearchTreeEntries(
userData = srActionFactory.EraseBuild(),
level = 1
},
new(new GUIContent("Copy"))
{
userData = srActionFactory.CopyBuild(),
level = 1
},
new(new GUIContent("Paste"))
{
userData = srActionFactory.PasteBuild(),
level = 1
},
new(new GUIContent("Cut"))
{
userData = srActionFactory.CutBuild(),
level = 1
},
};
list.AddRange(srTypeTreeFactory.MakeTypesTree(srActionFactory));

return list;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
#if UNITY_EDITOR
using SerializeReferenceEditor.Services;
#endif

namespace SerializeReferenceEditor
{
Expand Down Expand Up @@ -87,4 +89,4 @@ public FormerlySerializedTypeAttribute(string oldTypeFullName)
}
#endif
}
}
}