public static Texture SaveTextureAsPNG(Texture2D texture, string path) { byte[] encoding = texture.EncodeToPNG(); Debug.Log("Gradient saved at \"" + path + "\"."); Helper.writeBytesToFile(encoding, path); AssetDatabase.ImportAsset(path); Texture tex = (Texture)EditorGUIUtility.Load(path); tex.wrapMode = TextureWrapMode.Clamp; tex.filterMode = FilterMode.Point; return(SetTextureImporterFormat((Texture2D)tex, true)); }
public static void DownloadFileASync(string url, string path, Action <string> callback) { DownloadAsBytesASync(url, delegate(object o, DownloadDataCompletedEventArgs a) { if (a.Cancelled || a.Error != null) { MainThreader.Call(callback, null); } else { Helper.writeBytesToFile(a.Result, path); MainThreader.Call(callback, path); } }); }
//----------------------------Textures------------------------------------ public static Texture SaveTextureAsPNG(Texture2D texture, string path, TextureData settings) { if (!path.EndsWith(".png")) { path += ".png"; } byte[] encoding = texture.EncodeToPNG(); Debug.Log("Texture saved at \"" + path + "\"."); Helper.writeBytesToFile(encoding, path); AssetDatabase.ImportAsset(path); if (settings != null) { settings.ApplyModes(path); } Texture saved = AssetDatabase.LoadAssetAtPath <Texture>(path); return(saved); }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { GradientData data; if (ThryEditor.currentlyDrawing.property_data != null) { data = (GradientData)ThryEditor.currentlyDrawing.property_data; } else { data = new GradientData(); data.saved = true; ThryEditor.currentlyDrawing.property_data = data; } if (data.gradientObj == null) { data.gradientObj = GradientObject.CreateInstance <GradientObject>(); if (prop.textureValue != null) { data.texture = (Texture2D)prop.textureValue; TextureUpdated(ref data); } else { data.texture = new Texture2D(256, 1); data.serializedGradient = new SerializedObject(data.gradientObj); data.colorGradient = data.serializedGradient.FindProperty("gradient"); } data.saved = true; } EditorGUI.BeginChangeCheck(); editor.TexturePropertyMiniThumbnail(position, prop, "", ""); if (EditorGUI.EndChangeCheck()) { data.texture = (Texture2D)prop.textureValue; TextureUpdated(ref data); } EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(position, data.colorGradient, new GUIContent(" " + label.text, label.tooltip)); string windowName = ""; if (EditorWindow.focusedWindow != null) { windowName = EditorWindow.focusedWindow.titleContent.text; } bool isGradientEditor = windowName == "Gradient Editor"; if (isGradientEditor) { data.gradientWindow = EditorWindow.focusedWindow; } bool changed = EditorGUI.EndChangeCheck(); if (changed) { if (data.texture == prop.textureValue) { data.texture = new Texture2D(256, 1); } data.serializedGradient.ApplyModifiedProperties(); GradientToTexture(ref data); prop.textureValue = data.texture; data.saved = false; } if (data.gradientWindow == null && !data.saved) { byte[] encoding = data.texture.EncodeToPNG(); string gradient_data = GradientToString(ref data); string gradient_name = Config.Get().gradient_name; gradient_name = gradient_name.Replace("<material>", editor.target.name); gradient_name = gradient_name.Replace("<hash>", "" + gradient_data.GetHashCode()); gradient_name = gradient_name.Replace("<prop>", prop.name); string path = "Assets/Textures/Gradients/" + gradient_name; Debug.Log("Gradient saved at \"" + path + "\"."); Helper.writeBytesToFile(encoding, path); Helper.SaveValueToFile(gradient_name, gradient_data, GRADIENT_INFO_FILE_PATH); AssetDatabase.ImportAsset(path); Texture tex = (Texture)EditorGUIUtility.Load(path); tex.wrapMode = TextureWrapMode.Clamp; SetTextureImporterFormat((Texture2D)tex, true); prop.textureValue = tex; data.saved = true; } }