3

is there anyway to draw stuff on scene view without calling OnSceneGUI?

or is there a way to get OnSceneGUI to get called even if the object with the script attached is not selected?

Edit: Looks like I wasn't explicit enough on what I was asking for so here's a little update:

I have a whole bunch of controls shown as GUI objects on my Game Scene that are used by the game designers to more easily test the game. Since these tools are for development use rather than deployment, I wanted to move these to the scene window instead.

Unfortunately I am only able to display these GUI tools if the object that contains the script with the "OnSceneGUI" method is selected. Instead I want them to be displayed whenever the game is running and regardless of the selected object.

4

2 回答 2

2

I have found the solution to my issue.

If you want your GUI stuff to always be displayed on the scene window you can do the following:

public class MyClass{
    static MyStaticConstructor() {
        SceneView.onSceneGUIDelegate += OnScene;
    }
    static void OnScene(SceneView sceneView) {
        // Draw GUI stuff here for Scene window display
    }
}

This code will run as soon as you press play and will draw whatever you wish on your scene window.

Hope it will help others!

于 2013-11-14T11:13:45.390 回答
1

There are many ways to use GUI, The easiest but least efficient way is using the GUI class on OnGUI()

GUI.Label(new Rect(10,10,10,10), "This is a label");
GUI.Label(new Rect(10,10,10,10), "Your Texture2D here");

Any active monobehaviour will run OnGUI() if its defined. So it can be attached to any gameObject. You can create an empty gameObject in the scene and call it "GuiGameObject" for example and attach the script there. That way it wont be mixed in with your gameplay script.

There are also GUI textures --> More Info on GUITexture

Also I recommend checking out nGUI

Edit: For OnSceneGUI You can try Editor.Repaint, you can use it to make sure that the inspector updates changes made inside of OnSceneGUI

于 2013-11-13T15:31:00.177 回答