Giter VIP home page Giter VIP logo

asset-pipeline's Introduction

Asset Import Pipeline for Unity

openupm

This tool is a rule-based approach to asset postprocessors within Unity. The goal is develop re-usable processors that can be applied to assets when they are imported.

Asset Import Profiles

Asset Import Profiles are ScriptableObjects that store information about how to import assets based on a rule based path system. The rules consist of a base folder, asset types to process and processors that should execute on these assets when they are imported.

Asset Types

The asset types are Textures, Models, Audio, Videos, Fonts, Animations, Materials, Prefabs, SpriteAtlases and Other. Other can be used to match against any asset that matches a specified set of file extensions.

Path Variables

The asset import profile folder path and asset type file filters can create variables that you can use within the asset processors.

To specify a variable, wrap the variable name in {}. As an example, Assets/3DGamekit/Art/Textures/Characters/{characterName}/ will create the variable characterName with the folder name as a value when processors are run. This variable can be used when setting the asset bundle name, asset label, etc.

The variables can be forced to match a string convention such as snake case or pascal case. This can be done by adding a suffix to the variable name {characterName:\snake}.

Convention Variable Suffix Convention Example
No convention :\none The quick brown fox
Snake Case :\snake the_quick_brown_fox
Upper Snake Case :\usnake THE_QUICK_BROWN_FOX
Pascal Case :\pascal TheQuickBrownFox
Camel Case :\camel theQuickBrownFox
Kebab Case :\kebab the-quick-brown-fox
Upper Case :\upper THE QUICK BROWN FOX
Lower Case :\lower the quick brown fox

The variable suffix can also be used as basic regex. As an example if the variable should be enforced to be a number, this can be achieved by using :\d+.

When using the variable within a processor that supports it, you can use the string convention suffixes to convert the variable value to a specific string convention.

Asset Processors

Asset Processors are similar asset postprocessors that are executed when an asset is imported and it matches an profile and asset filter.

There are several asset processors provided and more will be added over time.

Processor Asset Types Descriptions
Apply Preset Textures, Models, Audio, SpriteAtlases, Fonts, Videos Applies a preset for the asset type
Set Asset Bundle All Assigns the asset bundle name and variant
Set Asset Labels All Assigns labels
Add To Sprite Atlas Textures Adds a sprite or texture to a SpriteAtlas and will create the SpriteAtlas if it does not exist
Pack Texture 2D Textures Packs a texture into a channel of another texture
Extract Materials Models Extracts materials from a model
Setup Materials Models Sets up materials from a model - Sets shader, properties, and assigns textures if they are found
Strip Mesh Data Models Strips mesh data from model, such as vertex colors, other uv channels
Reset Transform Models Resets position, rotation and scale on the model root object
Create Prefab Models Creates a prefab with the option to set layer, tag and mesh renderer(s) settings

User Data within the .meta file

Most processors will add custom user data to the meta file. This is done to signify that it has processed the asset and prevent multiple applications of the processor to the asset when it should only run once.

Custom Processors

Custom processors can be created by them via code. This is done by inheriting from the AssetProcessor class.

The AssetProcessorDescription attribute will allow you to setup a custom icon and assign what asset types are viable for your processor. The default will make the processor available for all asset types.

Here is an example processor that will set labels on assets

using System.Linq;
using Daihenka.AssetPipeline.Import;
using UnityEditor;
using UnityEngine;

[AssetProcessorDescription("FilterByLabel@2x")]
public class SetAssetLabels : AssetProcessor
{
    [SerializeField] string[] Labels;

    public override void OnPostprocess(Object asset, string assetPath)
    {
        var assetLabels = AssetDatabase.GetLabels(asset).ToHashSet();
        assetLabels.AddRange(labels);
        AssetDatabase.SetLabels(asset, assetLabels.ToArray());
        
        // Update the user data in the meta file
        ImportProfileUserData.AddOrUpdateProcessor(assetPath, this);
    }
}

How to Use

Open the Import Profiles window via the Tools > Asset Pipeline > Import Profiles menu item.

image

image

From here you can create Import Profiles via the Create New button.

Once you have created an import profile, double click on the item to open the editor for it.

image

Here you can specify the Base Folder and setup any Asset Filters and Processors.

asset-pipeline's People

Contributors

bpastoors avatar daihenka avatar

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.