0
\$\begingroup\$

My team is switching to Unity 3D for an upcoming project. I'm tasked with converting our game data system into Unity.

Our existing games use spreadsheet documents (Google Docs) for designers to set values and formulas. This is then exported into an XML doc (and obfuscated) and read in by our game client. I'm trying to figure out a way to accomplish this same thing but solely through Unity. Storing, exposing, and reading data through Unity is pretty straightforward but I'm not sure on supporting formulas.

I realize I can write a custom parser and interpreter which can handle formulas but I'm wondering if there is already a way to do this in Unity.

For example, let's say I have a unit with various stats: Level, Max HP, HP, Damage, Victory Reward, etc. That unit may receive a reward after combat which is based on its Level and remaining HP. A designer would be able to enter into the Victory Reward field either a flat value, like 3, or a formula such as "Floor({Level} * ({HP} / {Max HP}))", something like that.

My question is basically, is there an existing solution for handling data with formulas in Unity, via a downloadable asset or something in Unity itself, or is there a simple framework or technology which already can do something like this which can be easily integrated (example: some kind of JSON extension which supports self-referencing other values and basic mathematical/logical operations)?

\$\endgroup\$
  • \$\begingroup\$ Store formulas or load specific spreadsheet formulas format? \$\endgroup\$ – wondra Apr 4 '17 at 16:39
  • \$\begingroup\$ The formula should be stored but then interpreted when the client starts up. \$\endgroup\$ – Nick Gotch Apr 4 '17 at 16:43
  • \$\begingroup\$ Do you need to store those formulas in Unity? Or would it be acceptable to process the formulas in your Google Docs spreadsheet to produce the outputs you need in a particular range of cells, export the sheet as xml or csv, and import the result as a TextAsset? That way you're not spending development effort duplicating functionality that Google Docs already handles for you, and you don't need to worry about bugs where a formula is interpreted differently by the two tools. \$\endgroup\$ – DMGregory Apr 4 '17 at 16:45
  • \$\begingroup\$ That's the thing, I'd really like to have it all in Unity and get away from importing the spreadsheet from Google Docs. Over the years we've found issues with this (the spreadsheet is independent of code branches/streams and caused issues, etc). If it comes to it I can go with another import system but I'd like to just have it all in Unity itself. \$\endgroup\$ – Nick Gotch Apr 4 '17 at 16:47
1
\$\begingroup\$

The canonical way in Unity to create "data-assets" is by implementing ScriptableObject's. This allows you to create a custom type of asset which you can then create and maintain in the Unity editor (optionally using some custom editor controls which you also need to program). This would allow you to create aUnitType asset with all the fields mentioned in the question and then assign the UnitTypes to units in the scene.

But you might have a hard time to create these automatically from Google Docs spreadsheets.

Formulas are game mechanics, not game data. So they should be hard-coded into scripts. If you prefer to have all your mechanical formulas in one place, you could do so by implementing them all as static methods in a stateless class.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.