Ejemplo n.º 1
0
    public static void WriteAnimation(BitAnimator bitAnimator)
    {
        Action <BitAnimator> updateCallback = (BitAnimator b) =>
        {
            EditorUtility.DisplayProgressBar("Creating animation", b.status, b.taskProgress);
        };
        Action <BitAnimator> finishCallback = (BitAnimator b) =>
        {
            b.core.FreeMemory();
            isRunningTask = false;
            executionTime = Time.realtimeSinceStartup - executionTime;
            EditorUtility.ClearProgressBar();
        };

        bitAnimator.StartCoroutine(bitAnimator.CreateAnimation(finishCallback, updateCallback));
        executionTime = Time.realtimeSinceStartup;
        isRunningTask = true;
    }
Ejemplo n.º 2
0
    public static void SetupRuntimeAnimation(BitAnimator bitAnimator)
    {
        Animator animator = bitAnimator.animatorObject;

        //animator.runtimeAnimatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPathWithClip(Path.ChangeExtension(bitAnimator.animationAssetPath, "controller"), clip);
        animation = animator.gameObject.GetComponent <Animation>();
        if (animation == null)
        {
            animation = animator.gameObject.AddComponent <Animation>();
        }
        animation.playAutomatically = false;
        AnimationState runtimeAnimation = animation["BitAnimator.RuntimeAnimation"];

        if (runtimeAnimation == null)
        {
            AnimationClip clip = new AnimationClip
            {
                name   = bitAnimator.audioClip.name,
                legacy = true
            };
            animation.AddClip(clip, "BitAnimator.RuntimeAnimation");
            runtimeAnimation = animation["BitAnimator.RuntimeAnimation"];
        }
        animation.clip           = runtimeAnimation.clip;
        animation.clip.frameRate = (float)bitAnimator.audioClip.frequency / (1 << bitAnimator.FFTWindowLog) * bitAnimator.multisamples;
        Action <BitAnimator> updateCallback = (BitAnimator b) =>
        {
            EditorUtility.DisplayProgressBar("Creating animation", b.status, b.taskProgress);
        };
        Action <BitAnimator> finishCallback = (BitAnimator b) =>
        {
            b.core.FreeMemory();
            isRunningTask = false;
            executionTime = Time.realtimeSinceStartup - executionTime;
            EditorUtility.ClearProgressBar();
            animation.Play();
            //audio.enabled = true;
            if (!audio.isPlaying)
            {
                audio.Play();
            }
        };

        bitAnimator.StartCoroutine(bitAnimator.ComputeAnimation(runtimeAnimation.clip, finishCallback, updateCallback));
        if (EditorApplication.isPlaying)
        {
            bitAnimator.animatorObject.enabled = false;
        }
        isRunningTask = true;
        executionTime = Time.realtimeSinceStartup;

        audio = bitAnimator.animatorObject.gameObject.GetComponentInChildren <AudioSource>();
        if (audio == null)
        {
            audio = bitAnimator.animatorObject.gameObject.AddComponent <AudioSource>();
        }

        if (audio.clip != bitAnimator.audioClip)
        {
            audio.clip         = bitAnimator.audioClip;
            audio.volume       = 0.25f;
            audio.minDistance  = 10;
            audio.dopplerLevel = 0;
            audio.spatialBlend = 0;
            audio.spatialize   = false;
        }
    }