Freyja Data Asset

Freyja Data Asset provides a flexible and efficient way to manage data assets in Unity projects.

Features

  • Data Asset Definition: Create custom data assets for various types of data.

  • Data Asset Persistence: Persist data asset references and values across scenes.

  • Data Reference System: Easily reference and use data assets in scripts.

Requirements

  • Unity 2021.3.22.f1 or later

  • Odin Inspector 3.1.14.3

Dependencies

Name
Tags

Installation

  1. Install from Unity Package Manager -> (Window -> Package Manager -> Add package from git URL)

Example Usage

Create Data Asset

SwordData
using System;

[Serializable]
public class SwordData
{
     public int Damage;
     public int Strength;
}
SwordDataAsset
using Freyja.DataAsset;

using UnityEngine;

[CreateAssetMenu(menuName = "Test/Runtime/" + nameof(SwordDataAsset))]
public class SwordDataAsset : DataAsset<SwordData>
{
    
}

Create Reference Data Asset

PlayerData
using System;

using Freyja.DataAsset;

[Serializable]
public class PlayerData
{
    public string Name;

    public DataReference<SwordData> SwordDataReference;
}
PlayerDataAsset
using Freyja.DataAsset;

using UnityEngine;

[CreateAssetMenu(menuName = "Test/Runtime/" + nameof(PlayerDataAsset))]
public class PlayerDataAsset : DataAsset<PlayerData>
{
  
}

Call Data Asset & Data Asset Reference

DataAssetManager
using UnityEngine;

public class DataAssetManager : MonoBehaviour
{
    [SerializeField]
    private PlayerDataAsset m_playerdataasset;

    private void Start()
    {
        Debug.Log(m_playerdataasset.Value.Name);
        Debug.Log(m_playerdataasset.Value.SwordDataReference.Value.Strength);
    }
}

Last updated