Freyja File System
Freyja File System makes it easy to create files and directories with unity
Requirements
Unity 2021.3.22.f1 or later
Dependencies
Installation
Install from Unity Package Manager -> (
Window -> Package Manager -> Add package from git URL
)

Copy and Paste this URL link https://github.com/winartodev/Freyja-File-System.git
If
Freyja File System
successfully installed will look like this

Example Usage
Handle Directory
Create two C# scripts
TestHandleDirectory.cs
(used for core scripts)TestCreatingDirectoryEditor.cs
(use for operations in unity editor)
using System;
using Freyja.FileSystem;
using UnityEngine;
public class TestHandleDirectory : MonoBehaviour
{
[SerializeField]
private string m_DirectoryName;
private FreyjaDirectory _freyjaDirectory;
public string DirectoryName
{
get
{
if (string.IsNullOrEmpty(m_DirectoryName))
{
return string.Empty;
}
return m_DirectoryName;
}
}
public string GetFullPath()
{
_freyjaDirectory = new FreyjaDirectory();
return _freyjaDirectory.Path + "/" + m_DirectoryName;
}
}
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TestHandleDirectory))]
public class TestHandleDirectoryEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
var script = (TestHandleDirectory)target;
if (GUILayout.Button("Create Directory"))
{
// TODO: Creating Directory
}
if (GUILayout.Button("Delete Directory"))
{
// TODO: Delete Directory
}
if (GUILayout.Button($"Directory {script.DirectoryName} Is Exists"))
{
// TODO: Check Directory Is Exists
}
}
}
#endif
Add
TestHandleDirectory.cs
into inspector

Create Directory
Create function
CreateDirectory()
insideTestHandleDirectory.cs
public void CreateDirectory()
{
_freyjaDirectory = new FreyjaDirectory();
try
{
if (string.IsNullOrEmpty(DirectoryName))
{
throw new ArgumentNullException();
}
if (!_freyjaDirectory.DirectoryExists(DirectoryName))
{
_freyjaDirectory.CreateDirectory(DirectoryName);
}
}
catch (ArgumentNullException e)
{
Console.WriteLine(e);
throw;
}
}
Add
CreateDirectory()
intoTestHandleDirectoryEditor.cs
if (GUILayout.Button("Create Directory"))
{
script.CreateDirectory();
}
Delete Directory
Create function
DeleteDirectory()
insideTestHandleDirectory.cs
public void DeleteDirectory()
{
_freyjaDirectory = new FreyjaDirectory();
try
{
if (string.IsNullOrEmpty(DirectoryName))
{
throw new ArgumentNullException();
}
if (_freyjaDirectory.DirectoryExists(DirectoryName))
{
_freyjaDirectory.DeleteDirectory(DirectoryName, true);
}
}
catch (ArgumentNullException e)
{
Console.WriteLine(e);
throw;
}
}
add
DeleteDirectory()
intoTestHandleDirectoryEditor.cs
if (GUILayout.Button("Delete Directory"))
{
script.DeleteDirectory();
}
Check If Directory Exists
Create function
DeleteDirectory()
insideTestHandleDirectory.cs
public void DirectoryIsExists()
{
_freyjaDirectory = new FreyjaDirectory();
try
{
if (string.IsNullOrEmpty(DirectoryName))
{
throw new ArgumentNullException();
}
Debug.Log(_freyjaDirectory.DirectoryExists(DirectoryName));
}
catch (ArgumentNullException e)
{
Console.WriteLine(e);
throw;
}
}
add
DeleteDirectory()
intoTestHandleDirectoryEditor.cs
if (GUILayout.Button($"Directory {script.DirectoryName} Is Exists"))
{
script.DirectoryIsExists();
}
Handle Files
Notes:
Before we create a new file prefer we should first prepare the directory
Create two C# scripts
TestHandleFile.cs
(used for core scripts)TestHandleFileEditor.cs
(use for operations in unity editor)
using System.Collections.Generic;
using Freyja.FileSystem;
using UnityEngine;
public class TestHandleFile : MonoBehaviour
{
private enum FileType
{
Sav,
Json,
Txt,
}
private Dictionary<FileType, string> FileTypeMap = new Dictionary<FileType, string>()
{
{ FileType.Sav, ".sav" },
{ FileType.Json, ".json" },
{ FileType.Txt, ".txt" },
};
[SerializeField]
private TestHandleDirectory m_TestHandleDirectory;
[SerializeField]
private string m_File;
[SerializeField]
private FileType m_FileType;
[SerializeField]
[TextArea]
private string m_Text;
private FreyjaFile _freyjaFile;
private void Reset()
{
m_TestHandleDirectory = FindObjectOfType<TestHandleDirectory>();
}
}
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TestHandleFile))]
public class TestHandleFileEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
var script = (TestHandleFile)target;
if (GUILayout.Button("Create File"))
{
}
if (GUILayout.Button("Read File"))
{
}
if (GUILayout.Button("Delete File"))
{
}
}
}
#endif
Add
TestHandleFile.cs
into inspector

Create File
Create function
CreateFile()
insideTestHandleFile.cs
public void CreateFile()
{
_freyjaFile = new FreyjaFile();
try
{
if (string.IsNullOrEmpty(FullPath))
{
throw new ArgumentNullException();
}
_freyjaFile.WriteAllText(FullPath, m_Text);
}
catch (ArgumentNullException e)
{
Console.WriteLine(e);
throw;
}
}
Add
CreateFile()
intoTestHandleFileEditor.cs
if (GUILayout.Button("Create File"))
{
script.CreateFile();
}
Read File
Create function
ReadFile()
insideTestHandleFile.cs
public void ReadFile()
{
_freyjaFile = new FreyjaFile();
try
{
if (string.IsNullOrEmpty(FullPath))
{
throw new ArgumentNullException();
}
var text = _freyjaFile.ReadAllText(FullPath);
Debug.Log(text);
}
catch (ArgumentNullException e)
{
Console.WriteLine(e);
throw;
}
}
Add
ReadFile()
intoTestHandleFileEditor.cs
if (GUILayout.Button("Create File"))
{
script.ReadFile();
}
Delete File
Create function
DeleteFile()
insideTestHandleFile.cs
public void DeleteFile()
{
_freyjaFile = new FreyjaFile();
try
{
if (string.IsNullOrEmpty(FullPath))
{
throw new ArgumentNullException();
}
_freyjaFile.Delete(FullPath);
}
catch (ArgumentNullException e)
{
Console.WriteLine(e);
throw;
}
}
Add
DeleteFile()
intoTestHandleFileEditor.cs
if (GUILayout.Button("Delete File"))
{
script.DeleteFile();
}
Last updated