I thought I would share it, because it’s very useful, for components in the scene or assets. (e.g : ruletiles or/and child class ruletiles)
Theses scripts can copy and paste properties through different classes of the same inheritance group (base / parent class).
Component Copy & Paste :
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
public static class ComponentUtil
{
static SerializedObject source;
[MenuItem("CONTEXT/Component/CopySerialized")]
public static void CopySerializedFromBase(MenuCommand command)
{ source = new SerializedObject(command.context); }
[MenuItem("CONTEXT/Component/PasteSerialized")]
public static void PasteSerializedFromBase(MenuCommand command)
{
SerializedObject dest = new SerializedObject(command.context);
SerializedProperty prop_iterator = source.GetIterator();
//jump into serialized object, this will skip script type so that we dont override the destination component's type
if (prop_iterator.NextVisible(true))
{
while (prop_iterator.NextVisible(true)) //itterate through all serializedProperties
{
//try obtaining the property in destination component
SerializedProperty prop_element = dest.FindProperty(prop_iterator.name);
//validate that the properties are present in both components, and that they're the same type
if (prop_element != null && prop_element.propertyType == prop_iterator.propertyType)
{
//copy value from source to destination component
dest.CopyFromSerializedProperty(prop_iterator);
}
}
}
dest.ApplyModifiedProperties();
}
}
#endif
From : http://answers.unity.com/answers/1538287/view.html
I adapted this code to match with assets:
Asset Copy & Paste :
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Security.Cryptography;
public static class ComponentUtil
{
static SerializedObject source;
[MenuItem("CONTEXT/Object/Copy Serialized Fields %#&c")]
public static void CopySerializedFromBase(MenuCommand command)
{
source = new SerializedObject(command.context);
}
[MenuItem("CONTEXT/Object/Paste Serialized Fields %#&v")]
public static void PasteSerializedFromBase(MenuCommand command)
{
SerializedObject dest = new SerializedObject(command.context);
SerializedProperty prop_iterator = source.GetIterator();
//jump into serialized object, this will skip script type so that we dont override the destination component's type
if (prop_iterator.NextVisible(true))
{
while (prop_iterator.Next(true)) //itterate through all serializedProperties
{
//try obtaining the property in destination component
SerializedProperty prop_element = dest.FindProperty(prop_iterator.name);
//validate that the properties are present in both components, and that they're the same type
if (prop_element != null && prop_element.propertyType == prop_iterator.propertyType)
{
//copy value from source to destination component
dest.CopyFromSerializedProperty(prop_iterator);
}
}
}
dest.ApplyModifiedProperties();
}
}
#endif
from : OrdinaryDev83
Hope it helps!