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 /
This question was closed Aug 15, 2017 at 06:31 PM by Razputin for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Razputin · Aug 15, 2017 at 08:22 AM · editorinspectorcustom editorcustomcustom-inspector

Questions Regarding Images in Custom Inspector/Editor

I'm trying to make it so one can edit the texture from the editor right of the name string and left of the Remove Character button, I can get an image to display their if I add it in the Element however I'd like to base.OnInspector and hide those variables later.

I'd like it so in Image 1 you can click the image to change it to a different texture, the way you can in Image 2. If you click them you'll understand what I'm talking about.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 using UnityEngine.UI;
 using System;
 
 public class CutsceneManager : MonoBehaviour
 {
 
     public CharacterList c;
 
     void OnEnable()
     {
         c = GetComponent<CharacterList>();
     }
 
     public CharacterList GetCharacterList()
     {   
         return c;       
     }
 
     [CustomEditor(typeof(CutsceneManager))]
     public class Inspector_Buttons : Editor
     {
         private CharacterList c;
         private CutsceneManager cM;
 
         void OnEnable()
         {
             cM = (CutsceneManager)target;
             c = cM.GetCharacterList();
         }
 
         public override void OnInspectorGUI()
         {
             if (GUILayout.Button("Create Character"))
             {
                 AddCharacter();
             }
 
             for(int i = 0; i < c.characters.Count; i++)
             {
                 GUILayout.BeginHorizontal();
                 c.characters[i].name = GUILayout.TextField(c.characters[i].name, GUILayout.Width(100), GUILayout.Height(25));
 
                 if (GUILayout.Button("Remove Character"))
                 {
                     RemoveCharacter(i);
                     return;
                 }
                 GUILayout.EndHorizontal();
             }
 
             base.OnInspectorGUI();
         }
 
         void AddCharacter()
         {
             c.characters.Add(new Character());
         }
 
         void RemoveCharacter(int i)
         {
             c.characters.RemoveAt(i);
         }
     }
 
     [System.Serializable]
     public class CharacterList
     {
         public List<Character> characters = new List<Character>();
 
     }
 
     [System.Serializable]
     public class Character 
     {
         public string name = string.Empty;
         public Texture myImage = new Texture();
     }
 }
 


[1]: /storage/temp/99940-aosf2.png

aosf2.png (60.3 kB)
aosfjafso.png (61.0 kB)
Comment
Add comment · Show 1
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
avatar image Razputin · Aug 15, 2017 at 05:35 PM 0
Share

bumpingggg

1 Reply

  • Sort: 
avatar image
0

Answer by Razputin · Aug 15, 2017 at 06:31 PM

Got it working.

 public class CutsceneManager : MonoBehaviour
 {
 
     public CharacterList c;
     public BackdropList b;
 
     void OnEnable()
     {
         c = GetComponent<CharacterList>();
         b = GetComponent<BackdropList>();
     }
 
     public CharacterList GetCharacterList()
     {   
         return c;       
     }
     
     public BackdropList GetBackdropList()
     {
         return b;
     }
 
     [CustomEditor(typeof(CutsceneManager))]
     public class Inspector_Buttons : Editor
     {
         private CharacterList c;
         private BackdropList b;
         private CutsceneManager cM;
 
         void OnEnable()
         {
             cM = (CutsceneManager)target;
             c = cM.GetCharacterList();
             b = cM.GetBackdropList();
         }
 
         public override void OnInspectorGUI()
         {
             if (GUILayout.Button("Create Character"))
             {
                 AddCharacter();
             }
 
             for(int i = 0; i < c.characters.Count; i++)
             {
                 GUILayout.BeginHorizontal();
                 c.characters[i].name = GUILayout.TextField(c.characters[i].name, GUILayout.Width(100), GUILayout.Height(25));
                 if (GUILayout.Button("Remove Character"))
                 {
                     RemoveCharacter(i);
                     return;
                 }
                 GUILayout.EndHorizontal();
             }
 
             if (GUILayout.Button("Create Backdrop"))
             {
                 AddBackdrop();
             }
 
             for (int i = 0; i < b.backdrops.Count; i++)
             {
                 GUILayout.BeginHorizontal();
                 b.backdrops[i].backdropName = GUILayout.TextField(b.backdrops[i].backdropName, GUILayout.Width(100), GUILayout.Height(25));
                 b.backdrops[i].backdrop = (Texture2D)EditorGUILayout.ObjectField(b.backdrops[i].backdrop, typeof(Texture2D), false);
                 if (GUILayout.Button("Remove Backdrop"))
                 {
                     RemoveBackdrop(i);
                     return;
                 }
                 GUILayout.EndHorizontal();
             }
 
             base.OnInspectorGUI();
         }
 
         void AddCharacter()
         {
             c.characters.Add(new Character());
         }
 
         void RemoveCharacter(int i)
         {
             c.characters.RemoveAt(i);
         }
 
         void AddBackdrop()
         {
             b.backdrops.Add(new Backdrop());
         }
 
         void RemoveBackdrop(int i)
         {
             b.backdrops.RemoveAt(i);
         }
 
     }
 
     [System.Serializable]
     public class CharacterList
     {
         public List<Character> characters = new List<Character>();
 
     }
 
     [System.Serializable]
     public class Character 
     {
         public string name = string.Empty;
         public Texture characterPortrait = new Texture();
     }
 
     [System.Serializable]
     public class BackdropList
     {
         public List<Backdrop> backdrops = new List<Backdrop>();
     }
 
     [System.Serializable]
     public class Backdrop
     {
         public string backdropName = string.Empty;
         public Texture2D backdrop;
 
         void OnAwake()
         {
             backdrop = new Texture2D(10, 10);
         }
     }
 }
 


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

Follow this Question

Answers Answers and Comments

89 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i get SerializedProperty from UnityEvent which in List. Sorry for my Eng. 2 Answers

Custom editor super slow even with no draw operations 1 Answer

Custom inspector, show string instead of component type 0 Answers

Unity Custom Editor Texture Warning 2 Answers

editorguilayout.objectfield issue 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