예제 #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.
    }
예제 #2
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);
            }
        }
    }
예제 #3
0
    void CreateCharacterAt(Vector3 pos)
    {
        //Message.Log( "Create Character at: " + pos );

    #if CLONE_ON_TOUCH
        GameObject rendererObject = GameObject.Instantiate(gameObjectToClone) as GameObject;
        rendererObject.transform.localPosition = new Vector3(pos.x, pos.y, pos.z);
        rendererObject.transform.parent        = gameObject.transform;

        HarmonyRenderer  renderer  = rendererObject.GetComponent <HarmonyRenderer>();
        HarmonyAnimation animation = rendererObject.GetComponent <HarmonyAnimation>();
    #else
        GameObject rendererObject = new GameObject("Space Duck");
        rendererObject.transform.localScale    = new Vector3(0.01f, 0.01f, 0.01f);
        rendererObject.transform.localPosition = new Vector3(pos.x, pos.y, pos.z);
        rendererObject.transform.parent        = gameObject.transform;


        HarmonyRenderer  renderer  = rendererObject.AddComponent <HarmonyRenderer>();
        HarmonyAnimation animation = rendererObject.AddComponent <HarmonyAnimation>();

        Rigidbody2D       rigidBody = rendererObject.AddComponent <Rigidbody2D>();
        PolygonCollider2D collider  = rendererObject.AddComponent <PolygonCollider2D>();

        //  Set up clip collection in renderer.
        renderer.projectFolder = liveProjectFolder;
        renderer.clipNames     = XML_StageLoader.loadStageClipNames(renderer.projectFolder).ToArray();

        renderer.syncCollider  = HarmonyRenderer.SyncCollider.eAlways;
        renderer.colliderShape = colliderShape;
    #endif // CLONE_ON_TOUCH

        //  Randomly play a clip.
        if (renderer.clipNames.Length > 0)
        {
            animation.LoopAnimation(24.0f, rand.Next() % renderer.clipNames.Length);
        }
    }
예제 #4
0
    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;
    }