public static void ShowWindow(SunGeneratorEditor targ) { SaveToTextureSunWindow win = GetWindow <SaveToTextureSunWindow>(false, "Save animated", true); win.target = targ; win.target.TimeStep = 5.0f; }
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(); }
public override void OnInspectorGUI() { current = this; SunGenerator tTarget = (SunGenerator)target; EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) { tTarget.Build(); } GUILayout.Space(6); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Save animated", "Save animation to texture and create material"))) { SaveToTextureSunWindow.ShowWindow(this); AssetDatabase.Refresh(); } GUI.enabled = tTarget.ShaderMode != SunGenerator.EModeSM.CPU_2SM3 && tTarget.ShaderMode != SunGenerator.EModeSM.CPU_SM3 && tTarget.ShaderMode != SunGenerator.EModeSM.CPU_SM4 && tTarget.ShaderMode != SunGenerator.EModeSM.LIGHT_CPU; if (GUILayout.Button(new GUIContent("Save material", "Save current material"))) { string path = EditorUtility.SaveFilePanel("", Application.dataPath, target.name, "mat"); MeshRenderer mr = tTarget.GetComponent <MeshRenderer>(); if (path.Length != 0 && mr != null) { Material mat = mr.sharedMaterial; path = path.Replace(Application.dataPath, "Assets"); AssetDatabase.CreateAsset(mat, path); AssetDatabase.Refresh(); } } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Load Themplate", "Load parameters to xml"))) { string path = EditorUtility.OpenFilePanel( "Load template from XML", "/Assets/SunShader/Temlpates", "xml"); if (path.Length != 0) { LoadXml(path, ref tTarget); } } if (GUILayout.Button(new GUIContent("Save Themplate", "Save parameters to xml"))) { string path = EditorUtility.SaveFilePanel( "Save template as XML", "/Assets/SunShader/Temlpates", target.name + ".xml", "xml"); if (path.Length != 0) { SaveXml(path, ref tTarget); } } GUILayout.EndHorizontal(); }