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 Sawula · Jan 04, 2017 at 07:20 PM · listpropertieseditor window

Editor Window Edit property of items in a list

Hello, need a bit of help I have a script that serve as manager for items in my game I'm trying to make a custom editor window to display in a list only the item with that manager script. And I want to be able to edit the properties of that script on each item, from that window.

I thought ReorderableList would be the solution, but after hours trying I'm getting nowhere and I don't understand half of what I'm doing, following scattered tutorials left and right. Ideally I want this http://va.lent.in/content/images/2014/Jun/list_2.png But I've no idea how to get to this

This is my Manager script

 using UnityEngine;
 using System.Collections;
 using System;
 
 [Serializable]
 public enum CubeGroups {Red, Boing, Black, Green, Roll, Spawner}
 
 public class CubeManager : MonoBehaviour {
 
     public bool startCube;
     public CubeGroups myGroup;
 
     [Header("Smaller Number means longer life")]
     public float lifeTime;
     
     static public float _chrono;
 
     void Start(){
                 _chrono = 25;
         }
 
         void Update(){
 
         _chrono -= Time.deltaTime;
         if (_chrono < 0) {
             transform.tag = "Cube";
         }
         if (!startCube) {
         
             float _a = GetComponent<MeshRenderer> ().material.color.a;
             _a  -= (lifeTime * Time.deltaTime);
             GetComponent<MeshRenderer> ().material.color = new Color (GetComponent<MeshRenderer> ().material.color.r, GetComponent<MeshRenderer> ().material.color.g, GetComponent<MeshRenderer> ().material.color.b, _a);
             if (_a <= 0) {
                 Destroy (this.gameObject);
             }
         }
             
     }
     
 }
 

And this is my attempt at editor window

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using UnityEditorInternal;
 
 public class CubeWindow : EditorWindow {
 
     CubeManager[] cubemag = (CubeManager[])FindObjectsOfType (typeof(CubeManager));
 
     [MenuItem ("Window/Cube Window")]
 
     public static void  ShowWindow () {
         EditorWindow.GetWindow(typeof(CubeWindow));
     }           
 
        void OnGUI() {
 
         GUILayout.Label ("List of Cubes", EditorStyles.boldLabel);
 
         cubemag = (CubeManager[])FindObjectsOfType (typeof(CubeManager));
         for(int i = 0; i < cubemag.Length; i++)
         {
             cubemag[i] = (CubeManager)EditorGUILayout.ObjectField(cubemag[i], typeof(CubeManager));
         }       
     }
 }
 


If anyone know how to do so, and can explain me with a simple step-by-step because I've never fiddled with Unity gui before so I'm completely lost...

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

Answer by RobAnthem · Jan 04, 2017 at 08:29 PM

Well I got it to display for you, the rest is up to you :P

CubeWindow

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using System.Collections.Generic;
 
 public class CubeWindow : EditorWindow //Deriving from editor window to get window and GUI elements.
 {
 
     private CubeManager[] Cubemag; //Obiously your array of target objects
     [MenuItem("Window/Cube Window")] //Declaring to Unity engine that this is meant as a menu item.
     public static void ShowWindow() //Telling unity what MenuItem - "WIndowCube" does.
     {
         EditorWindow cubeWindow = EditorWindow.GetWindow(typeof(CubeWindow)); //Getting our window for unity to use.
         GUIContent titlecontent = new GUIContent("Cube Window"); //Creating some title content.
         cubeWindow.titleContent = titlecontent; //Setting the title content to the window.
         cubeWindow.maxSize = new Vector2(300, 500); //Declaring the max size of the window.
         cubeWindow.minSize = new Vector2(300, 500); //Declaring the min size of the window.
         cubeWindow.ShowPopup(); //Showing our window as a Popup, I.E., a default editor style.
     }
 
 
     void OnGUI() //OnGUI gets called like an Update... very very often, avoid making large data collection calls here.
     {
         EditorGUILayout.BeginVertical(EditorStyles.helpBox); //Declaring our first part of our layout, and adding a bit of flare with EditorStyles.
 
         GUILayout.Label("List of Cubes", EditorStyles.boldLabel); //Making a label in our vertical view, declaring its contents, and adding editor flare.
 
         Cubemag = FindObjectsOfType<CubeManager>(); //Collecting our cube info, I suggest finding a way to do this outside of OnGUI.
         for (int i = 0; i < Cubemag.Length; i++) //Your loop to display the objects, THIS must exist in OnGUI.
         {
             if (Cubemag[i] != null) //Preventing null errors if the objects are removed.
             {
                 Cubemag[i] = (CubeManager)EditorGUILayout.ObjectField(Cubemag[i], typeof(CubeManager), true); //Declaring our object as an object field, with the type of object we want, and allowing scene object.
                 EditorGUILayout.BeginHorizontal(); //Adding a horizontal view to indent our next line so that the properties look like children, LOTS of things you can add like toggles and stuff to reduce this clutter.
                 GUILayout.Space(15); //The indent for our next line, in pixels.
                 Cubemag[i].lifeTime = EditorGUILayout.FloatField("Life Time", Cubemag[i].lifeTime); //the lifeTime property of cubemap can be assigned to a GUI element here.
                 EditorGUILayout.EndHorizontal(); //All layout areas must be closed like this.
 
             }
         }
         EditorGUILayout.EndVertical(); // And closing our last area.
 
     }
 }

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 Sawula · Jan 05, 2017 at 10:56 AM 0
Share

It work! Thank you so much, I should indeed be able to do the rest on my own! Also thanks for all the commenting, it's much more clear now :D

avatar image govi627 · Mar 04, 2019 at 05:34 AM 0
Share

This worked wonders for me thanks

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

63 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

Related Questions

A node in a childnode? 1 Answer

Instantiate to temp var or directly adding to list? 1 Answer

Trying to do custom editor using propertyfield of a List<> but want to stuff each item with a dropdown picklist from another list. 1 Answer

Creating item-packages with properties 2 Answers

Combining Lists 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