private void Awake()
 {
     if (Instance != null && Instance != this)
     {
         Destroy(Instance);
     }
     else
     {
         Instance = this;
     }
 }
Ejemplo n.º 2
0
        void RecognizeShake()
        {
            if (recogInterval[Gesture.Shake] > 0)
            {
                return;
            }
            try {
                var         nextType      = 0; //0: unknown, 1: pos, 2: neg
                var         diffSum       = 0.0f;
                var         shakeCount    = 0;
                var         shakeDuration = 0.0f;
                const float minShake      = 20.0f;

                var beforeY         = hdms.First().eulerAngles.y;
                var beforeShakeTime = float.NaN;
                var index           = 0;
                foreach (var hdm in hdms)
                {
                    if (index < recogIndex[Gesture.Shake])
                    {
                        continue;
                    }
                    index++;
                    diffSum += GetAngleDiff(beforeY, hdm.eulerAngles.y);
                    beforeY  = hdm.eulerAngles.y;
                    if (nextType == 0)
                    {
                        if (diffSum > minShake || diffSum < -minShake)
                        {
                            if (diffSum > minShake)
                            {
                                nextType = 2;
                            }
                            else if (diffSum < -minShake)
                            {
                                nextType = 1;
                            }
                            shakeCount     += 1;
                            beforeShakeTime = hdm.timestamp;
                        }
                    }
                    else if (nextType == 1)
                    {
                        if (diffSum > minShake)
                        {
                            nextType      = 2;
                            shakeCount   += 1;
                            shakeDuration = hdm.timestamp - beforeShakeTime;
                        }
                    }
                    else if (nextType == 2)
                    {
                        if (diffSum < -minShake)
                        {
                            nextType      = 1;
                            shakeCount   += 1;
                            shakeDuration = hdm.timestamp - beforeShakeTime;
                        }
                    }
                }
                if (shakeCount >= 4)
                {
                    Debug.LogFormat("Shake! {0}, {1}", shakeCount, shakeDuration / shakeCount);
                    if (ShakeHandler != null)
                    {
                        ShakeHandler.Invoke(shakeDuration / shakeCount);
                    }
                    recogInterval[Gesture.Shake] = gestureInterval;
                    recogIndex[Gesture.Shake]    = hdms.Count;
                }
            }
            catch (InvalidOperationException)
            {
                // pass
            }
        }
Ejemplo n.º 3
0
 private void Awake()
 {
     ShakeHandler.handler = this;
 }
    // Update is called once per frame
    void Update()
    {
        UpdateWeapon();

        DealKnockback(0);

        wpimg = gunTypes[Belt[held]].GetComponent <SpriteRenderer>();
        //wpimg = gunBelt[held].GetComponent<SpriteRenderer>();
        //definimos o angulo que vamos usar para a mira.
        AimAngle();
        //invertendo o personagem
        //Como temos tiros por segundo, devemos usar o botão pressionado.
        if (Input.GetButton("Fire1"))
        {
            fevent = gunTypes[Belt[held]].GetComponent <Gun>().Shoot(camvec);
            //int fevent = gunBelt[held].GetComponent<Gun>().Shoot(camvec);


            if (fevent.status == 1)
            {
                //Debug.Log("Shot Fired");
                //Debug.Log("Segurando" +  gunTypes[Belt[held]].GetComponent<Gun>());
                //Debug.Log("Gun Type" + Belt[held]);
                ShakeHandler.PlayShake((ShakeHandler.Shake)Belt[held]);
                //test for knockback:
                DealKnockback(1);
            }
            if (fevent.status == 2)
            {
                // Debug.Log("Gun -resting-");
            }
            if (fevent.status == 0)
            {
                //  Debug.Log("Must Reload");
            }

            UI.SetBulletGun(gunTypes[Belt[held]].GetComponent <Gun>().curammo, held);
        }

        //Se estamos recarregando
        if (Input.GetKeyDown(KeyCode.R))
        {
            // Debug.Log("R pressed" + held);
            int fevent2 = gunTypes[Belt[held]].GetComponent <Gun>().Reload();
            //int fevent = gunBelt[held].GetComponent<Gun>().Reload();
            if (fevent2 == 0)
            {
                // Debug.Log("No ammo");
            }
            else
            {
                // Debug.Log("Reloaded");
            }

            UI.SetBulletGun(gunTypes[Belt[held]].GetComponent <Gun>().curammo, held);
            UI.SetBulletColdre(gunTypes[Belt[held]].GetComponent <Gun>().ammo, held);
        }

        //Setamos qual eh a arma que estamos usando.
        if (Input.mouseScrollDelta.y != 0)
        {
            //scroll pra cima
            //Como temos duas armas, ambas fazem a mesma coisa, mas esse codigo serve se tivermos mais armas no futuro
            if (held == 0)
            {
                held   = 1;
                _other = 0;
            }
            //scroll pra baixo;
            else
            {
                held   = 0;
                _other = 1;
            }

            //Debug.Log("Scroll Moved");
            //Debug.Log(held);
        }
    }