public static Texture2D CreatePreviewForAsset(UnityEngine.Object obj, UnityEngine.Object[] subAssets, string assetPath)
        {
            if (obj == null)
            {
                return(null);
            }
            System.Type type = CustomEditorAttributes.FindCustomEditorType(obj, false);
            if (type == null)
            {
                return(null);
            }
            MethodInfo method = type.GetMethod("RenderStaticPreview");

            if (method == null)
            {
                Debug.LogError("Fail to find RenderStaticPreview base method");
                return(null);
            }
            if (method.DeclaringType == typeof(Editor))
            {
                return(null);
            }
            Editor editor = Editor.CreateEditor(obj);

            if (editor == null)
            {
                return(null);
            }
            Texture2D textured = editor.RenderStaticPreview(assetPath, subAssets, 0x80, 0x80);

            UnityEngine.Object.DestroyImmediate(editor);
            return(textured);
        }
        internal static Type FindCustomEditorTypeByType(Type type, bool multiEdit)
        {
            if (!CustomEditorAttributes.s_Initialized)
            {
                Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
                for (int i = loadedAssemblies.Length - 1; i >= 0; i--)
                {
                    CustomEditorAttributes.Rebuild(loadedAssemblies[i]);
                }
                CustomEditorAttributes.s_Initialized = true;
            }
            List <CustomEditorAttributes.MonoEditorType> source = (!multiEdit) ? CustomEditorAttributes.kSCustomEditors : CustomEditorAttributes.kSCustomMultiEditors;
            Type inspected;

            for (inspected = type; inspected != null; inspected = inspected.BaseType)
            {
                CustomEditorAttributes.MonoEditorType monoEditorType;
                if (type == inspected)
                {
                    monoEditorType = source.FirstOrDefault((CustomEditorAttributes.MonoEditorType x) => inspected == x.m_InspectedType);
                }
                else
                {
                    monoEditorType = source.FirstOrDefault((CustomEditorAttributes.MonoEditorType x) => inspected == x.m_InspectedType && x.m_EditorForChildClasses);
                }
                if (monoEditorType != null)
                {
                    return(monoEditorType.m_InspectorType);
                }
            }
            return(null);
        }
示例#3
0
        internal static System.Type FindCustomEditorTypeByType(System.Type type, bool multiEdit)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            CustomEditorAttributes.\u003CFindCustomEditorTypeByType\u003Ec__AnonStorey35 typeCAnonStorey35 = new CustomEditorAttributes.\u003CFindCustomEditorTypeByType\u003Ec__AnonStorey35();
            // ISSUE: reference to a compiler-generated field
            typeCAnonStorey35.type = type;
            if (!CustomEditorAttributes.s_Initialized)
            {
                Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
                for (int index = loadedAssemblies.Length - 1; index >= 0; --index)
                {
                    CustomEditorAttributes.Rebuild(loadedAssemblies[index]);
                }
                CustomEditorAttributes.s_Initialized = true;
            }
            List <CustomEditorAttributes.MonoEditorType> source = !multiEdit ? CustomEditorAttributes.kSCustomEditors : CustomEditorAttributes.kSCustomMultiEditors;

            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            CustomEditorAttributes.\u003CFindCustomEditorTypeByType\u003Ec__AnonStorey37 typeCAnonStorey37 = new CustomEditorAttributes.\u003CFindCustomEditorTypeByType\u003Ec__AnonStorey37();
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            for (typeCAnonStorey37.pass = 0; typeCAnonStorey37.pass < 2; typeCAnonStorey37.pass = typeCAnonStorey37.pass + 1)
            {
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: variable of a compiler-generated type
                CustomEditorAttributes.\u003CFindCustomEditorTypeByType\u003Ec__AnonStorey36 typeCAnonStorey36 = new CustomEditorAttributes.\u003CFindCustomEditorTypeByType\u003Ec__AnonStorey36();
                // ISSUE: reference to a compiler-generated field
                typeCAnonStorey36.\u003C\u003Ef__ref\u002453 = typeCAnonStorey35;
                // ISSUE: reference to a compiler-generated field
                typeCAnonStorey36.\u003C\u003Ef__ref\u002455 = typeCAnonStorey37;
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                for (typeCAnonStorey36.inspected = typeCAnonStorey35.type; typeCAnonStorey36.inspected != null; typeCAnonStorey36.inspected = typeCAnonStorey36.inspected.BaseType)
                {
                    // ISSUE: reference to a compiler-generated method
                    CustomEditorAttributes.MonoEditorType monoEditorType = source.FirstOrDefault <CustomEditorAttributes.MonoEditorType>(new Func <CustomEditorAttributes.MonoEditorType, bool>(typeCAnonStorey36.\u003C\u003Em__4C));
                    if (monoEditorType != null)
                    {
                        return(monoEditorType.m_InspectorType);
                    }
                }
            }
            return((System.Type)null);
        }
示例#4
0
        internal static Type FindCustomEditorTypeByType(Type type, bool multiEdit)
        {
            if (!CustomEditorAttributes.s_Initialized)
            {
                Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
                for (int i = loadedAssemblies.Length - 1; i >= 0; i--)
                {
                    CustomEditorAttributes.Rebuild(loadedAssemblies[i]);
                }
                CustomEditorAttributes.s_Initialized = true;
            }
            Type result;

            if (type == null)
            {
                result = null;
            }
            else
            {
                Dictionary <Type, Type> dictionary = (!multiEdit) ? CustomEditorAttributes.kCachedEditorForType : CustomEditorAttributes.kCachedMultiEditorForType;
                Type inspectorType;
                if (dictionary.TryGetValue(type, out inspectorType))
                {
                    result = inspectorType;
                }
                else
                {
                    List <CustomEditorAttributes.MonoEditorType> list = (!multiEdit) ? CustomEditorAttributes.kSCustomEditors : CustomEditorAttributes.kSCustomMultiEditors;
                    for (int j = 0; j < 2; j++)
                    {
                        for (Type type2 = type; type2 != null; type2 = type2.BaseType)
                        {
                            for (int k = 0; k < list.Count; k++)
                            {
                                if (CustomEditorAttributes.IsAppropriateEditor(list[k], type2, type != type2, j == 1))
                                {
                                    inspectorType = list[k].m_InspectorType;
                                    dictionary.Add(type, inspectorType);
                                    result = inspectorType;
                                    return(result);
                                }
                            }
                        }
                    }
                    dictionary.Add(type, null);
                    result = null;
                }
            }
            return(result);
        }
示例#5
0
        // Generate a preview texture for an asset
        public static Texture2D CreatePreviewForAsset(Object obj, Object[] subAssets, string assetPath)
        {
            if (obj == null)
            {
                return(null);
            }

            System.Type type = CustomEditorAttributes.FindCustomEditorType(obj, false);
            if (type == null)
            {
                return(null);
            }

            System.Reflection.MethodInfo info = type.GetMethod("RenderStaticPreview");
            if (info == null)
            {
                Debug.LogError("Fail to find RenderStaticPreview base method");
                return(null);
            }

            if (info.DeclaringType == typeof(Editor))
            {
                return(null);
            }


            Editor editor = Editor.CreateEditor(obj);

            if (editor == null)
            {
                return(null);
            }

            Texture2D tex = editor.RenderStaticPreview(assetPath, subAssets, 128, 128);

            // For debugging we write the preview to a file (keep)
            //{
            //  var bytes = tex.EncodeToPNG();
            //  string previewFilePath = string.Format ("{0}/../SavedPreview{1}.png", Application.dataPath, (int)(EditorApplication.timeSinceStartup*1000));
            //  System.IO.File.WriteAllBytes(previewFilePath, bytes);
            //  Debug.Log ("Wrote preview file to: " +previewFilePath);
            //}

            Object.DestroyImmediate(editor);

            return(tex);
        }
        private static bool EditorForMultiEditingChanged(Editor editor, Object target)
        {
            if (editor.targets.Length <= 1)
            {
                return(false);
            }

            var currentEditorType  = editor.GetType();
            var expectedEditorType = CustomEditorAttributes.FindCustomEditorType(target, true);

            // Going from generic to generic inspector for multi editing is correctly handled.
            if (editor is GenericInspector && expectedEditorType == null)
            {
                return(false);
            }
            return(currentEditorType != expectedEditorType);
        }
        public static Texture2D CreatePreviewForAsset(UnityEngine.Object obj, UnityEngine.Object[] subAssets, string assetPath)
        {
            Texture2D result;

            if (obj == null)
            {
                result = null;
            }
            else
            {
                Type type = CustomEditorAttributes.FindCustomEditorType(obj, false);
                if (type == null)
                {
                    result = null;
                }
                else
                {
                    MethodInfo method = type.GetMethod("RenderStaticPreview");
                    if (method == null)
                    {
                        Debug.LogError("Fail to find RenderStaticPreview base method");
                        result = null;
                    }
                    else if (method.DeclaringType == typeof(Editor))
                    {
                        result = null;
                    }
                    else
                    {
                        Editor editor = Editor.CreateEditor(obj);
                        if (editor == null)
                        {
                            result = null;
                        }
                        else
                        {
                            Texture2D texture2D = editor.RenderStaticPreview(assetPath, subAssets, 128, 128);
                            UnityEngine.Object.DestroyImmediate(editor);
                            result = texture2D;
                        }
                    }
                }
            }
            return(result);
        }
示例#8
0
 // Is there a custom editor for this object?
 public static bool HasCustomEditor(UnityObject obj)
 {
     return(CustomEditorAttributes.FindCustomEditorType(obj, false) != null);
 }
示例#9
0
 public static bool HasCustomEditor(UnityEngine.Object obj) =>
 (CustomEditorAttributes.FindCustomEditorType(obj, false) != null);
 internal static Type FindCustomEditorType(UnityEngine.Object o, bool multiEdit)
 {
     return(CustomEditorAttributes.FindCustomEditorTypeByType(o.GetType(), multiEdit));
 }
示例#11
0
        internal static Type FindCustomEditorTypeByType(Type type, bool multiEdit)
        {
            if (!CustomEditorAttributes.s_Initialized)
            {
                Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
                for (int i = loadedAssemblies.Length - 1; i >= 0; i--)
                {
                    CustomEditorAttributes.Rebuild(loadedAssemblies[i]);
                }
                CustomEditorAttributes.s_Initialized = true;
            }
            Type result;

            if (type == null)
            {
                result = null;
            }
            else
            {
                Dictionary <Type, List <CustomEditorAttributes.MonoEditorType> > dictionary = (!multiEdit) ? CustomEditorAttributes.kSCustomEditors : CustomEditorAttributes.kSCustomMultiEditors;
                for (int j = 0; j < 2; j++)
                {
                    Type type2 = type;
                    while (type2 != null)
                    {
                        List <CustomEditorAttributes.MonoEditorType> list;
                        if (dictionary.TryGetValue(type2, out list))
                        {
                            goto IL_AB;
                        }
                        if (type2.IsGenericType)
                        {
                            type2 = type2.GetGenericTypeDefinition();
                            if (dictionary.TryGetValue(type2, out list))
                            {
                                goto IL_AB;
                            }
                        }
IL_20E:
                        type2 = type2.BaseType;
                        continue;
IL_AB:
                        CustomEditorAttributes.s_SearchCache.Clear();
                        foreach (CustomEditorAttributes.MonoEditorType current in list)
                        {
                            if (CustomEditorAttributes.IsAppropriateEditor(current, type2, type != type2, j == 1))
                            {
                                CustomEditorAttributes.s_SearchCache.Add(current);
                            }
                        }
                        Type type3 = null;
                        if (GraphicsSettings.renderPipelineAsset != null)
                        {
                            Type type4 = GraphicsSettings.renderPipelineAsset.GetType();
                            foreach (CustomEditorAttributes.MonoEditorType current2 in CustomEditorAttributes.s_SearchCache)
                            {
                                if (current2.m_RenderPipelineType == type4)
                                {
                                    type3 = current2.m_InspectorType;
                                    break;
                                }
                            }
                        }
                        if (type3 == null)
                        {
                            foreach (CustomEditorAttributes.MonoEditorType current3 in CustomEditorAttributes.s_SearchCache)
                            {
                                if (current3.m_RenderPipelineType == null)
                                {
                                    type3 = current3.m_InspectorType;
                                    break;
                                }
                            }
                        }
                        CustomEditorAttributes.s_SearchCache.Clear();
                        if (type3 != null)
                        {
                            result = type3;
                            return(result);
                        }
                        goto IL_20E;
                    }
                }
                result = null;
            }
            return(result);
        }