Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by skoandi · May 23, 2013 at 02:34 PM · editortexturegradientformulargb

Generate a gradient texture from editor script

Hi does somebody know how to generate a gradient PNG from a editor script? Whats the formula behind it?

I've looked around but nothing worked :/

This generates a texture using UnityEngine; using System.Collections; using UnityEditor; using System.IO;

 public class GenGradient : EditorWindow {
     public Color fromm;
     public Color too;
     public float tt;
     [MenuItem ("Window/Gen Texture")]
     // Use this for initialization
     static void Init(){
         GenGradient window = (GenGradient)EditorWindow.GetWindow(typeof(GenGradient));
         window.maxSize = new Vector2(300,200);
     }
     void OnGUI(){
         if(GUILayout.Button("Gen")){
             GenTexture();
         }
         fromm = EditorGUILayout.ColorField(fromm);
         too = EditorGUILayout.ColorField(too);
         tt = EditorGUILayout.Slider(tt,0,100);
     }
     void GenTexture(){
         Texture2D texture = new Texture2D(64,64,TextureFormat.RGB24,false);
         Color[] colors = new Color[texture.width];
         for(int i = 0; i < texture.width; i++){
             //for(int y = 0; y <texture.height; y++){
                 colors[i].r = (i/225)*1000;//Linear((i/64)*100);
                 Debug.Log("Value"+(i/225f)*1000f);//Linear((i/64)*100));
                 texture.SetPixel(i,1,colors[i]);
             //}
         }
         texture.Apply();
         var bytes = texture.EncodeToPNG();
         File.WriteAllBytes("Assets/gui/swag.png",bytes);
         //AssetDatabase.CreateAsset(bytes,"Assets/hi.png");
         //AssetDatabase.CreateAsset(bytes,"Assets/grad.png");
         AssetDatabase.Refresh();
     }
     public float Linear (float per) {
         return fromm.r * per + too.r * (1-per);
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Are textured/z-clipped gizmos possible? 0 Answers

Overall quality became worse after changing to Windows from Mac 1 Answer

Gradient Changes in Editor Reset In Play Mode. Why? 1 Answer

How to check if a Gradient in Editor has been changed. 1 Answer

How can you tell if a texture is NPOT or not, and what its NPOT import settings are 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges