• 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 LesPaul · Apr 22, 2013 at 04:36 PM · customeditor

Custom GUIEditor Array question

Hey guys,

I've got a few scripts that manage icons and such on a menu. The issue i have is this one. I want to be able to add and remove the icons in a user-friendly way.

Is it possible to take a few arrays inside of the main GUI script, and edit the properties of those arrays in separate blocks? Something like the following:

 Arrays in regular script:
 
 var icon_array : Array;
 var name_array : Array;
 
 Look to the custom editor thingy:
 
 Icon 1
    icon_texture
    icon_name
 
 Icon 2
    icon_texture
    icon_name
 
 etc...

If this is possible please let me know :)

edit mo 21:44 :

I've made the classes necessary, but all I need now is a way to access the private variables from a custom editor using getters and setters. The script i've got for the apps is this:

 using UnityEngine;
 using System.Collections;
 
 public class App : MonoBehaviour {
     private string app_name = "undifined";
     private Texture2D icon;
     private Texture2D background;
     private bool show = false;
     
     public bool Show {
         get { return show; }
         set { show = value;}
     }
     public string Name {
         get { return app_name; }
         set { app_name = value; }
     }
     public Texture2D Icon {
         get { return icon; }
         set { icon = value; }
     }
     public Texture2D Background {
         get { return background; }
         set { background = value; }
     }
 }
 

Can I somehow use the get and set things in here to make something like this?

 #pragma strict
 @CustomEditor(GUI_Handler)
 @CanEditMultipleObjects
 class customEditor extends Editor {
     var nameProp        : SerializedProperty;
     var iconProp         : SerializedProperty;
     var backgroundProp         : SerializedProperty;
     var showProp         : SerializedProperty;
    
     function OnEnable () {
         // Setup the SerializedProperties
         nameProp        = serializedObject.FindProperty ("app_name");
         iconProp         = serializedObject.FindProperty ("icon");
         backgroundProp        = serializedObject.FindProperty ("background"); 
         showProp         = serializedObject.FindProperty ("show");
     }
     function OnInspectorGUI() {
         // Update the serializedProperty
         serializedObject.Update ();
         // Show the custom GUI controls
         
         EditorGUILayout.PropertyField(nameProp,new GUIContent("Name"));
        
         
         EditorGUILayout.PropertyField(iconProp,new GUIContent("App Icon"));
         
         EditorGUILayout.PropertyField(backgroundProp, new GUIContent("App Background"));
         serializedObject.ApplyModifiedProperties ();
     }
 }

Something like this, but then for each array index on the name array inside the main GUI script, using that same index to cover all variables. Using those variables create a new icon, and set all the textures and such.

Is this possible or not? Please let me know and if you are kind: Leave an example ;)

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
1
Best Answer

Answer by fafase · Apr 22, 2013 at 04:43 PM

 [System.Serializable]
 public class Icon{
    public Texture2D icon_texture;
    public string icon_name;
 }
 
 public class MyScript:MonoBehaviour{
     public Icon [] icon;
 }

Is that what you meant?

This will let you define in the inspector how many icons you want and then you can give them values from the inspector again.

Comment
Add comment · Show 2 · 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
avatar image LesPaul · Apr 22, 2013 at 05:06 PM 0
Share

If I do it this way, is every single icon grouped in the array as far as properties go?

avatar image fafase · Apr 23, 2013 at 06:59 AM 0
Share

If I were you I would try and see if it is what you need.

You will get a variable icon with a size 0. The when you provide 1, you get one slot for Texture and icon_name. Give two and you get a second one. And so on.

Access each of them with icon[index];

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 Answers


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