Coder Social home page Coder Social logo

scriptableobjects-oriented's Introduction

ScriptableObjects Oriented

Provide tools for an Unity architecture based on ScriptableObjects (SO).
The philosophy of this plugin is based on that conference.

Create a SO Event

A SO Event is a ScriptableObject that can raise event.
Since the event is an asset with a static number of parameter, you will probably create a lot of SO event asset.

Create a SO Event from scratch just to change the type of parameter or add new one of your event can be redundant and time-consuming, a little wizard is provided to help you.

  • Assets -> Create -> SO -> Create -> Event
  • The wizard will appear
  • Set the event name. It will define the class name.
  • [Optional] Set the category name. It will define its location in the "Create" asset menu.
  • [Optional] Set the number of parameters
  • Set the parameter name
  • Set the parameter type name OR use the preset box to select common types so you don't have to write it.
  • Click "Create" when you are done
  • Let Unity compile and you should now be able to create a new event from Assets -> Create -> SO -> [Your Category] -> [Your Event Name]

You can add more types with the settings.

Using SO Events

Just declare your SO Event in your class, as it is a standard C# class.
You can dynamically add listener, remove listener and raise event, like in any standard event system.
However, now you can select the SO Event in the Project tab and you will see that you have additional informations.
All these data are editor-only so no overhead in your final build.
You can :

  • Add a description : you can give extra datas to explain where it should be called.
  • Set some parameters : these parameters will be used when you click on Raise
  • Raise the event : it will trigger the event using the above parameters Raising the event is really useful to manually test isolated system.

SOEventMode Attribute

You can add a SOEventMode attribute on your event field to explicitly tell to the world if your event will be a listener or a broadcaster.
It will allow you to be more explicit on the use of an event, visible from the Unity Inspector, next to the event field.

  • Broadcaster : Broadcaster icon
  • Listener : Listener icon

Examples :

[SOEventMode(SOEventActionMode.Broadcaster)]
public SOMyEvent eventBroadcaster;

[SOEventMode(SOEventActionMode.Listener)]
public SOMyEvent eventListener;

Atomics

Multiple basic types are available when the plugin is installed. These one are called "Atomics" as they are really small sized data.
They are available from the Assets -> Create -> SO -> Create -> Atomics menu.

Are supported :

  • SO Bool
  • SO Integer
  • SO Float
  • SO String
  • SO Vector2
  • SO Vector3
  • SO Quaternion (not editable via Euler angles yet)
  • SO Integer Clamped : an integer that can be clamped by minimum, maximum or both. If both is selected, a slider will be available.
  • SO Float Clamped : a float that can be clamped by minimum, maximum or both. If both is selected, a slider will be available.

SO Integer Clamped Example

Containers

Containers are available from the Assets -> Create -> SO -> Create -> Containers menu.
Use the wizard to create your custom container types. Once it is done, you will be able to create new ScriptableObject from it.

Are supported :

  • SO List : it is the equivalent of a simple List

SO List Float Clamped Example

SO Variable Mode Attribute

To improve how your SO variables are used in your code, you can add a special attribute that will be shown in the Inspector.
Are supported :

  • Read Only Read Only Icon : expect to be used by the script but never written by it
  • Write Only Write Only Icon : expect to be feed from the script but never read from it (like writing the result of a calculus for example)
  • Read & Write Read Write Icon : expect to be read and feed by the script

Example of SO variable mode attribute

Examples :

[SOVariableMode(SOVariableActionMode.ReadOnly)]
public SOFloat numPlayers;

[SOVariableMode(SOVariableActionMode.WriteOnly)]
public SOFloat result;

[SOVariableMode(SOVariableActionMode.ReadWrite)]
public SOList<Player> playerList;

Constant & Runtime

To continue improving the use of your SO variables, you can indicate tell if you expect your SO variable to be a constant or a runtime variable.

  • Constant Constant Icon : a fixed data that should be read only.
    Examples : the minimum & maximum player speed, the camera lerp interpolation speed.
  • Runtime Runtime Icon : a runtime data that should be filled during the game.
    Every "Runtime data" should be reset (call variable.Reset()) at the Start (generally, by the script that will feed it).
    Examples : list of players in a multiplayer game, current score, current time, current player life etc.

Changing the mode is easy. Just inspect your SO variable and set the mode.
Changing SO variable mode

When the SO variable is bound in a slot, the icon is displayed.
See SO variable mode

Settings

The settings allow to improve the SO Wizards (Events & Variables).
Start by creating a new one.

  • Assets -> Create -> SO -> Create -> Settings
  • Add additional types
  • Open the SO Event Wizard and link the settings
  • Your new types are now available among the presets

scriptableobjects-oriented's People

Contributors

abegue avatar begounet avatar leapperture avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

scriptableobjects-oriented's Issues

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.