Skip to content

mtaha3249/SO-Architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scriptable Object Architecture

This is a scriptable object architecture followed by Ryan Hipple Talk.

This package is made from Unity 2020.3.0f1


How to create Scriptable Object?

To create scriptable object right click in Project Window => Create => SO-Architecture

Screenshot 2021-09-26 at 3 51 45 PM


How to add event listener?

Add a script named as GameEventListener.cs

Screenshot 2021-09-26 at 3 58 11 PM

API

// Event to Listen
public GameEvent Event;
// public Unity Event, which to be happen when event is raised
public UnityEvent<object[]> Response;

How to Create New Variable Type?

Go to the Menu Item => SO-Architecture => New Variable Type

Screenshot 2021-09-26 at 4 38 50 PM

Now you will see a window open

Screenshot 2021-09-26 at 4 38 59 PM

In this picture you see, assign a new variable type that can be variable type i.e. float, bool, int, LayerMask or any custom struct or enum. These given type are already created using this window

  • Bool
  • Int
  • Float
  • Vector2
  • Vector3
  • GameObject
  • Transform
  • Quaternion

How to get event callback?

In your class simply implement the interface IGenericCallback.cs, and write you functionality in the generated function. You can parse variable from object to any type. If you don't know about parsing data follow this link.

Code Example

In this example you can see i am handling the callback of integer, and parsing the variable.

using UnityEngine;

public class IntegerCallback : MonoBehaviour, IGenericCallback
{
    /// <summary>
    /// Event Callback
    /// </summary>
    /// <param name="param">parameter fetch</param>
    public void OnEventRaisedCallback(params object[] param)
    {
        int value = (int) param[0];
        
        Debug.Log(value);
    }
}

How to Raise Event?

In your class implement the interface IRaise.cs, and give the type of event you are going to raise.

Code Example

In this example you can see i am raising the integer event. You can implement multiple interface for multiple type raising, or you can raise event manually.

using UnityEngine;

public class RaiseInteger : MonoBehaviour, IRaise<int>
{
    /// <summary>
    /// Event to raise
    /// </summary>
    public GameEvent _gameEvent;

    /// <summary>
    /// Raise integer event base on given value
    /// </summary>
    /// <param name="value">value to pass</param>
    public void Raise(int value)
    {
        _gameEvent.Raise(value);
    }
}

How to fetch value from variable?

In your class create a variable type of Generic Reference, and pass the type of variable you want to create. You can see the variable in the inspector.

ezgif com-gif-maker

Code Example

using UnityEngine;

public class FetchInteger : MonoBehaviour
{
    /// <summary>
    /// Variable of integer type
    /// </summary>
    public GenericReference<int> _variable;

    /// <summary>
    /// Fetch Variable
    /// </summary>
    public void FetchVariable()
    {
        Debug.Log(_variable.Value);
    }
}

About

Scriptable Object Architecture

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages