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 GilbertoBitt · Sep 16, 2016 at 11:32 AM · editortexture2dcustom-inspectorpropertydrawerpreview

Texture2D on Property Drawers.

i have this scripts.

Item class

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Item  {
     public string itemName;
     public Texture2D itemImage;
     public int itemPrice;
 }

ItemDrawer class

 using UnityEditor;
 using UnityEngine;
 
 [CustomPropertyDrawer (typeof (ItemAttribute))]
 public class ItemDrawer : PropertyDrawer {
 
     ItemAttribute item { get { return ((ItemAttribute)attribute); } }
 
 
     public override void OnGUI (Rect position, SerializedProperty prop, GUIContent label) {
         // Adjust height of the text field
         EditorGUI.BeginProperty (position, label, prop);
         // Draw label
         //position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
 
         // Don't make child fields be indented
         var indent = EditorGUI.indentLevel;
         EditorGUI.indentLevel = 0;
 
         // Calculate rects
         //var amountRect = new Rect (position.x, position.y, 30, position.height);
         //var unitRect = new Rect (position.x+35, position.y, 50, position.height);
         //var nameRect = new Rect (position.x+90, position.y, position.width-90, position.height);
 
         // Draw fields - passs GUIContent.none to each so they are drawn without labels
         //EditorGUI.PropertyField (amountRect, prop.FindPropertyRelative ("itemImage"), GUIContent.none);
         //EditorGUI.PropertyField (unitRect, prop.FindPropertyRelative ("itemPrice"), GUIContent.none);
         //EditorGUI.PropertyField (nameRect, prop.FindPropertyRelative ("itemName"), GUIContent.none);
         //var texture = (Texture2D)prop.objectReferenceValue;
         //EditorGUI.LabelField (new Rect (position.x, position.y, position.width, position.height), "Image Preview", GUIContent);
             //EditorGUI.LabelField(new Rect(position.x,position.y,position.width,position.height), texture, GUIContent(Texture2D));
         //EditorGUI.DrawPreviewTexture(new Rect(position.x,position.y,position.width,position.height)
 
         // Set indent back to what it was
         EditorGUI.indentLevel = indent;
 
         EditorGUI.EndProperty ();
 
     }
 }

ItemAttribute class

 using UnityEngine;
 
 public class ItemAttribute : PropertyAttribute {
 
     public ItemAttribute () {
 
     }
 
 }

example of use

     [ItemAttribute]
     public Item item;


What i want: OBS: achieve this using custom inspector but i want property drawers.

alt text

so as u can see that the problem i having i want to make the same preview texture with all the infos using property drawes but having hard time trying to get image texture2D to show and make it selectable so users can change the sprite right there on inspector. help please.

i already try this ways of get texture.

 var texture = (Texture2D)prop.objectReferenceValue;


 EditorGUI.PropertyField (amountRect, prop.FindPropertyRelative ("itemImage"), GUIContent.none);
itempreview.png (4.6 kB)
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Select a readonly value from dropdown using PropertyDrawers 0 Answers

PropertyDrawer not updating in custom inspector. 0 Answers

CustomAttribute on Class or Method ( EDIT: Button to call methods) 2 Answers

SerializedProperty to Texture2D 2 Answers

What should be handled in the custom inspector version of a script? 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