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. }
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 ); } }
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); } } }
void postStart() { HarmonyRenderer renderer = GetComponent <HarmonyRenderer>(); // Preemptively load clip. renderer.LoadClipIndex(0 /* first clip */); HarmonyAnimation animation = gameObject.GetComponent <HarmonyAnimation>(); if (animation != null) { HarmonyAnimation.CallbackEvents callbacks = new HarmonyAnimation.CallbackEvents(); // Trigger a callback at frame 10 of animation. callbacks.AddCallbackAtFrame(10.0f, CallbackMethod1); // Trigget a callback at end of animation. callbacks.AddCallbackAtEnd(CallbackMethod2); // Loop animation indefinitely. animation.LoopAnimation(frameRate, 0 /* first clip */, 1.0f /*first frame*/, false /*forward*/, callbacks); } renderer.readyToRender = true; }