public static Texture2D Render(GameObject prefab)
        {
            if (prefab == null)
            {
                return(null);
            }
            if (prefab.GetComponent <Renderer>() == null)
            {
                return(null);
            }
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(true);
            Texture2D texture2D = new Texture2D(64, 64);

            texture2D.hideFlags = HideFlags.HideAndDontSave;
            texture2D.name      = "Preview Texture";
            RenderTexture temporary  = RenderTexture.GetTemporary(texture2D.width, texture2D.height);
            GameObject    gameObject = new GameObject("Preview");

            gameObject.hideFlags = HideFlags.HideAndDontSave;
            Camera camera = gameObject.AddComponent(typeof(Camera)) as Camera;

            camera.clearFlags      = CameraClearFlags.Color;
            camera.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 0f);
            camera.cullingMask     = 0;
            camera.enabled         = false;
            camera.targetTexture   = temporary;
            Light light = gameObject.AddComponent(typeof(Light)) as Light;

            light.type = LightType.Directional;
            Bounds  bounds = RenderThumbnailUtility.CalculateVisibleBounds(prefab);
            Vector3 vector = new Vector3(0.7f, 0.3f, 0.7f);
            float   num    = bounds.extents.magnitude * 1.6f;

            gameObject.transform.position = bounds.center + vector.normalized * num;
            gameObject.transform.LookAt(bounds.center);
            camera.nearClipPlane = num * 0.1f;
            camera.farClipPlane  = num * 2.2f;
            Camera current = Camera.current;

            camera.RenderDontRestore();
            Light[] lights = new Light[]
            {
                light
            };
            Graphics.SetupVertexLights(lights);
            Component[] componentsInChildren = prefab.GetComponentsInChildren(typeof(Renderer));
            Component[] array = componentsInChildren;
            for (int i = 0; i < array.Length; i++)
            {
                Renderer renderer = (Renderer)array[i];
                if (renderer.enabled)
                {
                    Material[] sharedMaterials = renderer.sharedMaterials;
                    for (int j = 0; j < sharedMaterials.Length; j++)
                    {
                        if (!(sharedMaterials[j] == null))
                        {
                            Material material   = sharedMaterials[j];
                            string   dependency = ShaderUtil.GetDependency(material.shader, "BillboardShader");
                            if (dependency != null && dependency != string.Empty)
                            {
                                material           = UnityEngine.Object.Instantiate <Material>(material);
                                material.shader    = Shader.Find(dependency);
                                material.hideFlags = HideFlags.HideAndDontSave;
                            }
                            for (int k = 0; k < material.passCount; k++)
                            {
                                if (material.SetPass(k))
                                {
                                    renderer.RenderNow(j);
                                }
                            }
                            if (material != sharedMaterials[j])
                            {
                                UnityEngine.Object.DestroyImmediate(material);
                            }
                        }
                    }
                }
            }
            texture2D.ReadPixels(new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), 0, 0);
            RenderTexture.ReleaseTemporary(temporary);
            UnityEngine.Object.DestroyImmediate(gameObject);
            Camera.SetupCurrent(current);
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(false);
            return(texture2D);
        }
        public static Texture2D Render(GameObject prefab)
        {
            if ((Object)prefab == (Object)null)
            {
                return((Texture2D)null);
            }
            if ((Object)prefab.GetComponent <Renderer>() == (Object)null)
            {
                return((Texture2D)null);
            }
            Texture2D texture2D = new Texture2D(64, 64);

            texture2D.hideFlags = HideFlags.HideAndDontSave;
            texture2D.name      = "Preview Texture";
            RenderTexture temporary  = RenderTexture.GetTemporary(texture2D.width, texture2D.height);
            GameObject    gameObject = new GameObject("Preview");

            gameObject.hideFlags = HideFlags.HideAndDontSave;
            Camera camera = gameObject.AddComponent(typeof(Camera)) as Camera;

            camera.cameraType      = CameraType.Preview;
            camera.clearFlags      = CameraClearFlags.Color;
            camera.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 0.0f);
            camera.cullingMask     = 0;
            camera.enabled         = false;
            camera.targetTexture   = temporary;
            Light light = gameObject.AddComponent(typeof(Light)) as Light;

            light.type = LightType.Directional;
            Bounds  visibleBounds = RenderThumbnailUtility.CalculateVisibleBounds(prefab);
            Vector3 vector3       = new Vector3(0.7f, 0.3f, 0.7f);
            float   num           = visibleBounds.extents.magnitude * 1.6f;

            gameObject.transform.position = visibleBounds.center + vector3.normalized * num;
            gameObject.transform.LookAt(visibleBounds.center);
            camera.nearClipPlane = num * 0.1f;
            camera.farClipPlane  = num * 2.2f;
            Camera current = Camera.current;

            camera.RenderDontRestore();
            Graphics.SetupVertexLights(new Light[1] {
                light
            });
            foreach (Renderer componentsInChild in prefab.GetComponentsInChildren(typeof(Renderer)))
            {
                if (componentsInChild.enabled)
                {
                    Material[] sharedMaterials = componentsInChild.sharedMaterials;
                    for (int material = 0; material < sharedMaterials.Length; ++material)
                    {
                        if (!((Object)sharedMaterials[material] == (Object)null))
                        {
                            Material original   = sharedMaterials[material];
                            string   dependency = ShaderUtil.GetDependency(original.shader, "BillboardShader");
                            if (dependency != null && dependency != string.Empty)
                            {
                                original           = Object.Instantiate <Material>(original);
                                original.shader    = Shader.Find(dependency);
                                original.hideFlags = HideFlags.HideAndDontSave;
                            }
                            for (int pass = 0; pass < original.passCount; ++pass)
                            {
                                if (original.SetPass(pass))
                                {
                                    componentsInChild.RenderNow(material);
                                }
                            }
                            if ((Object)original != (Object)sharedMaterials[material])
                            {
                                Object.DestroyImmediate((Object)original);
                            }
                        }
                    }
                }
            }
            texture2D.ReadPixels(new Rect(0.0f, 0.0f, (float)texture2D.width, (float)texture2D.height), 0, 0);
            RenderTexture.ReleaseTemporary(temporary);
            Object.DestroyImmediate((Object)gameObject);
            Camera.SetupCurrent(current);
            return(texture2D);
        }