Last active
February 11, 2021 18:25
-
-
Save karljj1/ccace256567c5a32c0422064d51d311b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEditor; | |
public class CopyPasteValues | |
{ | |
const string kBufferName = "json-copy-buffer"; | |
const string kTypeName = "json-copy-type"; | |
[MenuItem("CONTEXT/Component/Copy Values With Json")] | |
static void Copy(MenuCommand command) | |
{ | |
SessionState.SetString(kTypeName, command.context.GetType().AssemblyQualifiedName); | |
SessionState.SetString(kBufferName, EditorJsonUtility.ToJson(command.context)); | |
} | |
[MenuItem("CONTEXT/Component/Paste Values With Json")] | |
static void Paste(MenuCommand command) | |
{ | |
var json = SessionState.GetString(kBufferName, string.Empty); | |
EditorJsonUtility.FromJsonOverwrite(json, command.context); | |
} | |
[MenuItem("CONTEXT/Component/Paste Values With Json", validate = true)] | |
static bool PasteValidate(MenuCommand command) | |
{ | |
var json = SessionState.GetString(kBufferName, string.Empty); | |
var copyType = Type.GetType(SessionState.GetString(kTypeName, string.Empty), false); | |
var type = command.context.GetType(); | |
return !string.IsNullOrEmpty(json) && type != null && copyType.IsAssignableFrom(type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment