Example #1
0
    IEnumerator Start()
    {
        //  Preemptively load clips.
        HarmonyRenderer renderer = GetComponent <HarmonyRenderer>();

        if ((renderer == null) || (renderer.clipNames == null))
        {
            yield break;
        }

        //yield return StartCoroutine(renderer.WaitForDownloads());

        foreach (string clipName in renderer.clipNames)
        {
            renderer.LoadClipName(clipName);
        }

        //  Wait for audio if necessary.
        HarmonyAudio audio = GetComponent <HarmonyAudio>();

        if (audio != null)
        {
            yield return(StartCoroutine(audio.WaitForDownloads()));
        }
    }
Example #2
0
    public IEnumerator RefreshRendererObject()
    {
        if (rendererObject == null)
        {
            yield break;
        }

        SceneSettings settings = FindObjectOfType(typeof(SceneSettings)) as SceneSettings;

        if (settings == null)
        {
            yield break;
        }

        HarmonyRenderer  renderer  = rendererObject.GetComponent <HarmonyRenderer>();
        HarmonyAnimation animation = rendererObject.GetComponent <HarmonyAnimation>();
        HarmonyAudio     audio     = rendererObject.GetComponent <HarmonyAudio>();

        if ((renderer == null) || (animation == null) || (audio == null))
        {
            yield break;
        }

        renderer.LoadClipIndex(settings.clipIdx);

        //  Make sure sound is all downloaded before playing animation.
        yield return(StartCoroutine(audio.WaitForDownloads()));

        //  Loop animation indefinitely.
        animation.ResetAnimation();
        animation.LoopAnimation(frameRate, settings.clipIdx);
        animation.ResumeAnimation(); // resume if paused.
    }
Example #3
0
    IEnumerator Start()
    {
        HarmonyAnimation[] animations = FindObjectsOfType <HarmonyAnimation>();

        //  Wait for audio to be complete before playing animation.
        foreach (HarmonyAnimation animation in animations)
        {
            GameObject gameObject = animation.gameObject;

            HarmonyRenderer renderer = gameObject.GetComponent <HarmonyRenderer>();
            if (renderer != null)
            {
                //  Preemptively load clip.
                renderer.LoadClipIndex(0 /* first clip */);
            }

            //  Wait for audio if necessary.
            HarmonyAudio audio = gameObject.GetComponent <HarmonyAudio>();
            if (audio != null)
            {
                yield return(StartCoroutine(audio.WaitForDownloads()));
            }
        }

        foreach (HarmonyAnimation animation in animations)
        {
            animation.LoopAnimation(24.0f, 0 /* first clip */);

            //  Loop only part of the animation.
            //animation.LoopFrames( 24.0f, 1.0f, 30.0f );
        }
    }
Example #4
0
    IEnumerator Start()
    {
        SceneSettings settings = FindObjectOfType(typeof(SceneSettings)) as SceneSettings;

        if (settings != null)
        {
            if (settings.clipNames.Length > 0)
            {
                rendererObject = new GameObject("RendererObject");
                rendererObject.transform.parent = settings.viewerGroup.transform;

                HarmonyRenderer  renderer            = rendererObject.AddComponent <HarmonyRenderer>();
                HarmonyAnimation animation           = rendererObject.AddComponent <HarmonyAnimation>();
                HarmonyAudio     audio               = rendererObject.AddComponent <HarmonyAudio>();
                AudioSource      templateAudioSource = rendererObject.AddComponent <AudioSource>();

                //  Linear rolloff.  Easier for sound to be heard.
                templateAudioSource.rolloffMode = AudioRolloffMode.Linear;

                //  Set up clip collection in renderer.
                renderer.projectFolder = settings.projectFolder;
                renderer.clipNames     = settings.clipNames;

                renderer.LoadClipIndex(settings.clipIdx);

                //  Adjust renderer object size to fit in camera.
                Bounds box = renderer.CalculateCurrentBoundingBox();

                float scaleFactor = 5.0f / Mathf.Max(box.size.x, box.size.y);
                rendererObject.transform.localScale = new Vector3(scaleFactor, scaleFactor, 1.0f);

                //  Make sure sound is all downloaded before playing animation.
                yield return(StartCoroutine(audio.WaitForDownloads()));

                //  Loop animation indefinitely.
                animation.ResetAnimation();
                animation.LoopAnimation(frameRate, settings.clipIdx);
            }
        }
    }