• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A micro-framework for changing Unity 3D's Animator parameters with ScriptableObject(s). Designed to make going from custom scripts to Animator parameters easy. Works with 2D or 3D projects.

Unity Animator Helpers

Ever had to handle complex animations that require multiple frames such as jump, attack, or receiving damage? Generally this results in messy Animator variables and repeated code. Unity Animator Helpers provides a micro-framework to create modular animations that can be visually programmed and modularly shared between GameObjects.

  • Create animator variable changes from a ScriptableObject with visual programming
  • Share animator playback variable changes between GameObject(s)
  • Wait for multiple animator variable changes from a coroutine or loop
  • Pre-made library of common Animator Behaviors for visually programming the Animator with variable changes and randomization

Support

Join the Discord Community if you have questions or need help.

Quickstart

AnimatorPlayback Objects

How to use the AnimatorPlayback object to play animations with variables.

Preview of Playback Helper

  1. Right click in the project window
  2. Go to Create -> ADNC -> Animator Variables -> Animator Playback
  3. Set your variables and true conditions on the object
  4. Attach the object to a MonoBehavior as so AnimatorPlayback playback;
  5. Call playback.Play(MY_ANIMATOR); to trigger the variables.

Example script.

public class AnimatorPlaybackExample : MonoBehaviour {
    private Animator anim;
    
    [SerializeField]
    private AnimatorPlayback _completeEvent;

    [SerializeField]
    private string _completeMessage = "Detected animation playback as complete";

    private void Start () {
        anim = GetComponent<Animator>();

        // To play with a coroutine that waits for the conditions
        StartCoroutine(DetectEventComplete());
        
        // To play without any coroutine or wait conditions
        // _completeEvent.Play(anim);
    }

    IEnumerator DetectEventComplete () {
        yield return _completeEvent.PlayCoroutine(anim);
        Debug.Log(_completeMessage);
    }
}

Note that the AnimatorPlayback objects are fully unit and runtime tested due to their level of complexity.

Features

  • AnimatorPlayback objects to easily detect animation completion conditions
  • Pre-built library on AnimatorBehavior(s) for complex animation playback
  • Animator extensions that add missing functionality to Unity's Animator component
  • Animator unit testing helper (for editor only tests)
  • Unit tested

Installation

Unity Animator Helpers is used through Unity's Package Manager. In order to use it you'll need to add the following lines to your Packages/manifest.json file. After that you'll be able to visually control what specific version of Unity Animator Helpers you're using from the package manager window in Unity. This has to be done so your Unity editor can connect to NPM's package registry.

{
  "scopedRegistries": [
    {
      "name": "NPM",
      "url": "https://registry.npmjs.org",
      "scopes": [
        "com.fluid"
      ]
    }
  ],
  "dependencies": {
    "com.fluid.unity-animator-helpers": "2.0.0"
  }
}

Releases

Archives of specific versions and release notes are available on the releases page.

Nightly Builds

To access nightly builds of the develop branch that are package manager friendly, you'll need to manually edit your Packages/manifest.json as so.

{
    "dependencies": {
      "com.fluid.unity-animator-helpers": "https://github.com/ashblue/unity-animator-helpers.git#nightly"
    }
}

Note that to get a newer nightly build you must delete this line and any related lock data in the manifest, let Unity rebuild, then add it back. As Unity locks the commit hash for Git urls as packages.

Development Environment

If you wish to run to run the development environment you'll need to install the latest node.js. Then run the following from the root once.

npm install

If you wish to create a build run npm run build from the root and it will populate the dist folder.

Making Commits

All commits should be made using Commitizen (which is automatically installed when running npm install). Commits are automatically compiled to version numbers on release so this is very important. PRs that don't have Commitizen based commits will be rejected.

To make a commit type the following into a terminal from the root

npm run commit

Other Helper Libraries

Animator Behaviors

There are several animator helper scripts to assist you with Animator Behavior(s). These are aimed at allowing you to interact with the Animator without having to write additional scripts to tweak variables and playback.

Preview of Playback Helper

Available Helpers

Here is a brief list of helpers. New ones will be added as the repo is updated over time.

  • SetVarBool
  • SetVarRandomBool
  • SetVarFloat
  • SetVarRandomFloat
  • SetVarInt
  • SetVarRandomInt
  • RandomSpeed
  • RandomStartTime

See documentation on methods (in code) for complete details.

Animator Extensions

Unity Animator Helpers extends the pre-existing functionality of Unity3D's built in Animator component with static extensions. This doesn't hurt or break any existing functionality. For example you could do the following to check if you have a particular bool parameter.

public class AnimatorExtensionExample : MonoBehaviour {
    private Animator anim;
    
    public string hasAnimatorBool = "myBool";
    
    private void Start () {
        anim = GetComponent<Animator>();
        
        Debug.LogFormat("Animator has bool {0}: {1}", hasAnimatorBool, anim.HasBool(hasAnimatorBool));
    }
}

Available Animator extensions

  • HasParameter(name)
  • HasBool(name)
  • HasFloat(name)
  • HasInt(name)
  • HasTrigger(name)

See documentation on methods (in code) for complete details.

Extension Caching

Animator extensions perform some caching to make lookups instant. This only happens on the first extension call per unique AnimatorController. While this generally shouldn't cause performance problems and is almost instant. You may need to call AnimatorHelperRuntime.Instance.Cache(Animator) on Start or Awake if your Animator(s) have over 300 parameters. Please note that your AnimatorController object (what you pass into the Animator via inspector) must be uniquely named in order for the caching to work correctly.

Animator Unit Test Helper

This library provides an AnimatorStub (editor only) class that makes testing animations via pure code super simple. All you need to do is the following.

using Adnc.AnimatorHelpers.Editors.Testing.Utilities;
using NUnit.Framework;
using UnityEngine;

public class TestAnimatorStub {
    private AnimatorStub _stub;
    
    [SetUp]
    public void Setup () {
        _stub = new AnimatorStub();
    }

    [TearDown]
    public void Teardown () {
        // The stub is attached to a GameObject, so it must be destroyed manually
        Object.DestroyImmediate(_stub.Animator.gameObject);
    }
    
    [Test]
    public void MyTest () {
        // Setup your AnimatorController as desired
        stub.AnimatorCtrl.AddParameter("myBool", AnimatorControllerParameterType.Bool);
        
        // Inject a runtime version of the AnimatorController with all of your settings
        stub.InjectCtrl();
        
        // Test as normal
        // stub.Animator.Update(10); // If you need to simulate time
        Assert.IsTrue(stub.Animator.HasBool("myBool));
    }
}

This project was generated with Oyster Package Generator.

More Repositories

1

fluid-behavior-tree

Behavior trees for Unity3D projects. Written with a code driven approach on the builder pattern.
C#
961
star
2

fluid-dialogue

A Unity dialogue system that features an easy to use drag and drop graph. ScriptableObject driven with the ability to write custom actions and conditions to create complex dialogue workflows.
C#
198
star
3

unity-skill-tree-editor

Example Unity custom graph editor for editing skill trees.
C#
125
star
4

fluid-stats

A Unity3D character stats system for handling health, energy, defense, attack, ect. Supports dynamic stat values with modifiers such as addition, subtraction, multiplication, and division.
C#
83
star
5

unity-quest-journal

A Unity 3D package for managing complex or simple quests in video games. Inspired by The Witcher 3 and Skyrim like quest management systems.
C#
66
star
6

fluid-state-machine

A finite state machine micro-framework for Unity3D focused on a pure code implementation.
C#
62
star
7

pathfinding-platformer

JavaScript algorithm for A* Pathfinding in a platformer game. Includes a notion of gravity and able to take into account complex obstacles and jumping.
JavaScript
54
star
8

unity-elastic-inventory

An easy to use Unity inventory framework built with scaling and extendability in mind
C#
45
star
9

fluid-unique-id

A micro-framework to manage unique IDs in scenes with Unity
C#
36
star
10

unity-2d-parallax

Custom toolset for 2D Parallaxing in Unity
C#
35
star
11

simple-tween-js

A lightweight tweening micro-framewrok for your JavaScript projects. Only 2.8kb when minified.
JavaScript
27
star
12

oyster-package-generator

Oyster is a package generator for Unity Package Manager (UPM). It generates a best standards Unity package with automated deployments via CLI. Focus on coding your package instead of deployments, changelogs, ect.
TypeScript
25
star
13

unity-simple-spellcheck

A simple spell check tool for the Unity editor
C#
23
star
14

javascript-pathfinding

A* algorithm for pathfinding on a tile grid in JavaScript.
JavaScript
22
star
15

fluid-behavior-tree-ctf-example

CTF example that demonstrates how an AI might be written with Fluid Behavior Tree
C#
18
star
16

canvas-prime

A minimal OOP HTML5 game engine that uses extendable classes for its engine and objects without any libraries.
JavaScript
18
star
17

unity-package-manager-git-example

Example Unity3D projects that demonstrates how to use the new package manager with a Git repo.
C#
13
star
18

unity-timeline-dialogue-tool-sample

An example of how to use Unity's timeline tools with printed dialogue. Demonstrates how it could be used for dialogue boxes, subtitles, shoutboxes, ect.
C#
13
star
19

unity-simple-settings

Access static serialized files in Unity from your resources folder. Automatically initializes a runtime safe copy when the game starts.
C#
12
star
20

fluid-database

A simple key value pair database for Unity3d projects that supports string, bool, float, and int.
C#
11
star
21

canvas-sat

HTML5 JavaScript Canvas - Separating Axis Test (SAT) Demo
JavaScript
9
star
22

rect-wars

Rectangle wars is a retro style space shooter where you play as pixel, defender of the 2D universe. The game is built on the Canvas Prime engine and uses IndexedDB to record data.
JavaScript
7
star
23

upm-package-populator

A node.js build script to populate a nested package in a Unity Package Manager project to a dist folder. Also cross populates root package.json to the UPM package.
TypeScript
7
star
24

unity-ui-node-printer

Generic API for printing out complex UI graphs such as skill trees
C#
7
star
25

unity-event-plus

A simple wrapper utility to use interfaces with UnityEvent classes
C#
6
star
26

unity-simple-singleton

An easy to use singleton class for Unity3d projects. Easily installable as a package.
C#
6
star
27

fast-crop

HTML5 Canvas cropping utility that uses the File API to crop images in browser. All rendering is done client-side and finalized image is exported.
JavaScript
6
star
28

uvpm-server

A private Unity package manager server for Ultra Violet Package Manger (UVPM). The back-end server portion of the software.
TypeScript
6
star
29

unity-gauges

C#
5
star
30

unity-simple-notifications

A simple UPM package for displaying message notifications to a user
C#
5
star
31

cinemachine-rts-camera-test

C#
5
star
32

unity-find-and-replace

A simple modular find and replace utility for Unity3D projects
C#
5
star
33

unity-quest-log

C#
4
star
34

adnc-utilities

Unity utilities used for A Dragon Named Coal
C#
4
star
35

unity-inventory-example

C#
4
star
36

unity-platformer-pathfinding

C#
4
star
37

unity-additive-level-loading

http://blueashes.com/2015/game-development/unity-live-training-additive-level-loading/
C#
4
star
38

fluid-state-machine-examples

Door with lock and pressure plate state machine examples for Fluid State Machine
C#
3
star
39

unity-save-restore

Save and restore system for maintaining ScriptableObject(s) via serialization
C#
3
star
40

upm-package-nsubstitute

A simple Unity package wrapper around NSubstitute to prevent DLL dependency conflicts.
2
star
41

html5-games-presentation

Getting started with HTML5 games and Construct 2
JavaScript
2
star
42

unity-decision-editor

C#
2
star
43

terra

Lua
2
star
44

unity-move-along-bezier

C#
2
star
45

unity-skill-tree

Prototype skill tree for The Wanderer
C#
1
star
46

wp-simple-settings

An OOP script for handeling WordPress settings.
PHP
1
star
47

uvpm-cli

A Unity3D package manager CLI interface for Ultra Violet Packet Manager (UVPM)
TypeScript
1
star
48

ember-checklist

JavaScript
1
star
49

line-of-sight

Interactive JavaScript line of sight algorithm with debugging details.
JavaScript
1
star
50

unity-platform-astar

JavaScript
1
star
51

html5-form-validator

An HTML5 form validation fallback that targets browsers who don't support the functionality.
JavaScript
1
star
52

unity-narration-editor

C#
1
star
53

json-demo

A simple demo of sending JSON image file data to a JavaScript application via PHP.
PHP
1
star
54

slot

An input library for handling data IDs and arrays with complex data structures
JavaScript
1
star
55

pathfinding-presentation

Interactive pathfinding presentation
JavaScript
1
star
56

package-zipper

A lightweight PHP class that allows you to clone and create new zip file packages on the fly with the ZipArchive class. Originally built for packing up and returning compiled JavaScript code, but has many other uses.
PHP
1
star
57

sprite-animator

A flash like interface for creating pixel based animations on a timeline
JavaScript
1
star
58

unity-quest-editor

Quest editing interface for Unity with extendable objects.
C#
1
star
59

gamedev-blog

Statically generated blog for game development projects
Ruby
1
star
60

my-idb

Creates an asynchronous IndexedDB database from a JSON file and provides active caching for synchronous access. Includes polyfills for older implementations of IndexedDB. My IDB accessed through window.mydb
JavaScript
1
star
61

blender3d-robot-rigger

The Robot Rigger add-on for Blender provides a convenient way to automatically rig and unrig objects to bones based on a naming pattern. This tool is designed for quickly rigging robots, mechanical objects, and non-organic items. This is a micro-framework and designed to be non-intrusive to your existing Blender workflow.
Python
1
star