Skip to content

Instantly share code, notes, and snippets.

@Novack
Forked from karljj1/CopyPasteValues.cs
Created May 27, 2020 12:53
Show Gist options
  • Save Novack/cbe8061de18a2d73ef678216ce9ab77c to your computer and use it in GitHub Desktop.
Save Novack/cbe8061de18a2d73ef678216ce9ab77c to your computer and use it in GitHub Desktop.
using System;
using UnityEditor;
using UnityEngine;
public class CopyPasteValues
{
static string copyBuffer;
static Type copyType;
[MenuItem("CONTEXT/Component/Copy Values With Json")]
static void Copy(MenuCommand command)
{
copyType = command.context.GetType();
copyBuffer = EditorJsonUtility.ToJson(command.context);
}
[MenuItem("CONTEXT/Component/Paste Values With Json")]
static void Paste(MenuCommand command)
{
EditorJsonUtility.FromJsonOverwrite(copyBuffer, command.context);
}
[MenuItem("CONTEXT/Component/Paste Values With Json", validate = true)]
static bool PasteValidate(MenuCommand command)
{
var type = command.context.GetType();
return !string.IsNullOrEmpty(copyBuffer) && copyType != null && copyType.IsAssignableFrom(type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment