Skip to content

MrRobinOfficial/Unity-Parser

Repository files navigation

Parser logo

Parser [Unity Engine]

Parsing system for Unity that helps developers easily convert strings into various data types within the engine. This system supports a wide range of data types, and offers try-parse methods to avoid allocating extra memory when parsing invalid strings.

This parsing system was built using NCalc.

license maintenance-status

Introduction

Parser is a helping system for folks who wants to parser string values into object values.

NOTE: This system will try to parse string value as user input into object value. For an example:

string input = "on"; // True
string input = "off"; // False

I do NOT recommend using this parsing system for serializing data. Instead, I highly recommend checking out my other project on uJSON for a more suitable solution for serializing data.

Installation

Or

  • Clone repo and build via Visual Studio as an .DLL

Quick guide

using UnityParsers;

Avoid regular parse method (Can cause errors if not parse correct!)

private const string VECTOR3 = "(-50, 30, 100)";
Parsers.Parse<UnityEngine.Vector2Int>(VECTOR3); // This will gives us error! Use TryParse instead for error-proud solution!

For an example

if (Parsers.TryParseVector3(VECTOR3, out UnityEngine.Vector3 result))
{

}

Avoid boxing/unboxing if you can. Read more about it

private const string VECTOR3 = "(-50, 30, 100)";
if (Parsers.TryParse(VECTOR3, out object result))
{
    // This take more performance because of boxing/unboxing values.
}

Tries to convert string with "off" into boolean

bool value = Parsers.ParseBoolean("off"); // This will return false

Tries to convert string with "bytes color format" into Color32

private const string COLOR_32 = "(255, 0, 0)";
Parsers.TryParseColor32(COLOR_32, out var color32); // Will return value as Color32

About

A friendly parsing system for Unity. This system supports a wide range of data types, and offers try-parse methods.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages