Example #1
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 #2
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 #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
    private void PlayPriv(AnimationClip newClip)
    {
        HarmonyAudio audio = GetComponent <HarmonyAudio>();

        if (audio != null)
        {
            newClip.InitializeAudio(audio);

            float delay = 0.0f;
            foreach (AnimationClip clip in animationClips)
            {
                //  infinite loop .. will not be able to play any clips afterwards unless it's stopped.
                if (clip.nTimes < 0)
                {
                    delay = -1.0f; // invalid delay
                    break;
                }

                delay += (clip.duration - clip.currentDuration) + (clip.nTimes - 1) * clip.duration;
            }

            if (delay >= 0.0f)
            {
                newClip.ScheduleAudioEvent(delay);
            }
        }

        animationClips.Add(newClip);
    }
Example #5
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);
            }
        }
    }
Example #6
0
    void Update()
    {
        HarmonyAudio audio = GetComponent <HarmonyAudio>();

        if ((audio != null) && !audio.isReady)
        {
            return;
        }

        HarmonyAnimation animation = GetComponent <HarmonyAnimation>();

        if (animation == null)
        {
            return;
        }

        HarmonyRenderer renderer = GetComponent <HarmonyRenderer>();

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

        //if ( !renderer.isReady )
        //  return;

        //  Almost at end of our scheduled list, reschedule a new sequence.
        if (renderer.clipNames.Length > animation.scheduledCount)
        {
            //  Play all clips
            foreach (string clipName in renderer.clipNames)
            {
                animation.PlayAnimation(frameRate, clipName);
            }
        }
    }
Example #7
0
    public bool LoadClipName(string clipName)
    {
        if (string.IsNullOrEmpty(clipName))
        {
            Message.LogWarning("Invalid clip name!");
            return(false);
        }

        //  If clip has already been loaded, bail out.
        if (loadedClips.ContainsKey(clipName))
        {
            return(true);
        }

        if (!ResolveProjectFolder())
        {
            Message.LogWarning("Could not find '" + projectFolder + "' on disk!");
            return(false);
        }

        float nFrames = Internal.LoadStageClip(liveProjectFolder, clipName, sheetResolution);

        if (nFrames == 0.0f)
        {
            Message.LogWarning("Clip '" + clipName + "' has no animation data.\n" +
                               "Is your asset folder missing information ?\n" +
                               "Possible reasons for this are:\n" +
                               "  - Clip name does not exist.  Look in the stage.xml file for valid clip names.\n" +
                               "  - Binary file version mismatch.  Make sure the output from Xml2Bin and the HarmonyRenderer plugin come from the same package.\n" +
                               "  - Incomplete XML Data.  If you are using the xml data, make sure skeleton.xml, animation.xml and drawingAnimation.xml files are in the folder.\n"
                               );
            //return false;
        }

        ClipData clipData = new ClipData();

        clipData.nFrames = nFrames;

        loadedClips[clipName] = clipData;

        if (!g_clipNamesRefCount.ContainsKey(liveProjectFolder))
        {
            g_clipNamesRefCount[liveProjectFolder] = new Dictionary <string, int>();
        }

        if (g_clipNamesRefCount[liveProjectFolder].ContainsKey(clipName))
        {
            ++g_clipNamesRefCount[liveProjectFolder][clipName];
        }
        else
        {
            g_clipNamesRefCount[liveProjectFolder][clipName] = 1;
        }

        //  Load audio clips used by current clip.
        HarmonyAudio audio = GetComponent <HarmonyAudio>();

        if (audio != null)
        {
            audio.LoadAudio(liveProjectFolder, clipName);
        }

        return(true);
    }
Example #8
0
 public void InitializeAudio(HarmonyAudio audio)
 {
     this.audio = audio;
 }