• 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
0
Question by Malharhak · Apr 29, 2012 at 04:39 PM · prefabscontentlevel design

How to manage list of contents²

Hello,

I am working on a mall building sim. So I have a list of "shops" and stuff like that, which will have different properties and so on.

I am wondering what is the best way to manage the list so I can easily add / delete elements and then call them in my game. The best would be to be able to tweak them directly in the inspector.

I thought of using prefabs but the problem is that I will have to assign manually the prefabs to the elements that use them...

Does anyone knows a nice and clean way to manage game content ?

Thanks :)

Comment
Add comment · Show 1
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 syclamoth · Apr 29, 2012 at 04:41 PM 0
Share

Very "big" question. You're asking about high-level design here! I'm honestly not sure I understand what you're asking.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Apr 29, 2012 at 05:39 PM

You want Array, or HashTable, or ArrayList. ArrayList is very popular. And you want to make a 'struct' or 'class' containing the data you want. Ex:

In jscript:

class Shop { var name : String; var location : Transform; var address : String; var owner : String; var inventory : ArrayList; }

Then you can use the methods on ArrayList as described here to add, delete, access lists of Shops, and note I put 'inventory' as an ArrayList also, so each shop has a list of its own containing inventory classes. I'll leave it to you to determine what goes there, but I would think product name, UPC, price, manufacturer, etc.

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 Malharhak · Apr 29, 2012 at 05:30 PM

Well basically I'm looking for a nice way to manage my gameObjects list. For exemple on an adventure game if I want to create 300 ennemies, how would I manage them ? Like, storing them on prefabs, creating a file describing them ?

I need a way to be able to get the list and use it easily in my game, without having to manually assign / unassign any new object I create

Comment
Add comment · Show 1 · 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 DaveA · Apr 29, 2012 at 05:34 PM 0
Share

This should have been either a comment on your question, or you should edit your question, but not answer it.

avatar image
0

Answer by bompi88 · Apr 29, 2012 at 05:08 PM

I think I would have started with setting up some basic classes, like Shop and so on. which include the basic shop properties which all shops have. An example: Area, customers, opening times etc. Then I would have created some classes like: ElectronicsStore, FoodsMarket etc. which inherit from the class Shop and will include information like the name of the shop and the reference to a prefab for this shop and etc.

Then when you build a shop, you just make a object of one of the classes (for example: FoodsMarket) and sets its properties and prefab to use. You have to be familiar with classes though. You can also go a step further and make classes like BobsCoolShop etc, which inherit for example from a class of ToyStore.

Comment
Add comment · Show 2 · 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 Malharhak · Apr 29, 2012 at 05:25 PM 0
Share

Yes, that's the kind of thing I have in mind, but then I'm wondering how would I be able to get the entire list of shop so I can easily use it (in shop selection menu for exemple) ?

avatar image bompi88 · Apr 29, 2012 at 05:50 PM 0
Share

you could tag all your prefabs to "Shop" and for example do:


GameObject[] shops = GameObject.FindGameObjectsWithTag("Shop");

And then get your respective properties from each GameObjects in the array shops. like:


Debug.Log(shops[0].type);

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Stacking level blocks in an Infinite runner game 2 Answers

How to load html content 2 Answers

Best Practice for Multiple Languages? 6 Answers

using WWW to upload prefabs/game objects in webplayer... help 1 Answer

How to trigger different prefabs (JavaScript) 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges