Coder Social home page Coder Social logo

emmetot / structableobject Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 0.0 19 KB

StructableObject is a wrapper for Unity's ScriptableObject system. It basically just lets you manipulate a data struct as if it were a ScriptableObject. This has been useful in my own development as it allows you to create systems which work well with both procedural data and designed data.

License: MIT License

C# 100.00%
unity-scriptableobject procedural-data wrapper unity3d unity unity-editor

structableobject's Introduction

StructableObject

StructableObject is a wrapper for Unity's ScriptableObject system. It basically just lets you manipulate a data struct as if it were a ScriptableObject. This has been useful in my own development as it allows you to create systems which work well with both procedural data and designed data.

Why

Let's say you have a simple struct which represents some data package. This could be damage information (how much HP, whether it's poison, the damage source...), an enemy AI profile, any small bit of data.

You want to make it so your designers can easily modify this information, so you put it in a ScriptableObject. However, your programmers also want to be able to easily create instances of these data objects at runtime with any kind of modification. Maybe your player gets a damage buff so all your projectiles now take 2x HP. There are many solutions for this. You can create ScriptableObjects without saving them as Unity assets, but that has a lot of overhead. You can make interfaces, but that could require some refactoring and it's a pain when you want to add or remove variables to your data.

I often found myself just putting this information in a struct and serializing that struct in a ScriptableObject. Over time, I began writing custom editors for these ScriptableObjects to make it appear that the struct's contents were the ScriptableObject, to make the experience seamless for designers. Finally, I wrote this generic solution.

How

All you have to do is write a serializable struct:

image

Inherit from StructableObject, giving this struct as a type parameter:

image

And likewise, create a Custom Editor class:

image

The final ScriptableObject appears and works exactly as though you had put the fields right in a ScriptableObject, including supporting undo.

image

The struct can be accessed in code via the .Data property on the StructableObject, but sometimes I add passthrough properties to make it even more seamless.

image

structableobject's People

Contributors

emmetot avatar

Stargazers

Hamza Lazaar avatar Zachary Pitcher avatar Spyridion Georges Fotakos avatar Saleh Ramezani avatar Alon Tzarafi avatar  avatar Spike Liu avatar  avatar Kevin CHABOUD avatar Jack Sydorenko avatar Andy Baker avatar vomrat avatar Jesse Talavera avatar Youngkyoung Lee avatar S. Tarık Çetin avatar mika avatar SPHYNX avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.