Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 3.1 KB

README.md

File metadata and controls

62 lines (45 loc) · 3.1 KB

Generic Scriptable Variables

Unity 2020.1+ License: MIT openupm

Scriptable Variables is package to implement variables in Unity using Scriptable Objects, taking advantage of Unity 2020.1 ability to serialize generic fields.

Warning

This package is considered to be a preview-package. This means:

  • Core features may be incomplete.
  • Functionality has not yet been fully tested and definitely contains bugs.
  • Documentation is incomplete.
  • Code may be uncommented and not following standards

System Requirements

Unity 2020.1.0 or later versions.

Installation

The package is available on the openupm registry at com.jreason.scriptablevariables.
More information can be found at the Installation page.

Usage

There are two main classes in the package: Variable<> and Reference<>

Variable

Variables are assets created in the Unity Editor which store data. A new Variable Asset can be created from the 'Assets/Create/Variable' menu or from the '+' Dropdown in the ProjectView. A Variable's type can be changed in the 'Type' Dropdown.

Variable Types
Before being able to create a Variable Asset of a certain Type, that type needs to be created as a Class. The nessary code to create a Variable type can generate from the 'Type' Dropdown by clicking 'Create new', this only needs to be done once per type. Some Types are pre-setup such as primitives and some more common Unity classes.

Reference

References are how variables are accessed in Code. (e.g. Use Reference<float> to reference a Float Variable.)

    //Reference to Vector3 Variable
    public Reference<Vector3> m_direction;

    private void Update()
    {
        //How to set the value of the variable
        m_direction.Value = transform.forward;

        //Can implicitly cast when getting the value of the variable
        transform.position += m_direction;

        //Sometimes you'll need to do this though
        transform.position += m_direction.Value * Time.deltaTime;
        transform.position += (Vector3)m_direction * Time.deltaTime;  
    }

More information can be found in the Variable page and Reference page

Credits