- Home /
Can Editor Windows function like the inspector ?
Hi. In the inspector window, we can have multiple objects with rigidbodies with different mass values. upon selecting one of these objects the mass value asscociated with the selected object is displayed in rigidbody in the inspector. At runtime , each object reads from its mass value.
Can Editor Windows be created to execute functions at runtime in the same way and for each object that I select , the editor windows will display only the values associated with the selected object ?
If so then How do I go about implementing it. I would be grateful for any examples.
Answer by immersiveGamer · Jan 26, 2015 at 03:14 AM
I think you have the Editor Windows a bit confused with components. Each game object has a component on it. When you select a game object it shows each of the components on the game object, like the rigidbody.
Editor Windows are not run at runtime if you try to use any actual Editor Window. What you want is to create a script. When you create a script in Unity it will act like a component. This way you can drag the script onto your game object and it will be like a component. Any public variables in the script will shown in the inspector and you can change them for each object, just like the mass value on the rigidbody.
Here is an example script:
using UnityEngine;
using System.Collections;
public class ScaleScript : MonoBehaviour {
//since this is public it will show in the inspector.
//even though it is set to 1 here if we change it in the
//inspector it will stay as the value we changed it to.
public float scale = 1.0f;
// Use this for initialization
void Start () {
//multiplies the current scale by the SCALE variable.
gameObject.transform.localScale = gameObject.transform.localScale * scale;
}
// Update is called once per frame
void Update () {
}
}
Here is what it looks like in the inspector. I've put it on each sphere and set the scale to a different value. When we run the scene it changes each one to the value we had set it to. This is like the mass we would set for the rigidbody.
Now there are Editors that you can make to make the script look nicer and fancier and editor windows that are not attached to any object, but for either to work with a game object you need to have a script coded and put on it first like above. I do apologize if this is not what you are looking for. You question was a bit hard to read and understand. Please leave a comment if you need clarification or a different answer.
this really cleared up my misunderstanding . thank you very much . so its only a matter of exposing the variables in script so that the editor window can access them.
Answer by cdrandin · Jan 26, 2015 at 02:51 AM
Can Editor Windows be created to execute functions at runtime in the same way and for each object that I select , the editor windows will display only the values associated with the selected object ?
Yes it can be.
Here are some references.
Format the window to your liking. If you want to execute some arbitrary code. Use the selector method. Determine what type you are dealing with executes its respective code.
Your answer
Follow this Question
Related Questions
ReImport in c# of GameObjects only for Scene Objects, not assets? 1 Answer
TexturePropertySingleLine in Editor class 0 Answers
Custom Inspector - How to add functionality? 1 Answer
Editor Script, Index Out of Range Exception after Play 1 Answer
Gizmos.DrawLine is dissapearing after returning to editor after Playing the scene 0 Answers