Frame-flipping for Sprites Unity Complex characters

This script is used to automate the flipping of characters animated with the Sprites Unity Complex engine when facing a particular direction.

This is similar to the "Frame flipping" option when using the Sprites Unity engine, where left-facing animations can be flipped when facing right (and vice-versa).

To use:


 * 1) Setup your character using the Sprites Unity Complex engine as normal
 * 2) Update your Animator so that he plays the left-facing equivalent of any right-facing animation (or vice-versa) when appropriate.
 * 3) Place the code below in a C# script named SUC_FrameFlip
 * 4) Place the script on the character and assign the fields - setting the charater's Sprite child as the Transform To Flip.
 * 5) Tweak the Top Angle Freedom value to control how wide an angle a character can have when facing up or down before the script takes effect.

using UnityEngine; using System.Collections; using AC; public class SUC_FrameFlip : MonoBehaviour {    [SerializeField] private AC.Char character; [SerializeField] private Transform transformToFlip; [SerializeField] private AC_2DFrameFlipping frameFlipping; [SerializeField] private float topAngleFreedom = 0f; private void Update {        if (frameFlipping == AC_2DFrameFlipping.None || character == null || transformToFlip == null) {            return; }        bool doFlip = false; float spriteAngle = character.GetSpriteAngle ; switch (frameFlipping) {        	case AC_2DFrameFlipping.LeftMirrorsRight: doFlip = (spriteAngle >= 0f && spriteAngle < 180f); break; case AC_2DFrameFlipping.RightMirrorsLeft: doFlip = (spriteAngle > 180f && spriteAngle <= 360f); break; default: return; }        if (spriteAngle < topAngleFreedom || spriteAngle > (360f - topAngleFreedom) || (spriteAngle > (180f - topAngleFreedom) && spriteAngle < (180f + topAngleFreedom))) {        	return; }        if ((doFlip && transformToFlip.localScale.x > 0f) || (!doFlip && transformToFlip.localScale.x < 0f)) {            transformToFlip.localScale = new Vector3 (-transformToFlip.localScale.x, transformToFlip.localScale.y, transformToFlip.localScale.z); }    } }