private void Save(MaterialProperty prop) { Debug.Log(prop.textureValue.ToString()); Texture saved_texture = TextureHelper.SaveTextureAsPNG(texture, PATH.TEXTURES_DIR + "curves/" + curve.GetHashCode() + ".png", null); prop.textureValue = saved_texture; saved = true; }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { CurveData data = (CurveData)ThryEditor.currentlyDrawing.currentProperty.property_data; if (data == null) { data = new CurveData(); data.curve = new AnimationCurve(); if (ThryEditor.currentlyDrawing.currentProperty.options.image == null) { data.imageData = new ImageData(); } else { data.imageData = ThryEditor.currentlyDrawing.currentProperty.options.image; } } editor.TexturePropertyMiniThumbnail(position, prop, "", ""); EditorGUI.BeginChangeCheck(); data.curve = EditorGUI.CurveField(position, new GUIContent(" " + label.text, label.tooltip), data.curve); if (EditorGUI.EndChangeCheck()) { data.texture = Converter.CurveToTexture(data.curve, data.imageData.width, data.imageData.height, data.imageData.channel); prop.textureValue = data.texture; data.saved = false; } string windowName = ""; if (EditorWindow.focusedWindow != null) { windowName = EditorWindow.focusedWindow.titleContent.text; } bool isCurveEditor = windowName == "Curve"; if (isCurveEditor) { data.window = EditorWindow.focusedWindow; } if (data.window == null && !data.saved) { Debug.Log(prop.textureValue.ToString()); Texture saved_texture = TextureHelper.SaveTextureAsPNG(data.texture, PATH.TEXTURES_DIR + "curves/" + data.curve.GetHashCode() + ".png", null); prop.textureValue = saved_texture; data.saved = true; } ThryEditor.currentlyDrawing.currentProperty.property_data = data; }
public void OnDestroy() { if (gradient_has_been_edited) { if (data.preview_texture.GetType() == typeof(Texture2D)) { string file_name = GradientFileName(data.gradient, prop.targets[0].name); Texture saved = TextureHelper.SaveTextureAsPNG((Texture2D)data.preview_texture, PATH.TEXTURES_DIR + "/Gradients/" + file_name, textureSettings); file_name = Regex.Replace(file_name, @"\.((png)|(jpg))$", ""); FileHelper.SaveValueToFile(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(saved)), Parser.ObjectToString(data.gradient), PATH.GRADIENT_INFO_FILE); prop.textureValue = saved; } } else { UpdatePreviewTexture(privious_preview_texture); } }