Coder Social home page Coder Social logo

validator's Introduction

Unity Validator

Version : 1.1.0

Installation

  1. Unity Package Manager
  2. Add package from git URL:
  3. https://github.com/fidt17/Validator.git?path=/Assets/fidt17/UnityValidationModule

How to use

Run validator either by pressing [Alt+V] or by navigating to "Tools/Validator/Validator Window"

)

Specify Validation mode by selecting one of the options from dropdown menu

  • "Active Scene": Validate all objects on loaded scene
  • "In Build Scenes": Validate all objects across all build scenes. You will be asked to save current scene if required
  • "Project Assets": Validate all Prefabs and ScriptableObjects
  • "Everything": Validate "In Build Scene" + "Project Assets"

Settings

  • "Run Validator on build": If enabled will start Validator in "Everything" mode before each new build
  • "Stop build on Validator failure": If enabled an exception will be thrown once Validator finds an error. Which should cancel active build process

Validation Attributes

  • NotNullValidation

    Fails if MyObject is null or missing

    [NotNullValidation(validateInPrefab: true, recursiveValidation: true)]
    public Object MyObject;

    Fails if MyCollection or any of it's elements are null

    [NotNullValidation(validateInPrefab: true, recursiveValidation: true)]
    public IList<Object> MyCollection;
  • NotEmptyCollection

    Fails if MyCollection is null or empty Field must be of type that implements ICollection interface

    [NotEmptyCollection(allowNullElements: false, validateInPrefab: true, recursiveValidation: true)]
    public ICollection<Object> MyCollection;
  • UnityEventValidation

    Fails if any of call targets or methods are invalid Field must be of type UnityEvent

    [UnityEventValidation(validateInPrefab: true, recursiveValidation: true)]
    public UnityEvent UEvent;
  • ValidationMethod

    Method must return a boolean

    [ValidationMethod(message: "This message will be displayed if validation fails.")]
    private bool MyValidationMethod()
    {
        bool validationResult = false;
        // ...
        return validationResult;
    }

Custom Validation Attributes

You can create your own validation attributes with complex logic

public class LocalizationValidationAttribute : FieldValidationAttribute
{
    public override ValidationResult ValidateField(FieldInfo field, object target)
    {
        var key = (string)field.GetValue(target);
        var languages = LocalizationUtility.GetAllLanguages();
        foreach (var language in languages)
        {
            if (string.IsNullOrEmpty(key)) continue;
            var localizationMap = LocalizationUtility.GetLanguageMap(language);
            if (localizationMap.IsValidLocalizationKey(key)) continue;

            return new FailResult($"Missing key [{key}] in [{language}] map.", target);
        }

        return new PassResult();
    }
}

Usage

[LocalizationValidation]
public string MyLocalizationKey;

validator's People

Contributors

fidt17 avatar

Stargazers

 avatar  avatar  avatar Bogdan Nikolayev avatar KonH avatar  avatar Danil Evgenievich Lamov avatar

Watchers

 avatar

validator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.