Custom GameObjects

Is it possible to derive your own GameObjects in script? I have a custom Sprite component that I add to an empty GameObject, but you can only see the sprite at runtime.

If I can make my own custom GameObject class, I should be able to embed the Sprite code into the class and have it render inside the editor. Is it possible to do this?

If not, are there any other ways to make aspects of a component show up in the browser?

I never tried … give it a shot! :slight_smile:

Usually if I need to see things in the editor, I’ll create an empty GameObject, add the scripts to it and then turn it into a prefab. Then you can use the whole thing like any other object in the editor.

Depending on your needs, using a gizmo icon may be enough.

Those are both good ideas, thanks!

This is somewhat of a hack, but you can use OnDrawGizmos to set things up in the editor.

Here’s a bit of code that I use to build a sprite whenever the sprite texture is changed in the inspector:

var spriteTexture : Texture2D;
private var oldTexture : Texture2D;

function OnDrawGizmos () {
	if (spriteTexture != oldTexture) {
		UpdateSprite();
	}
}

When spriteTexture and oldTexture go out of sync OnDrawGizmos detects the change and calls UpdateSprite(). UpdateSprite() creates a poly quad of the appropriate size, applies a sprite material, and so on. Finally, it sets oldTexture equal to spriteTexture so that it will be ignored by OnDrawGizmos() until the next change.