Exemple #1
0
    void Movement(Vector2 move)
    {
        GameObject bear = GameObject.FindWithTag("bear");

        if (RB2D.position.y > -5)
        {
            //RB2D.position += move;
            RB2D.rotation += Random.Range(0f, Mathf.Abs(velocity.y) * 2f);
        }
        else if (true)
        {
            velocity.y = RB2D.velocity.y * Random.Range(-0.8f, -0.9f);
            velocity.x = RB2D.velocity.x * Random.Range(0.8f, 0.9f);
            AudioData.Play();
            float distanceToBear = Vector2.Distance(bear.transform.position, RB2D.position);

            AudioData.volume = Mathf.Max(0, 1.0f / (distanceToBear + 0.1f) + 0.001f * velocity.y * velocity.y);
            //Debug.Log("AudioData.volume: " + AudioData.volume);
            if (velocity.magnitude < 0.01f)
            {
                RB2D.rotation    = 0;
                AudioData.volume = 0;
                // UnityNativeChromaSDK.SetCurrentFrameName("anim.chroma", 1);
                RB2D.velocity = 0 * RB2D.velocity;
                UnityNativeChromaSDK.StopAnimationName("anim.chroma");
            }
            else
            {
                //  UnityNativeChromaSDK.SetCurrentFrameName("anim.chroma", 0);
            }

            UnityNativeChromaSDK.PlayAnimationName("anim.chroma", false);
            // RB2D.rotation = -RB2D.rotation;
            //RB2D.position -= move;
        }

        if (RB2D.position.x > 19 || RB2D.position.x < -19)
        {
            velocity.x = -velocity.x;
        }
        RB2D.velocity = velocity;
    }
    private void OnGUI()
    {
        if (!UnityNativeChromaSDK.IsPlatformSupported())
        {
            GUILayout.BeginVertical(GUILayout.Height(Screen.height));
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
            GUILayout.FlexibleSpace();
            GUILayout.Label("The ChromaSDK is not supported on this platform!");
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            return;
        }

        bool isInitialized = UnityNativeChromaSDK.PluginIsInitialized();
        GUILayout.BeginVertical(GUILayout.Height(Screen.height));
        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Load Scene 2"))
        {
#if UNITY_3 || UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            Application.LoadLevel(1);
#else
            SceneManager.LoadScene(1);
#endif
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
        GUILayout.FlexibleSpace();
        GUI.enabled = isInitialized;
        if (GUILayout.Button("PLAY", GUILayout.Height(30)))
        {
            UnityNativeChromaSDK.PlayComposite("Random", false);
        }
        if (GUILayout.Button("LOOP", GUILayout.Height(30)))
        {
            UnityNativeChromaSDK.PlayComposite("Random", true);
        }
        if (GUILayout.Button("STOP", GUILayout.Height(30)))
        {
            UnityNativeChromaSDK.StopComposite("Random");
        }
        if (GUILayout.Button("RELOAD", GUILayout.Height(30)))
        {
            foreach (string animation in _mAnimations)
            {
                UnityNativeChromaSDK.CloseAnimationName(animation);
            }
        }
#endif
        GUI.enabled = true;
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        foreach (string animation in _mAnimations)
        {
            GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
            GUILayout.FlexibleSpace();
            GUILayout.Label(string.Format("{0}:", UnityNativeChromaSDK.GetDevice(animation)));
            GUILayout.Label(animation);
            GUI.enabled = isInitialized;
            if (GUILayout.Button("Play", GUILayout.Height(30)))
            {
                UnityNativeChromaSDK.PlayAnimationName(animation);
            }
            if (GUILayout.Button("Loop", GUILayout.Height(30)))
            {
                UnityNativeChromaSDK.PlayAnimationName(animation, true);
            }
            if (GUILayout.Button("Stop", GUILayout.Height(30)))
            {
                UnityNativeChromaSDK.StopAnimationName(animation);
            }
            if (GUILayout.Button("Reload", GUILayout.Height(30)))
            {
                UnityNativeChromaSDK.CloseAnimationName(animation);
            }
            if (GUILayout.Button("Edit", GUILayout.Height(30)))
            {
                UnityNativeChromaSDK.EditAnimation(animation);
            }
            GUI.enabled = true;
            GUILayout.Label(string.Format("({0} frames)", UnityNativeChromaSDK.GetFrameCountName(animation)));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("QUIT", GUILayout.Height(30)))
        {
            Application.Quit();
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
    }
 /// <summary>
 /// Stop the animation on disable
 /// </summary>
 private void OnDisable()
 {
     UnityNativeChromaSDK.StopAnimationName(_mAnimationName);
 }