Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Alberto · Mar 22, 2010 at 08:50 AM · editoreditor-scriptingtexture2ddrawing

UnityEditor - Drawing on a Texture

hello, do you know how I can draw with my mouse on textures? or other drawing tricks? I speak in from the side of the editor not in the gameScene. Below a sample code:

using UnityEngine; using UnityEditor;

public class MyWindow : EditorWindow { string myString = "Bella zi"; bool groupEnabled; bool myBool = true; float myFloat = 1.23f; Texture2D texty = new Texture2D(150,150);

// Add menu named "My Window" to the Window menu [MenuItem ("Window/My Window")] static void Init () { // Get existing open window or if none, make a new one: MyWindow window = (MyWindow)EditorWindow.GetWindow (typeof (MyWindow)); window.Show (); }

void OnGUI () { GUILayout.Label ("Base Settings", EditorStyles.boldLabel); EditorGUILayout.TextArea(myString, GUILayout.Height(200));

   //little box with texture to draw <-------
   GUILayout.Box(texty,GUILayout.Width(150),GUILayout.Height(150));      

   groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
   myBool = EditorGUILayout.Toggle ("Toggle", myBool);
   myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
   EditorGUILayout.EndToggleGroup ();

} }

thanks!!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by qJake · Jun 08, 2010 at 10:01 PM

You can use Texture2D.SetPixel(...) to set the color of an individual pixel on a texture. If your texture is on the GUI, it should be fairly easy to compute its position using its rectangle, which you can then offset from the Mouse position in order to get the pixel coordinates of the pixel that the mouse is over.

If this texture is in 3D space, however, you can check out my other answer here:

http://answers.unity3d.com/questions/10683/detecting-mouseclick-on-pixels-in-sprite-using-sm2-pixel-collisions

which details how you can Raycast to get which pixel the mouse is pointing at.

Comment
Add comment · Share
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

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

No one has followed this question yet.

Related Questions

How to access a texture for reading on the editor? 1 Answer

[Solved] How can I change Texture2D format in Editor Script? 1 Answer

Editor class "Texture Importer" question (applying settings to multiple texture assets). 2 Answers

EditorWindow loses Texture2D reference on scene change: how to handle? 4 Answers

reflection propertyinfo.getvalue compiles fine but gives erros in editor 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