Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by bridged · Jul 17, 2012 at 11:19 AM · textinspectoreditorguilabeltitle

Simple headline / title for a Script in the Inspector

Hey,

imagine I have the following code:

 public bool There;
 public bool are;
 public float a;
 public int lot
 public int of
 
 public _________1;
 
 public GameObject variables;
 public Transform in;
 public float my;
 public ray Script;

This is the way I do a kind of headline / tile atm to get the code a little more clearly to see. I know that I should do this with the editorGUI, but I have to do so much more extra stuff for it.

Isn't there a simple way to just put a text / headline / title / label somwhere between the variables that are listed from a script in the Inspector without all that editorGUI stuff?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Stardog · Nov 17, 2014 at 01:06 AM

The answer here is no longer true. There are new PropertyDrawers/DecoratorDrawers in Unity 4.X (4.5?).

http://va.lent.in/interesting-things-in-unity-4-5-you-probably-didnt-know-about/

 [Header("Hi there!")]
 public string TheHeader = "Header!"; 
 
 [Tooltip("This is THE VALUE!")]
 [ContextMenuItem("Reset", "resetTheValue")]
 public float TheValue = 42.0f;
  
 [Space(50)]
 public string TheString = "THE STRING";

 [ContextMenu("Reset The Value")]
 private void resetTheValue()  
 {
     TheValue = 42;
 }
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
avatar image
2

Answer by Bilelmnasser · Jun 06, 2014 at 08:11 PM

yes you can, editor take custom class as 1 element and group her element under one group, but the class need to be serializable, that he can do save your in data in inspector. you can simply using your logical grouping of element organize your prefabs/objects/variables in public serializable classes like the code below attach it to any gameobject in your scene, inspector show organized elements in logical groups :)

 using UnityEngine;
 using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Xml.Serialization;
 
 [Serializable]
 public class person{
     
     
     [SerializeField]
     public GameObject Head ;
     [SerializeField]
     public Color  SkinColor;
     
     [SerializeField]
     public GameObject[] BodyParts;
     
     
     
     
     
 }
 
 [Serializable]
 public class world{
     
     [SerializeField]
     public GameObject center ;
     [SerializeField]
     public Transform  terrain;
     
     [SerializeField]
     public GameObject[] WorldObjets;
     
     
     
     
     
     
 }
 public class NewBehaviourScript : MonoBehaviour {
     
 
     
     public world WorldPrefab;
     public person [] PersonPrefabs=new person[100];
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

 

alt text


screenshot_1.png (12.4 kB)
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
avatar image
0

Answer by Piflik · Jul 17, 2012 at 11:38 AM

In Javascript you can do something like this.

 class ScriptNameAnything {
 
 //variable declaration here
 
 }

These are not really headlines, but a way to organize your variables in different groups. See the CharacterMotor script in the Character Controller asset package.

Not sure if/how this can be done in C#, though.

Comment
Add comment · Show 5 · 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 bridged · Jul 17, 2012 at 11:48 AM 0
Share

you mean simple comments, don't you?

Thx but I'm already using comments =D (I think I wouldn't even had to install unity if I didn't know how to use comments ^^ ) But I wanted something to see in the Inspector not in $$anonymous$$onoDevelop.

Still thx!

avatar image Piflik · Jul 17, 2012 at 11:54 AM 0
Share

No, not comments, classes. If you have a look at the character$$anonymous$$otor script, you will see that it has several groups in the Inspector that can be opened and closed to reveal the variables that are part of that class.

avatar image Piflik · Jul 17, 2012 at 12:12 PM 0
Share

I'll give you an example. The script itself doesn't do much (since it is just an abandoned test script), but when you add this to any object, you will see an expandable group called 'Variables' in the Inspector.

 #pragma strict
 
 class FPS_ControllerVariables {
  var movSpeed : float;
  var rotSpeed : float;
  var gravity : float = 10.0;
  var maxVelocityChange : float = 10.0;
 }
 
 var variables : FPS_ControllerVariables = FPS_ControllerVariables();
 
 private var isGrounded : boolean = false;
 
 function Awake() {
  rigidbody.freezeRotation = true;
  rigidbody.useGravity = false;
 }
 
 function FixedUpdate() {
  if(isGrounded) {
  var targetVelocity = transform.TransformDirection(Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))) * variables.movSpeed;
  var velocity = rigidbody.velocity;
  var velocityChange = targetVelocity - velocity;
  
  velocityChange.x = $$anonymous$$athf.Clamp(velocityChange.x, -variables.maxVelocityChange, variables.maxVelocityChange);
  velocityChange.y = 0;
  velocityChange.z = $$anonymous$$athf.Clamp(velocityChange.z, -variables.maxVelocityChange, variables.maxVelocityChange);
  
  rigidbody.AddForce(velocityChange, Force$$anonymous$$ode.VelocityChange);
  
  //rigidbody.velocity = transform.TransformDirection((Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))) * movSpeed);
  //transform.Translate(Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * movSpeed * Time.deltaTime);
  transform.Rotate(Vector3(0, Input.GetAxis("$$anonymous$$ouse X"), 0) * variables.rotSpeed);
  
  if(Input.GetButtonDown("Jump")) {
  rigidbody.velocity.y = 20;
  }
  }
  
  rigidbody.AddForce(Vector3(0, -variables.gravity * rigidbody.mass, 0));
  
  
  isGrounded = false;
 }
 
 function OnCollisionStay() {
  //if(floor.gameObject.tag == "floor") {
  isGrounded = true;
  //}
 }
avatar image .sanders · Jul 17, 2012 at 12:34 PM 0
Share

True, same for c-sharp. But you need to make that extra "values-container"-class Serializable though. Else Unity will not show those values in the inspector. Anyway in that case you are creating some ($$anonymous$$imal, but extra) overhead at runtime since it will need to do an extra lookup every time you access a value of that extra class, which is not optimal.

avatar image bridged · Jul 17, 2012 at 01:08 PM 0
Share

runtime?

I just want to have a more clearly variable list while making games =D

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Easy text in the inspector 2 Answers

Custom inspector editor - how to put new editor fields in a specific place 1 Answer

How do I make a field that accepts a scene object that is linked to a prefab? EditorGUILayout.ObjectField does not allow this. 0 Answers

Text in the scene is not being updated! 0 Answers

CustomPropertyDrawer with UnityEvent 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