void OnGUI()
        {
            if (target == null)
            {
                target = SunGeneratorEditor.current;
                if (SunGeneratorEditor.current == null)
                {
                    return;
                }
            }
            GUILayout.BeginVertical();
            GUILayout.Space(4);
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Frame size ", GUILayout.Width(100));
            target.FrameSize = (FrameSizeType)EditorGUILayout.EnumPopup(target.FrameSize);
            GUILayout.EndHorizontal();
            GUILayout.Space(4);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Count of frames ", GUILayout.Width(100));
            target.FrameCount = (FramesCountType)EditorGUILayout.EnumPopup(target.FrameCount);
            GUILayout.EndHorizontal();
            GUILayout.Space(4);
            GUILayout.BeginHorizontal();
            GUILayout.Label("File type ", GUILayout.Width(100));
            target.Type = (SunGeneratorEditor.ImageType)EditorGUILayout.EnumPopup(target.Type);
            GUILayout.EndHorizontal();
            GUILayout.Space(4);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Time scale ", GUILayout.Width(100));
            target.TimeStep = EditorGUILayout.FloatField(target.TimeStep);
            GUILayout.EndHorizontal();
            int Width = target.CalcWidth();

            GUILayout.Space(4);
            GUILayout.Label("Result texture size: " + Width.ToString() + " x " + Width.ToString());
            GUILayout.EndVertical();
            target.animatedTexture = (Texture2D)EditorGUILayout.ObjectField("", target.animatedTexture, typeof(Texture2D), false);
            GUILayout.EndHorizontal();
            GUILayout.Space(4);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Save texture", "Save animated texture")))
            {
                string path = EditorUtility.SaveFilePanel("Save animated texture", Application.dataPath, target.target.name, target.Type.ToString().ToLower());
                if (path.Length != 0)
                {
                    target.SaveToTexture(path);
                    path = path.Replace(Application.dataPath, "Assets");
                    target.animatedTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
                }
            }
            if (GUILayout.Button(new GUIContent("Save material", "Save material for animated texture")))
            {
                string path = EditorUtility.SaveFilePanel("", Application.dataPath, target.target.name, "mat");
                if (path.Length != 0)
                {
                    SunGenerator tTarget = (SunGenerator)target.target;
                    Material     mat;
                    if (tTarget.ShaderMode == SunGenerator.EModeSM.LIGHT_CPU ||
                        tTarget.ShaderMode == SunGenerator.EModeSM.LIGHT_SM3 ||
                        tTarget.ShaderMode == SunGenerator.EModeSM.LIGHT_SM4)
                    {
                        mat = new Material(Shader.Find("Space/Star/Sun_soft_animated"));
                    }
                    else
                    {
                        mat = new Material(Shader.Find("Space/Star/Sun_animated"));
                    }
                    mat.SetTexture("_AT", target.animatedTexture);
                    mat.SetTextureScale("_AT", Vector2.one * 1.0f / Mathf.Sqrt(((int)target.FrameCount) * 2));
                    tTarget.fillShaderData(mat);
                    path = path.Replace(Application.dataPath, "Assets");
                    AssetDatabase.CreateAsset(mat, path);
                    AssetDatabase.Refresh();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }