x


How to provide assets to a static class?

I'm new to C# and Unity both, but trying to make use of design patterns I've seen elsewhere -- and so far, this seems like a very mature and capable environment. But I'm a bit stuck on one minor thing:

I have a static class that manages some item definitions for my game. There's no need to attach it to anything, as all the services it provides are global. All works fine when the definition data is hard-coded into the class, but now I'd prefer to define these in text files included in the project as text assets.

But now I'm stuck: if my script were a MonoBehavior, and instantiated as a component of some game object, I could give it a TextAsset property and assign the file through the inspector. But, being a static script, I don't see how that will work. I can think of a few hackish work-arounds, like attaching my TextAsset to some unrelated game object and finding it via GameObject.Find and GetComponent, but that doesn't seem very appetizing.

Is there some cleaner solution you would recommend?

more ▼

asked Feb 23 '11 at 02:44 AM

JoeStrout gravatar image

JoeStrout
177 8 8 16

What is the benefit of turning it into a text asset? Will you have multiple versions of the file and choose the one to be used dynamically? If not then why not just stick with the text (code) file that you have? "Hard-coding" is much softer in Unity than in other (precompiled) environments. Just a thought.

Feb 23 '11 at 04:14 AM yoyo
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
more ▼

answered Mar 24 '11 at 08:00 AM

Simon Wittber gravatar image

Simon Wittber
293 5 6 14

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x276
x42

asked: Feb 23 '11 at 02:44 AM

Seen: 861 times

Last Updated: Feb 23 '11 at 02:44 AM