Coder Social home page Coder Social logo

referencer's Introduction

sup

Referencer

This is a simple utility that lets you get an asset in the project by its name without setting anything up, both in editor and runtime.

Requirements

  • Git

Installation

If using 2018.3.x, you can add a new entry to the manifest.json file in your Packages folder:

"com.popcron.referencer": "https://github.com/popcron/referencer.git"

Example

//load using the full path
Sprite playerSprite = Refs.Get<Sprite>("Art/Sprites/Player.psd/Player_0");

//or load using just the name
playerSprite = Refs.Get<Sprite>("Player_0");

//load using just the name, if there are duplicates it will find the first one
GameObject playerPrefab = Refs.Get<GameObject>("Player");

//returns all scriptable objects of type Gun
List<Gun> allGuns = Refs.GetAll<Gun>();

//gets the original path of the sprite asset
string path = Refs.GetPath(gunSprite);

//returns a random gun
Gun randomGun = Refs.GetRandom<Gun>();

//for loops through every asset loaded
foreach (Reference reference in Refs.Assets)
{
    Debug.Log($"loaded in {reference.Object} at path {reference.Path}");
}

Types of assets

This utility will load all assets of these types in:

  • AudioClips
  • Fonts
  • Materials
  • GameObjects (Prefabs)
  • Meshes
  • ScriptableObjects
  • Sprite and Sprite sub assets
  • Textures
  • Shaders
  • TextAsset

Assets with IDs Included is the ScriptableObject loader, which will load all found types into the references. It will also check if the type has an ID property or id field. This gives the reference an extra piece of information for the loaded object, which will allow you to load the asset using its ID:

//get a gun scriptable object asset that has an ID of 12
int id = 12;
Gun gun = Refs.Get<Gun>(id);

Git ignore

So the references database is stored at Assets/References.asset, and this should be ignored in source control because this asset is always regenerated.

FAQ

  • What namespace? Popcron.Referencer
  • It loads everything? Yes
  • Is it optimized? For speed, yes

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.