Unity Editor工具-代码里复制Component

//CopyComponent

ublic static T CopyComponent<T>(T original, GameObject destination) where T : Component
    {
        Type type = original.GetType();
        Component copy = destination.AddComponent(type);
        System.Reflection.FieldInfo[] fields = type.GetFields();
        foreach (System.Reflection.FieldInfo field in fields)
        {
            field.SetValue(copy, field.GetValue(original));
        }
        return copy as T;
    }

 

posted @ 2018-01-19 14:08  MrBlue  阅读(858)  评论(0编辑  收藏  举报