Unity3D – Custom classes appear on Inspector

Hi folks,

Long time no see.

 

Let me teach you something I’ve learned some time ago. In Unity3D, we can create a custom class and make it appear in Inspector, just like other classes like Transform and GameObject, just like this:

Screen Shot 2013-01-23 at 3.43.52 PM

 

 

 

 

 

 

 

 

 

 

 

 

But we can do more: let’s imagine a real game-programming situation: We’d like to implement an item shop in our game. So, basically, we need some information about this item like: name, description, image, price, whether it’s bought or not… So, we can wrap it all together now. Let’s stop talking and start:

 

First, create an empty Game Object. After, create a new C# script and name it “Shop”. Open it and lets start programming.

 

An empty class will seem like this:

 

Screen Shot 2013-01-23 at 4.01.20 PM

So, after the last right bracket, write this:

 

public class ShopItem

{

public string name;

public string description;

public Texture2D texture;

public int price;

public bool bought;

}

 

So, on the top of our script, right after public class Shop : Monobehaviour {, type

 

public List<ShopItem> shopItens;

 

To use Lists and Dictionarys, onde the top of our script, just use:

 

using System.Collections.Generic;

 

Now, drag this script to our empty Game Object and no custom parameters should appear yet. That’s because we didn’t tell Unity that our custom class need to be serialized. So, to serialize our custom class, just write this above ShopItem’s class:

 

[System.Serializable]

 

It now puts MetaData to the class which could be retrived by reflection and used by Unity. With this Unity knows that it should/can serialize the class.

 

Just come back to Unity and the public attribute ShopItens should appear, like this:

 

Screen Shot 2013-01-23 at 4.08.35 PM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

That can be an easy way to give your project to Level Designer responsible or just to change/add/remove itens from your shop.

 

Thanks for all. Here’s the full script.

 

Screen Shot 2013-01-23 at 4.11.38 PM

 

Advertisements

Creating a Workplace.

Little by little we are assembling our workspace, here we share the first steps from our start in a empty office until it became de cosy place where we work everyday.

Pouco a pouco estamos montando nosso espaço de trabalho, aqui nós mostramos os primeiros passos, de quando começamos com nosso escritório vazio até se tornar o local aconchegante no qual  trabalhamos todos os dias. 

"An empty room, full of potencial"

"The office is ready for us to work  at full steam"

Pixel Art.

Hello everyone!

Here is pixel art caricature of the 3 members of the Overtime! The first one is “J” our angelic programer with a pure heart, the middle one is Costalonga, our hiperactive coffee addicted artist, and the last one is Stiven, our workaholic artist with a “Steve Jobs” complex.

Olá pessoal!

Aqui está uma caricatura em pixel art dos 3 membros da Overtime! O primeiro é “J” nosso programador angelical de coração puro; o do meio é Costalonga, nosso artista hiperativo viciado em café; e o último é Stiven nosso artista workaholic com complexo de Steve Jobs.

First Game Announcement

Hi everyone!

Overtime Studios is proud to announce it’s first game “SUSHIBOMB”. For starters here’s the official logo! We’ll be back soon with more news, stay tunned!

Olá Galera!

O Overtime Studios orgulhosamente anuncia seu primeiro jogo “SUSHIBOMB”. Para começar aqui está o logo oficial! Voltaremos em breve com mais novidades, fiquem ligados!

Hello World

Hi everyone,

As programmer of Overtime Studios, nothing like start as “Hello World”. This is our born. The beginning of all. Here, starts out journey to success and famous. We’ll get there.

But, exactly, who are we?

Let’s get started.

José João de Oliveira Júnior (Jay) – Programmer. A formed Game Designer by Anhembi Morumbi. Programmer as well. Flash and Unity 3D programmer (Actionscript 3.0 and C#). By now, I’m only working with Flash (blah!). It’s not the most awesome software to develop but… You know, we must start from low.

Fabio Costalonga – Artist 2D and Marketing guy. A formed publicist that also know how to draw (very well by the way). Beginning in Flash platform and awesome on character design. A friend that every person has to have. Always with smile and jokes.

Stiven Valério – 2D Animator. This guy knows what he’s doing. Designer since 3 years-old (okay, just kidding), his drawings is like a keyframe of a complex animation. You keep looking for the next frame. Every art can be named as art. He’s like God on Earth (oh-oh, I just got to far here).

Nice to meet you all.

We have just create the most awesome company that makes the most awesome games by the most awesome people. Just like that. Keep that in mind. 😉